public OutputProcessViewConditionFactory(
     StatementContext statementContext,
     OutputStrategyPostProcessFactory postProcessFactory,
     bool distinct,
     ExprTimePeriod afterTimePeriod,
     int?afterConditionNumberOfEvents,
     EventType resultEventType,
     OutputConditionFactory outputConditionFactory,
     int streamCount,
     ConditionType conditionType,
     OutputLimitLimitType outputLimitLimitType,
     bool terminable,
     bool hasAfter,
     bool isUnaggregatedUngrouped,
     SelectClauseStreamSelectorEnum selectClauseStreamSelectorEnum)
     : base(statementContext, postProcessFactory, distinct, afterTimePeriod, afterConditionNumberOfEvents, resultEventType)
 {
     _outputConditionFactory = outputConditionFactory;
     _streamCount            = streamCount;
     _conditionType          = conditionType;
     _outputLimitLimitType   = outputLimitLimitType;
     _terminable             = terminable;
     _hasAfter = hasAfter;
     _isUnaggregatedUngrouped        = isUnaggregatedUngrouped;
     _selectClauseStreamSelectorEnum = selectClauseStreamSelectorEnum;
 }
Beispiel #2
0
        public static StatementSpecRaw CompileEPL(
            string eplStatement,
            string eplStatementForErrorMsg,
            bool addPleaseCheck,
            string statementName,
            SelectClauseStreamSelectorEnum defaultStreamSelector,
            EngineImportService engineImportService,
            VariableService variableService,
            SchedulingService schedulingService,
            string engineURI,
            ConfigurationInformation configSnapshot,
            PatternNodeFactory patternNodeFactory,
            ContextManagementService contextManagementService,
            ExprDeclaredService exprDeclaredService,
            TableService tableService)
        {
            if (Log.IsDebugEnabled)
            {
                Log.Debug(".createEPLStmt statementName=" + statementName + " eplStatement=" + eplStatement);
            }

            ParseResult parseResult = ParseHelper.Parse(
                eplStatement, eplStatementForErrorMsg, addPleaseCheck, EPLParseRule, true);
            ITree ast = parseResult.Tree;

            var walker = new EPLTreeWalkerListener(
                parseResult.TokenStream, engineImportService, variableService, schedulingService, defaultStreamSelector,
                engineURI, configSnapshot, patternNodeFactory, contextManagementService, parseResult.Scripts,
                exprDeclaredService, tableService);

            try
            {
                ParseHelper.Walk(ast, walker, eplStatement, eplStatementForErrorMsg);
            }
            catch (ASTWalkException ex)
            {
                Log.Error(".createEPL Error validating expression", ex);
                throw new EPStatementException(ex.Message, ex, eplStatementForErrorMsg);
            }
            catch (EPStatementSyntaxException ex)
            {
                throw;
            }
            catch (Exception ex)
            {
                string message = "Error in expression";
                Log.Debug(message, ex);
                throw new EPStatementException(GetNullableErrortext(message, ex.Message), ex, eplStatementForErrorMsg);
            }

            if (Log.IsDebugEnabled)
            {
                ASTUtil.DumpAST(ast);
            }

            StatementSpecRaw raw = walker.StatementSpec;

            raw.ExpressionNoAnnotations = parseResult.ExpressionWithoutAnnotations;
            return(raw);
        }
Beispiel #3
0
        /// <summary>Constructor - takes the services context as argument. </summary>
        /// <param name="adminContext">administrative context</param>
        public EPAdministratorImpl(EPAdministratorContext adminContext)
        {
            _services = adminContext.Services;
            _configurationOperations = adminContext.ConfigurationOperations;
            _defaultStreamSelector   = adminContext.DefaultStreamSelector;

            ConfigurationEngineDefaults.AlternativeContext alternativeContext = adminContext.Services.ConfigSnapshot.EngineDefaults.AlternativeContextConfig;
            StatementIdGenerator statementIdGenerator = null;

            if (alternativeContext != null && alternativeContext.StatementIdGeneratorFactory != null)
            {
                var statementIdGeneratorFactory = TypeHelper.Instantiate <StatementIdGeneratorFactory>(alternativeContext.StatementIdGeneratorFactory);
                statementIdGenerator = statementIdGeneratorFactory.Invoke(new StatementIdGeneratorFactoryContext(_services.EngineURI));
            }

            _deploymentAdminService = new EPDeploymentAdminImpl(
                this,
                adminContext.Services.DeploymentStateService,
                adminContext.Services.StatementEventTypeRefService,
                adminContext.Services.EventAdapterService,
                adminContext.Services.StatementIsolationService,
                statementIdGenerator,
                adminContext.Services.FilterService,
                _services.ConfigSnapshot.EngineDefaults.ExpressionConfig.TimeZone);
        }
Beispiel #4
0
 /// <summary>
 /// Compile an EPL statement.
 /// </summary>
 /// <param name="eplStatement">to compile</param>
 /// <param name="eplStatementForErrorMsg">the statement to use for indicating error messages</param>
 /// <param name="addPleaseCheck">true to add please-check message text</param>
 /// <param name="statementName">the name of statement</param>
 /// <param name="services">engine services</param>
 /// <param name="defaultStreamSelector">stream selector</param>
 /// <returns>compiled statement</returns>
 public static StatementSpecRaw CompileEPL(
     string eplStatement,
     string eplStatementForErrorMsg,
     bool addPleaseCheck,
     string statementName,
     EPServicesContext services,
     SelectClauseStreamSelectorEnum defaultStreamSelector)
 {
     return(CompileEPL(
                services.Container,
                eplStatement,
                eplStatementForErrorMsg,
                addPleaseCheck,
                statementName,
                defaultStreamSelector,
                services.EngineImportService,
                services.VariableService,
                services.SchedulingService,
                services.EngineURI,
                services.ConfigSnapshot,
                services.PatternNodeFactory,
                services.ContextManagementService,
                services.ExprDeclaredService,
                services.TableService));
 }
Beispiel #5
0
 public ResultSetSpec(
     SelectClauseStreamSelectorEnum selectClauseStreamSelector,
     IList<OrderByItem> orderByList,
     SelectClauseSpecCompiled selectClauseSpec,
     InsertIntoDesc insertIntoDesc,
     GroupByClauseExpressions groupByClauseExpressions,
     ExprNode whereClause,
     ExprNode havingClause,
     OutputLimitSpec optionalOutputLimitSpec,
     RowLimitSpec rowLimitSpec,
     string contextName,
     ForClauseSpec forClauseSpec,
     IntoTableSpec intoTableSpec,
     StreamSpecCompiled[] streamSpecs,
     Attribute[] annotations)
 {
     this.SelectClauseStreamSelector = selectClauseStreamSelector;
     this.OrderByList = orderByList;
     this.SelectClauseSpec = selectClauseSpec;
     this.InsertIntoDesc = insertIntoDesc;
     this.GroupByClauseExpressions = groupByClauseExpressions;
     this.WhereClause = whereClause;
     this.HavingClause = havingClause;
     this.OptionalOutputLimitSpec = optionalOutputLimitSpec;
     this.RowLimitSpec = rowLimitSpec;
     this.ContextName = contextName;
     this.ForClauseSpec = forClauseSpec;
     this.IntoTableSpec = intoTableSpec;
     this.StreamSpecs = streamSpecs;
     this.Annotations = annotations;
 }
Beispiel #6
0
 public OutputProcessViewConditionForge(
     OutputStrategyPostProcessForge outputStrategyPostProcessForge,
     bool isDistinct,
     MultiKeyClassRef distinctMultiKey,
     ExprTimePeriod afterTimePeriodExpr,
     int? afterNumberOfEvents,
     OutputConditionFactoryForge outputConditionFactoryForge,
     int streamCount,
     ResultSetProcessorOutputConditionType conditionType,
     bool terminable,
     bool hasAfter,
     bool unaggregatedUngrouped,
     SelectClauseStreamSelectorEnum selectClauseStreamSelector,
     EventType[] eventTypes,
     EventType resultEventType)
 {
     _outputStrategyPostProcessForge = outputStrategyPostProcessForge;
     _isDistinct = isDistinct;
     _distinctMultiKey = distinctMultiKey;
     _afterTimePeriodExpr = afterTimePeriodExpr;
     _afterNumberOfEvents = afterNumberOfEvents;
     _outputConditionFactoryForge = outputConditionFactoryForge;
     _streamCount = streamCount;
     _conditionType = conditionType;
     _terminable = terminable;
     _hasAfter = hasAfter;
     _unaggregatedUngrouped = unaggregatedUngrouped;
     _selectClauseStreamSelector = selectClauseStreamSelector;
     _eventTypes = eventTypes;
     _resultEventType = resultEventType;
 }
Beispiel #7
0
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="streamSelector">selects insert, remove or insert+remove stream</param>
 /// <param name="eventTypeName">is the event type name</param>
 public InsertIntoDesc(
     SelectClauseStreamSelectorEnum streamSelector,
     String eventTypeName)
 {
     StreamSelector = streamSelector;
     EventTypeName  = eventTypeName;
     ColumnNames    = new List <String>();
 }
Beispiel #8
0
 /// <summary>Ctor. </summary>
 /// <param name="defaultStreamSelector">stream selection for the statement</param>
 public StatementSpecRaw(SelectClauseStreamSelectorEnum defaultStreamSelector)
 {
     OrderByList         = new List <OrderByItem>();
     StreamSpecs         = new List <StreamSpecRaw>();
     SelectClauseSpec    = new SelectClauseSpecRaw();
     OuterJoinDescList   = new List <OuterJoinDesc>();
     GroupByExpressions  = new List <GroupByClauseElement>();
     Annotations         = new List <AnnotationDesc>(1);
     SelectStreamDirEnum = defaultStreamSelector;
 }
Beispiel #9
0
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="runtimeSPI">The runtime SPI.</param>
 /// <param name="services">engine services</param>
 /// <param name="configurationOperations">configuration snapshot</param>
 /// <param name="defaultStreamSelector">default stream selection</param>
 public EPAdministratorContext(EPRuntimeSPI runtimeSPI,
                               EPServicesContext services,
                               ConfigurationOperations configurationOperations,
                               SelectClauseStreamSelectorEnum defaultStreamSelector
                               )
 {
     RuntimeSPI = runtimeSPI;
     ConfigurationOperations = configurationOperations;
     DefaultStreamSelector   = defaultStreamSelector;
     Services = services;
 }
Beispiel #10
0
 public OutputStrategyPostProcessForge(
     bool isRouted,
     SelectClauseStreamSelectorEnum? insertIntoStreamSelector,
     SelectClauseStreamSelectorEnum selectStreamSelector,
     bool routeToFront,
     TableMetaData table,
     bool audit)
 {
     this.isRouted = isRouted;
     this.insertIntoStreamSelector = insertIntoStreamSelector;
     this.selectStreamSelector = selectStreamSelector;
     this.routeToFront = routeToFront;
     this.table = table;
     this.audit = audit;
 }
        /// <summary>Constructor - takes the services context as argument. </summary>
        /// <param name="adminContext">administrative context</param>
        public EPAdministratorImpl(EPAdministratorContext adminContext)
        {
            _services = adminContext.Services;
            _configurationOperations = adminContext.ConfigurationOperations;
            _defaultStreamSelector   = adminContext.DefaultStreamSelector;

            _deploymentAdminService = new EPDeploymentAdminImpl(
                this,
                adminContext.Services.DeploymentStateService,
                adminContext.Services.StatementEventTypeRefService,
                adminContext.Services.EventAdapterService,
                adminContext.Services.StatementIsolationService,
                adminContext.Services.FilterService,
                _services.ConfigSnapshot.EngineDefaults.ExpressionConfig.TimeZone,
                _services.ConfigSnapshot.EngineDefaults.ExceptionHandlingConfig.UndeployRethrowPolicy);
        }
Beispiel #12
0
        /// <summary>Maps the internal stream selector to the SODA-representation</summary>
        /// <param name="selector">is the internal selector to map</param>
        /// <returns>SODA stream selector</returns>
        public static StreamSelector MapFromSODA(this SelectClauseStreamSelectorEnum selector)
        {
            switch (selector)
            {
            case SelectClauseStreamSelectorEnum.ISTREAM_ONLY:
                return(StreamSelector.ISTREAM_ONLY);

            case SelectClauseStreamSelectorEnum.RSTREAM_ONLY:
                return(StreamSelector.RSTREAM_ONLY);

            case SelectClauseStreamSelectorEnum.RSTREAM_ISTREAM_BOTH:
                return(StreamSelector.RSTREAM_ISTREAM_BOTH);

            default:
                throw new ArgumentException("Invalid selector '" + selector + "' encountered");
            }
        }
 public OutputStrategyPostProcessFactory(
     bool route,
     SelectClauseStreamSelectorEnum?insertIntoStreamSelector,
     SelectClauseStreamSelectorEnum selectStreamDirEnum,
     InternalEventRouter internalEventRouter,
     EPStatementHandle epStatementHandle,
     bool addToFront,
     TableService tableService,
     string tableName)
 {
     IsRoute = route;
     InsertIntoStreamSelector = insertIntoStreamSelector;
     SelectStreamDirEnum      = selectStreamDirEnum;
     InternalEventRouter      = internalEventRouter;
     EpStatementHandle        = epStatementHandle;
     IsAddToFront             = addToFront;
     TableService             = tableService;
     TableName = tableName;
 }
Beispiel #14
0
        public static StatementSpecRaw CompilePattern(String expression, String expressionForErrorMessage, bool addPleaseCheck, EPServicesContext services, SelectClauseStreamSelectorEnum defaultStreamSelector)
        {
            // Parse
            ParseResult parseResult = ParseHelper.Parse(expression, expressionForErrorMessage, addPleaseCheck, PatternParseRule, true);
            var         ast         = parseResult.Tree;

            if (Log.IsDebugEnabled)
            {
                ASTUtil.DumpAST(ast);
            }

            // Walk
            EPLTreeWalkerListener walker = new EPLTreeWalkerListener(
                parseResult.TokenStream,
                services.EngineImportService,
                services.VariableService,
                services.SchedulingService,
                defaultStreamSelector,
                services.EngineURI,
                services.ConfigSnapshot,
                services.PatternNodeFactory,
                services.ContextManagementService,
                parseResult.Scripts,
                services.ExprDeclaredService,
                services.TableService);

            try
            {
                ParseHelper.Walk(ast, walker, expression, expressionForErrorMessage);
            }
            catch (ASTWalkException ex)
            {
                Log.Debug(".createPattern Error validating expression", ex);
                throw new EPStatementException(ex.Message, expression);
            }
            catch (EPStatementSyntaxException ex)
            {
                throw;
            }
            catch (Exception ex)
            {
                String message = "Error in expression";
                Log.Debug(message, ex);
                throw new EPStatementException(GetNullableErrortext(message, ex.Message), expression);
            }

            var walkerStatementSpec = walker.GetStatementSpec();

            if (walkerStatementSpec.StreamSpecs.Count > 1)
            {
                throw new IllegalStateException("Unexpected multiple stream specifications encountered");
            }

            // Get pattern specification
            var patternStreamSpec = (PatternStreamSpecRaw)walkerStatementSpec.StreamSpecs[0];

            // Create statement spec, set pattern stream, set wildcard select
            var statementSpec = new StatementSpecRaw(SelectClauseStreamSelectorEnum.ISTREAM_ONLY);

            statementSpec.StreamSpecs.Add(patternStreamSpec);
            statementSpec.SelectClauseSpec.SelectExprList.Clear();
            statementSpec.SelectClauseSpec.SelectExprList.Add(new SelectClauseElementWildcard());
            statementSpec.Annotations             = walkerStatementSpec.Annotations;
            statementSpec.ExpressionNoAnnotations = parseResult.ExpressionWithoutAnnotations;

            return(statementSpec);
        }
Beispiel #15
0
 public static bool IsSelectsIStream(this SelectClauseStreamSelectorEnum selector)
 {
     return(selector != SelectClauseStreamSelectorEnum.RSTREAM_ONLY);
 }
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="onTriggerDesc">describes on-delete statements</param>
 /// <param name="createWindowDesc">describes create-window statements</param>
 /// <param name="createIndexDesc">when an index get</param>
 /// <param name="createVariableDesc">describes create-variable statements</param>
 /// <param name="createTableDesc">The create table desc.</param>
 /// <param name="createSchemaDesc">The create schema desc.</param>
 /// <param name="insertIntoDesc">insert into def</param>
 /// <param name="selectClauseStreamSelectorEnum">stream selection</param>
 /// <param name="selectClauseSpec">select clause</param>
 /// <param name="streamSpecs">specs for streams</param>
 /// <param name="outerJoinDescList">outer join def</param>
 /// <param name="filterExprRootNode">where filter expr nodes</param>
 /// <param name="havingExprRootNode">having expression</param>
 /// <param name="outputLimitSpec">output limit</param>
 /// <param name="orderByList">order by</param>
 /// <param name="subSelectExpressions">list of subqueries</param>
 /// <param name="declaredExpressions">The declared expressions.</param>
 /// <param name="variableReferences">variables referenced</param>
 /// <param name="rowLimitSpec">row limit specification, or null if none supplied</param>
 /// <param name="eventTypeReferences">event type names statically determined</param>
 /// <param name="annotations">statement annotations</param>
 /// <param name="updateSpec">update specification if used</param>
 /// <param name="matchRecognizeSpec">if provided</param>
 /// <param name="forClauseSpec">For clause spec.</param>
 /// <param name="sqlParameters">The SQL parameters.</param>
 /// <param name="contextDesc">The context desc.</param>
 /// <param name="optionalContextName">Name of the optional context.</param>
 /// <param name="createGraphDesc">The create graph desc.</param>
 /// <param name="createExpressionDesc">The create expression desc.</param>
 /// <param name="fireAndForgetSpec">The fire and forget spec.</param>
 /// <param name="groupByExpressions">The group by expressions.</param>
 /// <param name="intoTableSpec">The into table spec.</param>
 /// <param name="tableNodes">The table nodes.</param>
 public StatementSpecCompiled(OnTriggerDesc onTriggerDesc,
                              CreateWindowDesc createWindowDesc,
                              CreateIndexDesc createIndexDesc,
                              CreateVariableDesc createVariableDesc,
                              CreateTableDesc createTableDesc,
                              CreateSchemaDesc createSchemaDesc,
                              InsertIntoDesc insertIntoDesc,
                              SelectClauseStreamSelectorEnum selectClauseStreamSelectorEnum,
                              SelectClauseSpecCompiled selectClauseSpec,
                              StreamSpecCompiled[] streamSpecs,
                              OuterJoinDesc[] outerJoinDescList,
                              ExprNode filterExprRootNode,
                              ExprNode havingExprRootNode,
                              OutputLimitSpec outputLimitSpec,
                              OrderByItem[] orderByList,
                              ExprSubselectNode[] subSelectExpressions,
                              ExprDeclaredNode[] declaredExpressions,
                              ICollection <string> variableReferences,
                              RowLimitSpec rowLimitSpec,
                              string[] eventTypeReferences,
                              Attribute[] annotations,
                              UpdateDesc updateSpec,
                              MatchRecognizeSpec matchRecognizeSpec,
                              ForClauseSpec forClauseSpec,
                              IDictionary <int, IList <ExprNode> > sqlParameters,
                              CreateContextDesc contextDesc,
                              string optionalContextName,
                              CreateDataFlowDesc createGraphDesc,
                              CreateExpressionDesc createExpressionDesc,
                              FireAndForgetSpec fireAndForgetSpec,
                              GroupByClauseExpressions groupByExpressions,
                              IntoTableSpec intoTableSpec,
                              ExprTableAccessNode[] tableNodes)
 {
     OnTriggerDesc             = onTriggerDesc;
     CreateWindowDesc          = createWindowDesc;
     CreateIndexDesc           = createIndexDesc;
     CreateVariableDesc        = createVariableDesc;
     CreateTableDesc           = createTableDesc;
     CreateSchemaDesc          = createSchemaDesc;
     InsertIntoDesc            = insertIntoDesc;
     SelectStreamDirEnum       = selectClauseStreamSelectorEnum;
     SelectClauseSpec          = selectClauseSpec;
     StreamSpecs               = streamSpecs;
     OuterJoinDescList         = outerJoinDescList;
     FilterExprRootNode        = filterExprRootNode;
     HavingExprRootNode        = havingExprRootNode;
     OutputLimitSpec           = outputLimitSpec;
     OrderByList               = orderByList;
     this.SubSelectExpressions = subSelectExpressions;
     DeclaredExpressions       = declaredExpressions;
     VariableReferences        = variableReferences;
     RowLimitSpec              = rowLimitSpec;
     EventTypeReferences       = eventTypeReferences;
     Annotations               = annotations;
     UpdateSpec           = updateSpec;
     MatchRecognizeSpec   = matchRecognizeSpec;
     ForClauseSpec        = forClauseSpec;
     SqlParameters        = sqlParameters;
     ContextDesc          = contextDesc;
     OptionalContextName  = optionalContextName;
     CreateGraphDesc      = createGraphDesc;
     CreateExpressionDesc = createExpressionDesc;
     FireAndForgetSpec    = fireAndForgetSpec;
     GroupByExpressions   = groupByExpressions;
     IntoTableSpec        = intoTableSpec;
     TableNodes           = tableNodes;
 }
Beispiel #17
0
        public static OutputProcessViewFactory Make(
            StatementSpecCompiled statementSpec,
            InternalEventRouter internalEventRouter,
            StatementContext statementContext,
            EventType resultEventType,
            OutputProcessViewCallback optionalOutputProcessViewCallback,
            TableService tableService,
            ResultSetProcessorType resultSetProcessorType,
            ResultSetProcessorHelperFactory resultSetProcessorHelperFactory,
            StatementVariableRef statementVariableRef)
        {
            // determine direct-callback
            if (optionalOutputProcessViewCallback != null)
            {
                return(new OutputProcessViewFactoryCallback(optionalOutputProcessViewCallback));
            }

            // determine routing
            bool isRouted     = false;
            bool routeToFront = false;

            if (statementSpec.InsertIntoDesc != null)
            {
                isRouted     = true;
                routeToFront =
                    statementContext.NamedWindowMgmtService.IsNamedWindow(statementSpec.InsertIntoDesc.EventTypeName);
            }

            OutputStrategyPostProcessFactory outputStrategyPostProcessFactory = null;

            if ((statementSpec.InsertIntoDesc != null) ||
                (statementSpec.SelectStreamSelectorEnum == SelectClauseStreamSelectorEnum.RSTREAM_ONLY))
            {
                SelectClauseStreamSelectorEnum?insertIntoStreamSelector = null;
                string tableName = null;

                if (statementSpec.InsertIntoDesc != null)
                {
                    insertIntoStreamSelector = statementSpec.InsertIntoDesc.StreamSelector;
                    TableMetadata tableMetadata =
                        tableService.GetTableMetadata(statementSpec.InsertIntoDesc.EventTypeName);
                    if (tableMetadata != null)
                    {
                        tableName = tableMetadata.TableName;
                        EPLValidationUtil.ValidateContextName(
                            true, tableName, tableMetadata.ContextName, statementSpec.OptionalContextName, true);
                        statementVariableRef.AddReferences(statementContext.StatementName, tableMetadata.TableName);
                    }
                }

                outputStrategyPostProcessFactory = new OutputStrategyPostProcessFactory(
                    isRouted, insertIntoStreamSelector, statementSpec.SelectStreamSelectorEnum, internalEventRouter,
                    statementContext.EpStatementHandle, routeToFront, tableService, tableName);
            }

            // Do we need to enforce an output policy?
            int             streamCount     = statementSpec.StreamSpecs.Length;
            OutputLimitSpec outputLimitSpec = statementSpec.OutputLimitSpec;
            bool            isDistinct      = statementSpec.SelectClauseSpec.IsDistinct;
            bool            isGrouped       = statementSpec.GroupByExpressions != null &&
                                              statementSpec.GroupByExpressions.GroupByNodes.Length > 0;

            OutputProcessViewFactory outputProcessViewFactory;

            if (outputLimitSpec == null)
            {
                if (!isDistinct)
                {
                    outputProcessViewFactory = new OutputProcessViewDirectFactory(
                        statementContext, outputStrategyPostProcessFactory, resultSetProcessorHelperFactory);
                }
                else
                {
                    outputProcessViewFactory = new OutputProcessViewDirectDistinctOrAfterFactory(
                        statementContext, outputStrategyPostProcessFactory, resultSetProcessorHelperFactory, isDistinct,
                        null, null, resultEventType);
                }
            }
            else if (outputLimitSpec.RateType == OutputLimitRateType.AFTER)
            {
                outputProcessViewFactory = new OutputProcessViewDirectDistinctOrAfterFactory(
                    statementContext, outputStrategyPostProcessFactory, resultSetProcessorHelperFactory, isDistinct,
                    outputLimitSpec.AfterTimePeriodExpr, outputLimitSpec.AfterNumberOfEvents, resultEventType);
            }
            else
            {
                try
                {
                    bool isWithHavingClause         = statementSpec.HavingExprRootNode != null;
                    bool isStartConditionOnCreation = HasOnlyTables(statementSpec.StreamSpecs);
                    OutputConditionFactory outputConditionFactory =
                        OutputConditionFactoryFactory.CreateCondition(
                            outputLimitSpec, statementContext, isGrouped, isWithHavingClause, isStartConditionOnCreation,
                            resultSetProcessorHelperFactory);
                    bool hasOrderBy = statementSpec.OrderByList != null && statementSpec.OrderByList.Length > 0;
                    OutputProcessViewConditionFactory.ConditionType conditionType;
                    bool hasAfter = outputLimitSpec.AfterNumberOfEvents != null ||
                                    outputLimitSpec.AfterTimePeriodExpr != null;
                    bool isUnaggregatedUngrouped = resultSetProcessorType == ResultSetProcessorType.HANDTHROUGH ||
                                                   resultSetProcessorType ==
                                                   ResultSetProcessorType.UNAGGREGATED_UNGROUPED;

                    // hint checking with order-by
                    bool hasOptHint = HintEnum.ENABLE_OUTPUTLIMIT_OPT.GetHint(statementSpec.Annotations) != null;
                    if (hasOptHint && hasOrderBy)
                    {
                        throw new ExprValidationException(
                                  "The " + HintEnum.ENABLE_OUTPUTLIMIT_OPT + " hint is not supported with order-by");
                    }

                    if (outputLimitSpec.DisplayLimit == OutputLimitLimitType.SNAPSHOT)
                    {
                        conditionType = OutputProcessViewConditionFactory.ConditionType.SNAPSHOT;
                    }
                    else if (outputLimitSpec.DisplayLimit == OutputLimitLimitType.FIRST &&
                             statementSpec.GroupByExpressions == null)
                    {
                        // For FIRST without groups we are using a special logic that integrates the first-flag, in order to still conveniently use all sorts of output conditions.
                        // FIRST with group-by is handled by setting the output condition to null (OutputConditionNull) and letting the ResultSetProcessor handle first-per-group.
                        // Without having-clause there is no required order of processing, thus also use regular policy.
                        conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_FIRST;
                    }
                    else if (isUnaggregatedUngrouped && outputLimitSpec.DisplayLimit == OutputLimitLimitType.LAST)
                    {
                        conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_LASTALL_UNORDERED;
                    }
                    else if (hasOptHint && outputLimitSpec.DisplayLimit == OutputLimitLimitType.ALL && !hasOrderBy)
                    {
                        conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_LASTALL_UNORDERED;
                    }
                    else if (hasOptHint && outputLimitSpec.DisplayLimit == OutputLimitLimitType.LAST && !hasOrderBy)
                    {
                        conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_LASTALL_UNORDERED;
                    }
                    else
                    {
                        conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_NONFIRST;
                    }

                    SelectClauseStreamSelectorEnum selectClauseStreamSelectorEnum =
                        statementSpec.SelectStreamSelectorEnum;
                    bool terminable = outputLimitSpec.RateType == OutputLimitRateType.TERM ||
                                      outputLimitSpec.IsAndAfterTerminate;
                    outputProcessViewFactory = new OutputProcessViewConditionFactory(
                        statementContext, outputStrategyPostProcessFactory, isDistinct,
                        outputLimitSpec.AfterTimePeriodExpr, outputLimitSpec.AfterNumberOfEvents, resultEventType,
                        outputConditionFactory, streamCount, conditionType, outputLimitSpec.DisplayLimit, terminable,
                        hasAfter, isUnaggregatedUngrouped, selectClauseStreamSelectorEnum,
                        resultSetProcessorHelperFactory);
                }
                catch (Exception ex)
                {
                    throw new ExprValidationException("Error in the output rate limiting clause: " + ex.Message, ex);
                }
            }

            return(outputProcessViewFactory);
        }
        public static OutputProcessViewFactoryForgeDesc Make(
            EventType[] typesPerStream,
            EventType resultEventType,
            ResultSetProcessorType resultSetProcessorType,
            StatementSpecCompiled statementSpec,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            InsertIntoDesc insertIntoDesc = statementSpec.Raw.InsertIntoDesc;
            SelectClauseStreamSelectorEnum selectStreamSelector = statementSpec.Raw.SelectStreamSelectorEnum;
            OutputLimitSpec outputLimitSpec = statementSpec.Raw.OutputLimitSpec;
            int streamCount = statementSpec.StreamSpecs.Length;
            bool isDistinct = statementSpec.Raw.SelectClauseSpec.IsDistinct;
            bool isGrouped = statementSpec.GroupByExpressions != null &&
                             statementSpec.GroupByExpressions.GroupByNodes.Length > 0;
            List<StmtClassForgeableFactory> additionalForgeables = new List<StmtClassForgeableFactory>();

            // determine routing
            bool isRouted = false;
            bool routeToFront = false;
            if (insertIntoDesc != null) {
                isRouted = true;
                routeToFront = services.NamedWindowCompileTimeResolver.Resolve(insertIntoDesc.EventTypeName) != null;
            }

            OutputStrategyPostProcessForge outputStrategyPostProcessForge = null;
            if ((insertIntoDesc != null) || (selectStreamSelector == SelectClauseStreamSelectorEnum.RSTREAM_ONLY)) {
                SelectClauseStreamSelectorEnum? insertIntoStreamSelector = null;
                TableMetaData table = null;

                if (insertIntoDesc != null) {
                    insertIntoStreamSelector = insertIntoDesc.StreamSelector;
                    table = services.TableCompileTimeResolver.Resolve(statementSpec.Raw.InsertIntoDesc.EventTypeName);
                    if (table != null) {
                        EPLValidationUtil.ValidateContextName(
                            true,
                            table.TableName,
                            table.OptionalContextName,
                            statementSpec.Raw.OptionalContextName,
                            true);
                    }
                }

                bool audit = AuditEnum.INSERT.GetAudit(statementSpec.Annotations) != null;
                outputStrategyPostProcessForge = new OutputStrategyPostProcessForge(
                    isRouted,
                    insertIntoStreamSelector,
                    selectStreamSelector,
                    routeToFront,
                    table,
                    audit);
            }

            MultiKeyPlan multiKeyPlan = MultiKeyPlanner.PlanMultiKeyDistinct(
                isDistinct,
                resultEventType,
                statementRawInfo,
                SerdeCompileTimeResolverNonHA.INSTANCE);
            MultiKeyClassRef distinctMultiKey = multiKeyPlan.ClassRef;
            additionalForgeables.AddRange(multiKeyPlan.MultiKeyForgeables);

            OutputProcessViewFactoryForge outputProcessViewFactoryForge;
            if (outputLimitSpec == null) {
                if (!isDistinct) {
                    if (outputStrategyPostProcessForge == null || !outputStrategyPostProcessForge.HasTable) {
                        // without table we have a shortcut implementation
                        outputProcessViewFactoryForge =
                            new OutputProcessViewDirectSimpleForge(outputStrategyPostProcessForge);
                    }
                    else {
                        outputProcessViewFactoryForge =
                            new OutputProcessViewDirectForge(outputStrategyPostProcessForge);
                    }
                }
                else {
                    outputProcessViewFactoryForge = new OutputProcessViewDirectDistinctOrAfterFactoryForge(
                        outputStrategyPostProcessForge,
                        isDistinct,
                        distinctMultiKey,
                        null,
                        null,
                        resultEventType);
                }
            }
            else if (outputLimitSpec.RateType == OutputLimitRateType.AFTER) {
                outputProcessViewFactoryForge = new OutputProcessViewDirectDistinctOrAfterFactoryForge(
                    outputStrategyPostProcessForge,
                    isDistinct,
                    distinctMultiKey,
                    outputLimitSpec.AfterTimePeriodExpr,
                    outputLimitSpec.AfterNumberOfEvents,
                    resultEventType);
            }
            else {
                try {
                    bool isWithHavingClause = statementSpec.Raw.HavingClause != null;
                    bool isStartConditionOnCreation = HasOnlyTables(statementSpec.StreamSpecs);
                    OutputConditionFactoryForge outputConditionFactoryForge =
                        OutputConditionFactoryFactory.CreateCondition(
                            outputLimitSpec,
                            isGrouped,
                            isWithHavingClause,
                            isStartConditionOnCreation,
                            statementRawInfo,
                            services);
                    bool hasOrderBy = statementSpec.Raw.OrderByList != null && statementSpec.Raw.OrderByList.Count > 0;
                    bool hasAfter = outputLimitSpec.AfterNumberOfEvents != null ||
                                    outputLimitSpec.AfterTimePeriodExpr != null;

                    // hint checking with order-by
                    bool hasOptHint = ResultSetProcessorOutputConditionTypeExtensions
                        .GetOutputLimitOpt(statementSpec.Annotations, services.Configuration, hasOrderBy);
                    ResultSetProcessorOutputConditionType conditionType =
                        ResultSetProcessorOutputConditionTypeExtensions
                            .GetConditionType(
                                outputLimitSpec.DisplayLimit,
                                resultSetProcessorType.IsAggregated(),
                                hasOrderBy,
                                hasOptHint,
                                resultSetProcessorType.IsGrouped());

                    // plan serdes
                    foreach (EventType eventType in typesPerStream) {
                        IList<StmtClassForgeableFactory> serdeForgeables = SerdeEventTypeUtility.Plan(
                            eventType,
                            statementRawInfo,
                            services.SerdeEventTypeRegistry,
                            services.SerdeResolver);
                        additionalForgeables.AddRange(serdeForgeables);
                    }
                    
                    bool terminable = outputLimitSpec.RateType == OutputLimitRateType.TERM ||
                                      outputLimitSpec.IsAndAfterTerminate;
                    outputProcessViewFactoryForge = new OutputProcessViewConditionForge(
                        outputStrategyPostProcessForge,
                        isDistinct,
                        distinctMultiKey,
                        outputLimitSpec.AfterTimePeriodExpr,
                        outputLimitSpec.AfterNumberOfEvents,
                        outputConditionFactoryForge,
                        streamCount,
                        conditionType,
                        terminable,
                        hasAfter,
                        resultSetProcessorType.IsUnaggregatedUngrouped(),
                        selectStreamSelector,
                        typesPerStream,
                        resultEventType);
                }
                catch (Exception ex) {
                    throw new ExprValidationException("Failed to validate the output rate limiting clause: " + ex.Message, ex);
                }
            }
            
            return new OutputProcessViewFactoryForgeDesc(outputProcessViewFactoryForge, additionalForgeables);
        }
Beispiel #19
0
 /// <summary>
 ///     Ctor.
 /// </summary>
 /// <param name="defaultStreamSelector">stream selection for the statement</param>
 public StatementSpecRaw(SelectClauseStreamSelectorEnum defaultStreamSelector)
 {
     SelectStreamSelectorEnum = defaultStreamSelector;
 }
 public static bool IsSelectsIStream(this SelectClauseStreamSelectorEnum value)
 {
     return value != SelectClauseStreamSelectorEnum.RSTREAM_ONLY;
 }