Exemple #1
0
  public void validateAddIndexAssignUpdateStrategies(
      String createIndexStatementName, IndexMultiKey imk, String indexName)
      throws ExprValidationException {
    // add index - for now
    eventTableIndexMetadataRepo.addIndex(false, imk, indexName, createIndexStatementName, true);

    // validate strategies, rollback if required
    for (Map.Entry<String, List<TableUpdateStrategyReceiverDesc>> stmtEntry :
        stmtNameToUpdateStrategyReceivers.entrySet()) {
      for (TableUpdateStrategyReceiverDesc strategyReceiver : stmtEntry.getValue()) {
        try {
          TableUpdateStrategyFactory.validateGetTableUpdateStrategy(
              this, strategyReceiver.getUpdateHelper(), strategyReceiver.isOnMerge());
        } catch (ExprValidationException ex) {
          eventTableIndexMetadataRepo.removeIndex(imk);
          throw new ExprValidationException(
              "Failed to validate statement '"
                  + stmtEntry.getKey()
                  + "' as a recipient of the proposed index: "
                  + ex.getMessage());
        }
      }
    }

    // assign new strategies
    for (Map.Entry<String, List<TableUpdateStrategyReceiverDesc>> stmtEntry :
        stmtNameToUpdateStrategyReceivers.entrySet()) {
      for (TableUpdateStrategyReceiverDesc strategyReceiver : stmtEntry.getValue()) {
        TableUpdateStrategy strategy =
            TableUpdateStrategyFactory.validateGetTableUpdateStrategy(
                this, strategyReceiver.getUpdateHelper(), strategyReceiver.isOnMerge());
        strategyReceiver.getReceiver().update(strategy);
      }
    }
  }
Exemple #2
0
  public void open(DataFlowOpOpenContext openContext) {
    FilterValueSet valueSet;
    try {
      List<ExprNode> filters = Collections.emptyList();
      if (filter != null) {
        filters = Collections.singletonList(filter);
      }
      FilterSpecCompiled spec =
          FilterSpecCompiler.makeFilterSpec(
              eventType,
              eventType.getName(),
              filters,
              null,
              null,
              null,
              new StreamTypeServiceImpl(
                  eventType, eventType.getName(), true, agentInstanceContext.getEngineURI()),
              null,
              agentInstanceContext.getStatementContext(),
              new ArrayList<Integer>());
      valueSet = spec.getValueSet(null, agentInstanceContext, null);
    } catch (ExprValidationException ex) {
      throw new EPException("Failed to open filter: " + ex.getMessage(), ex);
    }

    EPStatementAgentInstanceHandle handle =
        new EPStatementAgentInstanceHandle(
            agentInstanceContext.getStatementContext().getEpStatementHandle(),
            agentInstanceContext.getAgentInstanceLock(),
            0,
            new StatementAgentInstanceFilterVersion());
    callbackHandle = new EPStatementHandleCallback(handle, this);
    agentInstanceContext.getStatementContext().getFilterService().add(valueSet, callbackHandle);
  }
  public TableOnMergeHelper(
      StatementContext statementContext,
      OnTriggerMergeDesc onTriggerDesc,
      EventType triggeringEventType,
      String triggeringStreamName,
      InternalEventRouter internalEventRouter,
      TableMetadata tableMetadata)
      throws ExprValidationException {
    matched = new ArrayList<TableOnMergeMatch>();
    unmatched = new ArrayList<TableOnMergeMatch>();

    int count = 1;
    boolean hasDeleteAction = false;
    boolean hasInsertIntoTableAction = false;
    boolean hasUpdateAction = false;
    for (OnTriggerMergeMatched matchedItem : onTriggerDesc.getItems()) {
      List<TableOnMergeAction> actions = new ArrayList<TableOnMergeAction>();
      for (OnTriggerMergeAction item : matchedItem.getActions()) {
        try {
          if (item instanceof OnTriggerMergeActionInsert) {
            OnTriggerMergeActionInsert insertDesc = (OnTriggerMergeActionInsert) item;
            TableOnMergeActionIns action =
                setupInsert(
                    tableMetadata,
                    internalEventRouter,
                    count,
                    insertDesc,
                    triggeringEventType,
                    triggeringStreamName,
                    statementContext);
            actions.add(action);
            hasInsertIntoTableAction = action.isInsertIntoBinding();
          } else if (item instanceof OnTriggerMergeActionUpdate) {
            OnTriggerMergeActionUpdate updateDesc = (OnTriggerMergeActionUpdate) item;
            EventBeanUpdateHelper updateHelper =
                EventBeanUpdateHelperFactory.make(
                    tableMetadata.getTableName(),
                    tableMetadata.getInternalEventType(),
                    updateDesc.getAssignments(),
                    onTriggerDesc.getOptionalAsName(),
                    triggeringEventType,
                    false);
            ExprEvaluator filterEval =
                updateDesc.getOptionalWhereClause() == null
                    ? null
                    : updateDesc.getOptionalWhereClause().getExprEvaluator();
            TableUpdateStrategy tableUpdateStrategy =
                statementContext
                    .getTableService()
                    .getTableUpdateStrategy(tableMetadata, updateHelper, true);
            TableOnMergeActionUpd upd = new TableOnMergeActionUpd(filterEval, tableUpdateStrategy);
            actions.add(upd);
            statementContext
                .getTableService()
                .addTableUpdateStrategyReceiver(
                    tableMetadata, statementContext.getStatementName(), upd, updateHelper, true);
            hasUpdateAction = true;
          } else if (item instanceof OnTriggerMergeActionDelete) {
            OnTriggerMergeActionDelete deleteDesc = (OnTriggerMergeActionDelete) item;
            ExprEvaluator filterEval =
                deleteDesc.getOptionalWhereClause() == null
                    ? null
                    : deleteDesc.getOptionalWhereClause().getExprEvaluator();
            actions.add(new TableOnMergeActionDel(filterEval));
            hasDeleteAction = true;
          } else {
            throw new IllegalArgumentException(
                "Invalid type of merge item '" + item.getClass() + "'");
          }
          count++;
        } catch (ExprValidationException ex) {
          boolean isNot = item instanceof OnTriggerMergeActionInsert;
          String message =
              "Validation failed in when-"
                  + (isNot ? "not-" : "")
                  + "matched (clause "
                  + count
                  + "): "
                  + ex.getMessage();
          throw new ExprValidationException(message, ex);
        }
      }

      if (matchedItem.isMatchedUnmatched()) {
        matched.add(new TableOnMergeMatch(matchedItem.getOptionalMatchCond(), actions));
      } else {
        unmatched.add(new TableOnMergeMatch(matchedItem.getOptionalMatchCond(), actions));
      }
    }

    // since updates may change future secondary keys
    requiresWriteLock = hasDeleteAction || hasInsertIntoTableAction || hasUpdateAction;
  }
  public NamedWindowOnMergeHelper(
      StatementContext statementContext,
      OnTriggerMergeDesc onTriggerDesc,
      EventType triggeringEventType,
      String triggeringStreamName,
      InternalEventRouter internalEventRouter,
      String namedWindowName,
      EventTypeSPI namedWindowType)
      throws ExprValidationException {
    matched = new ArrayList<NamedWindowOnMergeMatch>();
    unmatched = new ArrayList<NamedWindowOnMergeMatch>();

    int count = 1;
    for (OnTriggerMergeMatched matchedItem : onTriggerDesc.getItems()) {
      List<NamedWindowOnMergeAction> actions = new ArrayList<NamedWindowOnMergeAction>();
      for (OnTriggerMergeAction item : matchedItem.getActions()) {
        try {
          if (item instanceof OnTriggerMergeActionInsert) {
            OnTriggerMergeActionInsert insertDesc = (OnTriggerMergeActionInsert) item;
            actions.add(
                setupInsert(
                    namedWindowName,
                    internalEventRouter,
                    namedWindowType,
                    count,
                    insertDesc,
                    triggeringEventType,
                    triggeringStreamName,
                    statementContext));
          } else if (item instanceof OnTriggerMergeActionUpdate) {
            OnTriggerMergeActionUpdate updateDesc = (OnTriggerMergeActionUpdate) item;
            EventBeanUpdateHelper updateHelper =
                EventBeanUpdateHelperFactory.make(
                    namedWindowName,
                    namedWindowType,
                    updateDesc.getAssignments(),
                    onTriggerDesc.getOptionalAsName(),
                    triggeringEventType,
                    true);
            ExprEvaluator filterEval =
                updateDesc.getOptionalWhereClause() == null
                    ? null
                    : updateDesc.getOptionalWhereClause().getExprEvaluator();
            actions.add(new NamedWindowOnMergeActionUpd(filterEval, updateHelper));
          } else if (item instanceof OnTriggerMergeActionDelete) {
            OnTriggerMergeActionDelete deleteDesc = (OnTriggerMergeActionDelete) item;
            ExprEvaluator filterEval =
                deleteDesc.getOptionalWhereClause() == null
                    ? null
                    : deleteDesc.getOptionalWhereClause().getExprEvaluator();
            actions.add(new NamedWindowOnMergeActionDel(filterEval));
          } else {
            throw new IllegalArgumentException(
                "Invalid type of merge item '" + item.getClass() + "'");
          }
          count++;
        } catch (ExprValidationException ex) {
          boolean isNot = item instanceof OnTriggerMergeActionInsert;
          String message =
              "Validation failed in when-"
                  + (isNot ? "not-" : "")
                  + "matched (clause "
                  + count
                  + "): "
                  + ex.getMessage();
          throw new ExprValidationException(message, ex);
        }
      }

      if (matchedItem.isMatchedUnmatched()) {
        matched.add(new NamedWindowOnMergeMatch(matchedItem.getOptionalMatchCond(), actions));
      } else {
        unmatched.add(new NamedWindowOnMergeMatch(matchedItem.getOptionalMatchCond(), actions));
      }
    }
  }