Пример #1
0
 public static TableOnViewFactory Make(
     TableMetadata tableMetadata,
     OnTriggerDesc onTriggerDesc,
     EventType filterEventType,
     string filterStreamName,
     StatementContext statementContext,
     StatementMetricHandle metricsHandle,
     bool isDistinct,
     InternalEventRouter internalEventRouter)
 {
     if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_DELETE)
     {
         return(new TableOnDeleteViewFactory(statementContext.StatementResultService, tableMetadata));
     }
     else if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_SELECT)
     {
         EventBeanReader eventBeanReader = null;
         if (isDistinct)
         {
             eventBeanReader = tableMetadata.InternalEventType.GetReader();
         }
         var windowDesc = (OnTriggerWindowDesc)onTriggerDesc;
         return(new TableOnSelectViewFactory(
                    tableMetadata, internalEventRouter, statementContext.EpStatementHandle,
                    eventBeanReader, isDistinct, statementContext.StatementResultService,
                    statementContext.InternalEventEngineRouteDest, windowDesc.IsDeleteAndSelect));
     }
     else if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_UPDATE)
     {
         var updateDesc   = (OnTriggerWindowUpdateDesc)onTriggerDesc;
         var updateHelper = EventBeanUpdateHelperFactory.Make(
             tableMetadata.TableName, (EventTypeSPI)tableMetadata.InternalEventType, updateDesc.Assignments,
             updateDesc.OptionalAsName, filterEventType, false);
         TableUpdateStrategy updateStrategy = statementContext.TableService.GetTableUpdateStrategy(
             tableMetadata, updateHelper, false);
         var onUpdateViewFactory =
             new TableOnUpdateViewFactory(
                 statementContext.StatementResultService, tableMetadata, updateHelper, updateStrategy);
         statementContext.TableService.AddTableUpdateStrategyReceiver(
             tableMetadata, statementContext.StatementName, onUpdateViewFactory, updateHelper, false);
         return(onUpdateViewFactory);
     }
     else if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_MERGE)
     {
         var onMergeTriggerDesc = (OnTriggerMergeDesc)onTriggerDesc;
         var onMergeHelper      = new TableOnMergeHelper(
             statementContext, onMergeTriggerDesc, filterEventType, filterStreamName, internalEventRouter,
             tableMetadata);
         return(new TableOnMergeViewFactory(
                    tableMetadata, onMergeHelper, statementContext.StatementResultService, metricsHandle,
                    statementContext.MetricReportingService));
     }
     else
     {
         throw new IllegalStateException("Unknown trigger type " + onTriggerDesc.OnTriggerType);
     }
 }
        public override EPPreparedExecuteIUDSingleStreamExec GetExecutor(FilterSpecCompiled filter, string aliasName)
        {
            var services         = base.Services;
            var processor        = base.Processor;
            var statementContext = base.StatementContext;
            var statementSpec    = base.StatementSpec;
            var updateSpec       = (FireAndForgetSpecUpdate)statementSpec.FireAndForgetSpec;

            var assignmentTypeService = new StreamTypeServiceImpl(
                new EventType[] { processor.EventTypeResultSetProcessor, null, processor.EventTypeResultSetProcessor },
                new string[] { aliasName, "", EPStatementStartMethodOnTrigger.INITIAL_VALUE_STREAM_NAME },
                new bool[] { true, true, true }, services.EngineURI, true);

            assignmentTypeService.IsStreamZeroUnambigous = true;
            var evaluatorContextStmt = new ExprEvaluatorContextStatement(statementContext, true);
            var validationContext    = new ExprValidationContext(
                assignmentTypeService, statementContext.EngineImportService,
                statementContext.StatementExtensionServicesContext, null, statementContext.SchedulingService,
                statementContext.VariableService, statementContext.TableService, evaluatorContextStmt,
                statementContext.EventAdapterService, statementContext.StatementName, statementContext.StatementId,
                statementContext.Annotations, statementContext.ContextDescriptor, statementContext.ScriptingService,
                false, false, true, false, null, false);

            // validate update expressions
            try {
                foreach (OnTriggerSetAssignment assignment in updateSpec.Assignments)
                {
                    ExprNode validated = ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.UPDATEASSIGN, assignment.Expression, validationContext);
                    assignment.Expression = validated;
                    EPStatementStartMethodHelperValidate.ValidateNoAggregations(validated, "Aggregation functions may not be used within an update-clause");
                }
            } catch (ExprValidationException e) {
                throw new EPException(e.Message, e);
            }

            // make updater
            EventBeanUpdateHelper updateHelper;
            TableUpdateStrategy   tableUpdateStrategy = null;

            try {
                bool copyOnWrite = !(processor is FireAndForgetProcessorTable);
                updateHelper = EventBeanUpdateHelperFactory.Make(processor.NamedWindowOrTableName,
                                                                 (EventTypeSPI)processor.EventTypeResultSetProcessor, updateSpec.Assignments, aliasName, null, copyOnWrite, statementContext.StatementName, services.EngineURI, services.EventAdapterService);

                if (processor is FireAndForgetProcessorTable)
                {
                    FireAndForgetProcessorTable tableProcessor = (FireAndForgetProcessorTable)processor;
                    tableUpdateStrategy = services.TableService.GetTableUpdateStrategy(tableProcessor.TableMetadata, updateHelper, false);
                    copyOnWrite         = false;
                }
            } catch (ExprValidationException e) {
                throw new EPException(e.Message, e);
            }

            return(new EPPreparedExecuteIUDSingleStreamExecUpdate(filter, statementSpec.FilterRootNode, statementSpec.Annotations, updateHelper, tableUpdateStrategy, statementSpec.TableNodes, services));
        }
 public static NamedWindowOnExprFactory Make(
     EventType namedWindowEventType,
     string namedWindowName,
     string namedWindowAlias,
     OnTriggerDesc onTriggerDesc,
     EventType filterEventType,
     string filterStreamName,
     bool addToFront,
     InternalEventRouter internalEventRouter,
     EventType outputEventType,
     StatementContext statementContext,
     StatementMetricHandle createNamedWindowMetricsHandle,
     bool isDistinct,
     StreamSelector?optionalStreamSelector,
     string optionalInsertIntoTableName)
 {
     if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_DELETE)
     {
         return(new NamedWindowOnDeleteViewFactory(namedWindowEventType, statementContext.StatementResultService));
     }
     else if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_SELECT)
     {
         EventBeanReader eventBeanReader = null;
         if (isDistinct)
         {
             if (outputEventType is EventTypeSPI)
             {
                 eventBeanReader = ((EventTypeSPI)outputEventType).GetReader();
             }
             if (eventBeanReader == null)
             {
                 eventBeanReader = new EventBeanReaderDefaultImpl(outputEventType);
             }
         }
         var windowDesc = (OnTriggerWindowDesc)onTriggerDesc;
         return(new NamedWindowOnSelectViewFactory(
                    namedWindowEventType, internalEventRouter, addToFront,
                    statementContext.EpStatementHandle, eventBeanReader, isDistinct, statementContext.StatementResultService,
                    statementContext.InternalEventEngineRouteDest, windowDesc.IsDeleteAndSelect, optionalStreamSelector,
                    optionalInsertIntoTableName));
     }
     else if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_UPDATE)
     {
         var updateDesc   = (OnTriggerWindowUpdateDesc)onTriggerDesc;
         var updateHelper = EventBeanUpdateHelperFactory.Make(
             namedWindowName, (EventTypeSPI)namedWindowEventType, updateDesc.Assignments, namedWindowAlias,
             filterEventType, true);
         return(new NamedWindowOnUpdateViewFactory(
                    namedWindowEventType, statementContext.StatementResultService, updateHelper));
     }
     else if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_MERGE)
     {
         var onMergeTriggerDesc = (OnTriggerMergeDesc)onTriggerDesc;
         var onMergeHelper      = new NamedWindowOnMergeHelper(
             statementContext, onMergeTriggerDesc, filterEventType, filterStreamName, internalEventRouter,
             namedWindowName, (EventTypeSPI)namedWindowEventType);
         return(new NamedWindowOnMergeViewFactory(
                    namedWindowEventType, onMergeHelper, statementContext.StatementResultService,
                    createNamedWindowMetricsHandle, statementContext.MetricReportingService));
     }
     else
     {
         throw new IllegalStateException("Unknown trigger type " + onTriggerDesc.OnTriggerType);
     }
 }
Пример #4
0
        public NamedWindowOnMergeHelper(StatementContext statementContext,
                                        OnTriggerMergeDesc onTriggerDesc,
                                        EventType triggeringEventType,
                                        string triggeringStreamName,
                                        InternalEventRouter internalEventRouter,
                                        string namedWindowName,
                                        EventTypeSPI namedWindowType)

        {
            Matched   = new List <NamedWindowOnMergeMatch>();
            Unmatched = new List <NamedWindowOnMergeMatch>();

            var count = 1;

            foreach (var matchedItem in onTriggerDesc.Items)
            {
                IList <NamedWindowOnMergeAction> actions = new List <NamedWindowOnMergeAction>();
                foreach (var item in matchedItem.Actions)
                {
                    try {
                        if (item is OnTriggerMergeActionInsert)
                        {
                            var insertDesc = (OnTriggerMergeActionInsert)item;
                            actions.Add(SetupInsert(namedWindowName, internalEventRouter, namedWindowType, count, insertDesc, triggeringEventType, triggeringStreamName, statementContext));
                        }
                        else if (item is OnTriggerMergeActionUpdate)
                        {
                            var updateDesc   = (OnTriggerMergeActionUpdate)item;
                            var updateHelper = EventBeanUpdateHelperFactory.Make(namedWindowName, namedWindowType, updateDesc.Assignments, onTriggerDesc.OptionalAsName, triggeringEventType, true);
                            var filterEval   = updateDesc.OptionalWhereClause == null ? null : updateDesc.OptionalWhereClause.ExprEvaluator;
                            actions.Add(new NamedWindowOnMergeActionUpd(filterEval, updateHelper));
                        }
                        else if (item is OnTriggerMergeActionDelete)
                        {
                            var deleteDesc = (OnTriggerMergeActionDelete)item;
                            var filterEval = deleteDesc.OptionalWhereClause == null ? null : deleteDesc.OptionalWhereClause.ExprEvaluator;
                            actions.Add(new NamedWindowOnMergeActionDel(filterEval));
                        }
                        else
                        {
                            throw new ArgumentException("Invalid type of merge item '" + item.GetType() + "'");
                        }
                        count++;
                    }
                    catch (ExprValidationException ex) {
                        var isNot   = item is OnTriggerMergeActionInsert;
                        var message = "Validation failed in when-" + (isNot?"not-":"") + "matched (clause " + count + "): " + ex.Message;
                        throw new ExprValidationException(message, ex);
                    }
                }

                if (matchedItem.IsMatchedUnmatched)
                {
                    Matched.Add(new NamedWindowOnMergeMatch(matchedItem.OptionalMatchCond, actions));
                }
                else
                {
                    Unmatched.Add(new NamedWindowOnMergeMatch(matchedItem.OptionalMatchCond, actions));
                }
            }
        }
Пример #5
0
        public TableOnMergeHelper(
            StatementContext statementContext,
            OnTriggerMergeDesc onTriggerDesc,
            EventType triggeringEventType,
            string triggeringStreamName,
            InternalEventRouter internalEventRouter,
            TableMetadata tableMetadata)
        {
            _matched   = new List <TableOnMergeMatch>();
            _unmatched = new List <TableOnMergeMatch>();

            var count                    = 1;
            var hasDeleteAction          = false;
            var hasInsertIntoTableAction = false;
            var hasUpdateAction          = false;

            foreach (var matchedItem in onTriggerDesc.Items)
            {
                IList <TableOnMergeAction> actions = new List <TableOnMergeAction>();
                foreach (var item in matchedItem.Actions)
                {
                    try {
                        if (item is OnTriggerMergeActionInsert)
                        {
                            var insertDesc = (OnTriggerMergeActionInsert)item;
                            var action     = SetupInsert(tableMetadata, internalEventRouter, count, insertDesc, triggeringEventType, triggeringStreamName, statementContext);
                            actions.Add(action);
                            hasInsertIntoTableAction = action.IsInsertIntoBinding;
                        }
                        else if (item is OnTriggerMergeActionUpdate)
                        {
                            var updateDesc          = (OnTriggerMergeActionUpdate)item;
                            var updateHelper        = EventBeanUpdateHelperFactory.Make(tableMetadata.TableName, tableMetadata.InternalEventType, updateDesc.Assignments, onTriggerDesc.OptionalAsName, triggeringEventType, false);
                            var filterEval          = updateDesc.OptionalWhereClause == null ? null : updateDesc.OptionalWhereClause.ExprEvaluator;
                            var tableUpdateStrategy = statementContext.TableService.GetTableUpdateStrategy(tableMetadata, updateHelper, true);
                            var upd = new TableOnMergeActionUpd(filterEval, tableUpdateStrategy);
                            actions.Add(upd);
                            statementContext.TableService.AddTableUpdateStrategyReceiver(tableMetadata, statementContext.StatementName, upd, updateHelper, true);
                            hasUpdateAction = true;
                        }
                        else if (item is OnTriggerMergeActionDelete)
                        {
                            var deleteDesc = (OnTriggerMergeActionDelete)item;
                            var filterEval = deleteDesc.OptionalWhereClause == null ? null : deleteDesc.OptionalWhereClause.ExprEvaluator;
                            actions.Add(new TableOnMergeActionDel(filterEval));
                            hasDeleteAction = true;
                        }
                        else
                        {
                            throw new ArgumentException("Invalid type of merge item '" + item.GetType() + "'");
                        }
                        count++;
                    }
                    catch (ExprValidationException ex) {
                        var isNot   = item is OnTriggerMergeActionInsert;
                        var message = "Validation failed in when-" + (isNot?"not-":"") + "matched (clause " + count + "): " + ex.Message;
                        throw new ExprValidationException(message, ex);
                    }
                }

                if (matchedItem.IsMatchedUnmatched)
                {
                    _matched.Add(new TableOnMergeMatch(matchedItem.OptionalMatchCond, actions));
                }
                else
                {
                    _unmatched.Add(new TableOnMergeMatch(matchedItem.OptionalMatchCond, actions));
                }
            }

            // since updates may change future secondary keys
            _requiresWriteLock = hasDeleteAction || hasInsertIntoTableAction || hasUpdateAction;
        }