Exemplo n.º 1
0
  public void testVariantTwoJoin() {
    String stmtText =
        "insert into Event_1 "
            + "select intPrimitive - intBoxed as delta, intPrimitive * intBoxed as product "
            + "from "
            + SupportBean.class.getName()
            + ".win:length(100) as s0,"
            + SupportBean_A.class.getName()
            + ".win:length(100) as s1 "
            + " where s0.theString = s1.id";

    runAsserts(stmtText, null);

    // assert type metadata
    EventTypeSPI type =
        (EventTypeSPI)
            ((EPServiceProviderSPI) epService)
                .getEventAdapterService()
                .getExistsTypeByName("Event_1");
    assertEquals(null, type.getMetadata().getOptionalApplicationType());
    assertEquals(null, type.getMetadata().getOptionalSecondaryNames());
    assertEquals("Event_1", type.getMetadata().getPrimaryName());
    assertEquals("Event_1", type.getMetadata().getPublicName());
    assertEquals("Event_1", type.getName());
    assertEquals(EventTypeMetadata.TypeClass.STREAM, type.getMetadata().getTypeClass());
    assertEquals(false, type.getMetadata().isApplicationConfigured());
    assertEquals(false, type.getMetadata().isApplicationPreConfigured());
    assertEquals(false, type.getMetadata().isApplicationPreConfiguredStatic());
  }
Exemplo n.º 2
0
  public void setUp() {
    Configuration config = SupportConfigFactory.getConfiguration();
    ConfigurationVariantStream variant = new ConfigurationVariantStream();
    variant.setTypeVariance(ConfigurationVariantStream.TypeVariance.ANY);
    config.addVariantStream("MyVariantStream", variant);
    assertTrue(config.isVariantStreamExists("MyVariantStream"));

    epService = EPServiceProviderManager.getDefaultProvider(config);
    epService.initialize();
    listener = new SupportUpdateListener();

    // assert type metadata
    EventTypeSPI type =
        (EventTypeSPI)
            ((EPServiceProviderSPI) epService)
                .getValueAddEventService()
                .getValueAddProcessor("MyVariantStream")
                .getValueAddEventType();
    assertEquals(null, type.getMetadata().getOptionalApplicationType());
    assertEquals(null, type.getMetadata().getOptionalSecondaryNames());
    assertEquals("MyVariantStream", type.getMetadata().getPrimaryName());
    assertEquals("MyVariantStream", type.getMetadata().getPublicName());
    assertEquals("MyVariantStream", type.getName());
    assertEquals(EventTypeMetadata.TypeClass.VARIANT, type.getMetadata().getTypeClass());
    assertEquals(true, type.getMetadata().isApplicationConfigured());
    assertEquals(true, type.getMetadata().isApplicationPreConfigured());
    assertEquals(true, type.getMetadata().isApplicationPreConfiguredStatic());

    EventType[] valueAddTypes =
        ((EPServiceProviderSPI) epService).getValueAddEventService().getValueAddedTypes();
    assertEquals(1, valueAddTypes.length);
    assertSame(type, valueAddTypes[0]);

    assertEquals(0, type.getPropertyNames().length);
    assertEquals(0, type.getPropertyDescriptors().length);
  }
  private NamedWindowOnMergeActionIns setupInsert(
      String namedWindowName,
      InternalEventRouter internalEventRouter,
      EventTypeSPI eventTypeNamedWindow,
      int selectClauseNumber,
      OnTriggerMergeActionInsert desc,
      EventType triggeringEventType,
      String triggeringStreamName,
      StatementContext statementContext)
      throws ExprValidationException {

    // Compile insert-into info
    String streamName =
        desc.getOptionalStreamName() != null
            ? desc.getOptionalStreamName()
            : eventTypeNamedWindow.getName();
    InsertIntoDesc insertIntoDesc = InsertIntoDesc.fromColumns(streamName, desc.getColumns());

    // rewrite any wildcards to use "stream.wildcard"
    if (triggeringStreamName == null) {
      triggeringStreamName = UuidGenerator.generate();
    }
    List<SelectClauseElementCompiled> selectNoWildcard =
        compileSelectNoWildcard(triggeringStreamName, desc.getSelectClauseCompiled());

    // Set up event types for select-clause evaluation: The first type does not contain anything as
    // its the named window row which is not present for insert
    EventType dummyTypeNoProperties =
        new MapEventType(
            EventTypeMetadata.createAnonymous("merge_named_window_insert"),
            "merge_named_window_insert",
            0,
            null,
            Collections.<String, Object>emptyMap(),
            null,
            null,
            null);
    EventType[] eventTypes = new EventType[] {dummyTypeNoProperties, triggeringEventType};
    String[] streamNames = new String[] {UuidGenerator.generate(), triggeringStreamName};
    StreamTypeService streamTypeService =
        new StreamTypeServiceImpl(
            eventTypes, streamNames, new boolean[1], statementContext.getEngineURI(), false);

    // Get select expr processor
    SelectExprEventTypeRegistry selectExprEventTypeRegistry =
        new SelectExprEventTypeRegistry(
            statementContext.getStatementName(), statementContext.getStatementEventTypeRef());
    ExprEvaluatorContextStatement exprEvaluatorContext =
        new ExprEvaluatorContextStatement(statementContext, false);
    SelectExprProcessor insertHelper =
        SelectExprProcessorFactory.getProcessor(
            Collections.singleton(selectClauseNumber),
            selectNoWildcard.toArray(new SelectClauseElementCompiled[selectNoWildcard.size()]),
            false,
            insertIntoDesc,
            null,
            null,
            streamTypeService,
            statementContext.getEventAdapterService(),
            statementContext.getStatementResultService(),
            statementContext.getValueAddEventService(),
            selectExprEventTypeRegistry,
            statementContext.getMethodResolutionService(),
            exprEvaluatorContext,
            statementContext.getVariableService(),
            statementContext.getTableService(),
            statementContext.getTimeProvider(),
            statementContext.getEngineURI(),
            statementContext.getStatementId(),
            statementContext.getStatementName(),
            statementContext.getAnnotations(),
            statementContext.getContextDescriptor(),
            statementContext.getConfigSnapshot(),
            null,
            statementContext.getNamedWindowService(),
            null);
    ExprEvaluator filterEval =
        desc.getOptionalWhereClause() == null
            ? null
            : desc.getOptionalWhereClause().getExprEvaluator();

    InternalEventRouter routerToUser =
        streamName.equals(namedWindowName) ? null : internalEventRouter;
    boolean audit = AuditEnum.INSERT.getAudit(statementContext.getAnnotations()) != null;

    String insertIntoTableName = null;
    if (statementContext.getTableService().getTableMetadata(insertIntoDesc.getEventTypeName())
        != null) {
      insertIntoTableName = insertIntoDesc.getEventTypeName();
    }

    return new NamedWindowOnMergeActionIns(
        filterEval,
        insertHelper,
        routerToUser,
        insertIntoTableName,
        statementContext.getTableService(),
        statementContext.getEpStatementHandle(),
        statementContext.getInternalEventEngineRouteDest(),
        audit);
  }
  /**
   * Ctor.
   *
   * @param assignments the list of variable assignments
   * @param variableService variable service
   * @param eventAdapterService event adapters
   * @throws com.espertech.esper.epl.expression.core.ExprValidationException when variables cannot
   *     be found
   */
  public VariableReadWritePackage(
      List<OnTriggerSetAssignment> assignments,
      VariableService variableService,
      EventAdapterService eventAdapterService)
      throws ExprValidationException {
    this.metaData = new VariableMetaData[assignments.size()];
    this.readersForGlobalVars = new VariableReader[assignments.size()];
    this.mustCoerce = new boolean[assignments.size()];
    this.writers = new WriteDesc[assignments.size()];

    this.variableTypes = new HashMap<String, Object>();
    this.eventAdapterService = eventAdapterService;
    this.variableService = variableService;

    Map<EventTypeSPI, CopyMethodDesc> eventTypeWrittenProps =
        new HashMap<EventTypeSPI, CopyMethodDesc>();
    int count = 0;
    List<VariableTriggerSetDesc> assignmentList = new ArrayList<VariableTriggerSetDesc>();

    for (OnTriggerSetAssignment expressionWithAssignments : assignments) {
      Pair<String, ExprNode> possibleVariableAssignment =
          ExprNodeUtility.checkGetAssignmentToVariableOrProp(
              expressionWithAssignments.getExpression());
      if (possibleVariableAssignment == null) {
        throw new ExprValidationException(
            "Missing variable assignment expression in assignment number " + count);
      }
      assignmentList.add(
          new VariableTriggerSetDesc(
              possibleVariableAssignment.getFirst(),
              possibleVariableAssignment.getSecond().getExprEvaluator()));

      String fullVariableName = possibleVariableAssignment.getFirst();
      String variableName = fullVariableName;
      String subPropertyName = null;

      int indexOfDot = variableName.indexOf('.');
      if (indexOfDot != -1) {
        subPropertyName = variableName.substring(indexOfDot + 1, variableName.length());
        variableName = variableName.substring(0, indexOfDot);
      }

      VariableMetaData variableMetadata = variableService.getVariableMetaData(variableName);
      metaData[count] = variableMetadata;
      if (variableMetadata == null) {
        throw new ExprValidationException(
            "Variable by name '" + variableName + "' has not been created or configured");
      }
      if (variableMetadata.isConstant()) {
        throw new ExprValidationException(
            "Variable by name '" + variableName + "' is declared constant and may not be set");
      }
      if (variableMetadata.getContextPartitionName() == null) {
        readersForGlobalVars[count] =
            variableService.getReader(variableName, VariableService.NOCONTEXT_AGENTINSTANCEID);
      }

      if (subPropertyName != null) {
        if (variableMetadata.getEventType() == null) {
          throw new ExprValidationException(
              "Variable by name '"
                  + variableName
                  + "' does not have a property named '"
                  + subPropertyName
                  + "'");
        }
        EventType type = variableMetadata.getEventType();
        if (!(type instanceof EventTypeSPI)) {
          throw new ExprValidationException(
              "Variable by name '"
                  + variableName
                  + "' event type '"
                  + type.getName()
                  + "' not writable");
        }
        EventTypeSPI spi = (EventTypeSPI) type;
        EventPropertyWriter writer = spi.getWriter(subPropertyName);
        EventPropertyGetter getter = spi.getGetter(subPropertyName);
        if (writer == null) {
          throw new ExprValidationException(
              "Variable by name '"
                  + variableName
                  + "' the property '"
                  + subPropertyName
                  + "' is not writable");
        }

        variableTypes.put(fullVariableName, spi.getPropertyType(subPropertyName));
        CopyMethodDesc writtenProps = eventTypeWrittenProps.get(spi);
        if (writtenProps == null) {
          writtenProps = new CopyMethodDesc(variableName, new ArrayList<String>());
          eventTypeWrittenProps.put(spi, writtenProps);
        }
        writtenProps.getPropertiesCopied().add(subPropertyName);

        writers[count] = new WriteDesc(spi, variableName, writer, getter);
      } else {

        // determine types
        Class expressionType = possibleVariableAssignment.getSecond().getExprEvaluator().getType();

        if (variableMetadata.getEventType() != null) {
          if ((expressionType != null)
              && (!JavaClassHelper.isSubclassOrImplementsInterface(
                  expressionType, variableMetadata.getEventType().getUnderlyingType()))) {
            throw new VariableValueException(
                "Variable '"
                    + variableName
                    + "' of declared event type '"
                    + variableMetadata.getEventType().getName()
                    + "' underlying type '"
                    + variableMetadata.getEventType().getUnderlyingType().getName()
                    + "' cannot be assigned a value of type '"
                    + expressionType.getName()
                    + "'");
          }
          variableTypes.put(variableName, variableMetadata.getEventType().getUnderlyingType());
        } else {

          Class variableType = variableMetadata.getType();
          variableTypes.put(variableName, variableType);

          // determine if the expression type can be assigned
          if (variableType != java.lang.Object.class) {
            if ((JavaClassHelper.getBoxedType(expressionType) != variableType)
                && (expressionType != null)) {
              if ((!JavaClassHelper.isNumeric(variableType))
                  || (!JavaClassHelper.isNumeric(expressionType))) {
                throw new ExprValidationException(
                    VariableServiceUtil.getAssigmentExMessage(
                        variableName, variableType, expressionType));
              }

              if (!(JavaClassHelper.canCoerce(expressionType, variableType))) {
                throw new ExprValidationException(
                    VariableServiceUtil.getAssigmentExMessage(
                        variableName, variableType, expressionType));
              }

              mustCoerce[count] = true;
            }
          }
        }
      }

      count++;
    }

    this.assignments = assignmentList.toArray(new VariableTriggerSetDesc[assignmentList.size()]);

    if (eventTypeWrittenProps.isEmpty()) {
      copyMethods = Collections.EMPTY_MAP;
      return;
    }

    copyMethods = new HashMap<EventTypeSPI, EventBeanCopyMethod>();
    for (Map.Entry<EventTypeSPI, CopyMethodDesc> entry : eventTypeWrittenProps.entrySet()) {
      List<String> propsWritten = entry.getValue().getPropertiesCopied();
      String[] props = propsWritten.toArray(new String[propsWritten.size()]);
      EventBeanCopyMethod copyMethod = entry.getKey().getCopyMethod(props);
      if (copyMethod == null) {
        throw new ExprValidationException(
            "Variable '"
                + entry.getValue().getVariableName()
                + "' of declared type "
                + JavaClassHelper.getClassNameFullyQualPretty(entry.getKey().getUnderlyingType())
                + "' cannot be assigned to");
      }
      copyMethods.put(entry.getKey(), copyMethod);
    }
  }
Exemplo n.º 5
0
  public void setUp() {
    Configuration config = SupportConfigFactory.getConfiguration();

    config.addEventType("SupportBean", SupportBean.class);
    config.addEventType("FullEvent", SupportRevisionFull.class);
    config.addEventType("D1", SupportDeltaOne.class);
    config.addEventType("D2", SupportDeltaTwo.class);
    config.addEventType("D3", SupportDeltaThree.class);
    config.addEventType("D4", SupportDeltaFour.class);
    config.addEventType("D5", SupportDeltaFive.class);

    ConfigurationRevisionEventType configRev = new ConfigurationRevisionEventType();
    configRev.setKeyPropertyNames(new String[] {"k0"});
    configRev.addNameBaseEventType("FullEvent");
    configRev.addNameDeltaEventType("D1");
    configRev.addNameDeltaEventType("D2");
    configRev.addNameDeltaEventType("D3");
    configRev.addNameDeltaEventType("D4");
    configRev.addNameDeltaEventType("D5");
    config.addRevisionEventType("RevisableQuote", configRev);

    epService = EPServiceProviderManager.getDefaultProvider(config);
    epService.initialize();
    listenerOne = new SupportUpdateListener();
    listenerTwo = new SupportUpdateListener();
    listenerThree = new SupportUpdateListener();

    stmtCreateWin =
        epService
            .getEPAdministrator()
            .createEPL("create window RevQuote.win:keepall() as select * from RevisableQuote");
    epService.getEPAdministrator().createEPL("insert into RevQuote select * from FullEvent");
    epService.getEPAdministrator().createEPL("insert into RevQuote select * from D1");
    epService.getEPAdministrator().createEPL("insert into RevQuote select * from D2");
    epService.getEPAdministrator().createEPL("insert into RevQuote select * from D3");
    epService.getEPAdministrator().createEPL("insert into RevQuote select * from D4");
    epService.getEPAdministrator().createEPL("insert into RevQuote select * from D5");

    // assert type metadata
    EventTypeSPI type =
        (EventTypeSPI)
            ((EPServiceProviderSPI) epService)
                .getValueAddEventService()
                .getValueAddProcessor("RevQuote")
                .getValueAddEventType();
    assertEquals(null, type.getMetadata().getOptionalApplicationType());
    assertEquals(null, type.getMetadata().getOptionalSecondaryNames());
    assertEquals("RevisableQuote", type.getMetadata().getPrimaryName());
    assertEquals("RevisableQuote", type.getMetadata().getPublicName());
    assertEquals("RevisableQuote", type.getName());
    assertEquals(EventTypeMetadata.TypeClass.REVISION, type.getMetadata().getTypeClass());
    assertEquals(true, type.getMetadata().isApplicationConfigured());
    assertEquals(true, type.getMetadata().isApplicationPreConfigured());
    assertEquals(true, type.getMetadata().isApplicationPreConfiguredStatic());

    EventType[] valueAddTypes =
        ((EPServiceProviderSPI) epService).getValueAddEventService().getValueAddedTypes();
    assertEquals(1, valueAddTypes.length);
    assertSame(type, valueAddTypes[0]);

    ArrayAssertionUtil.assertEqualsAnyOrder(
        new Object[] {
          new EventPropertyDescriptor("k0", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("p0", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("p1", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("p2", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("p3", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("p4", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("p5", String.class, null, false, false, false, false, false)
        },
        type.getPropertyDescriptors());
  }