示例#1
0
 /// <summary>
 ///     Constructor - validates parameter list against event type, throws exception if invalid
 ///     property names or mismatcing filter operators are found.
 /// </summary>
 /// <param name="eventType">is the event type</param>
 /// <param name="filterParameters">is a list of filter parameters</param>
 /// <param name="eventTypeName">is the name of the event type</param>
 /// <param name="optionalPropertyEvaluator">optional if evaluating properties returned by filtered events</param>
 /// <throws>ArgumentException if validation invalid</throws>
 public FilterSpecCompiled(
     EventType eventType,
     string eventTypeName,
     IList<FilterSpecParamForge>[] filterParameters,
     PropertyEvaluatorForge optionalPropertyEvaluator)
 {
     FilterForEventType = eventType;
     FilterForEventTypeName = eventTypeName;
     Parameters = SortRemoveDups(filterParameters);
     OptionalPropertyEvaluator = optionalPropertyEvaluator;
 }
示例#2
0
        public static FilterSpecCompiled BuildNoStmtCtx(
            IList<ExprNode> validatedNodes,
            EventType eventType,
            string eventTypeName,
            string optionalStreamName,
            PropertyEvalSpec optionalPropertyEvalSpec,
            IDictionary<string, Pair<EventType, string>> taggedEventTypes,
            IDictionary<string, Pair<EventType, string>> arrayEventTypes,
            ISet<string> allTagNamesOrdered,
            StreamTypeService streamTypeService,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices compileTimeServices)
        {
            PropertyEvaluatorForge optionalPropertyEvaluator = null;
            if (optionalPropertyEvalSpec != null) {
                optionalPropertyEvaluator = PropertyEvaluatorForgeFactory.MakeEvaluator(
                    optionalPropertyEvalSpec,
                    eventType,
                    optionalStreamName,
                    statementRawInfo,
                    compileTimeServices);
            }

            // unwind "and" and "or"
            var unwound = FilterSpecCompilerIndexPlannerUnwindAndOr.UnwindAndOr(validatedNodes);

            var args = new FilterSpecCompilerArgs(
                taggedEventTypes,
                arrayEventTypes,
                allTagNamesOrdered,
                streamTypeService,
                null,
                statementRawInfo,
                compileTimeServices);
            var plan = FilterSpecCompilerIndexPlanner.PlanFilterParameters(unwound, args);

            var hook = (FilterSpecCompileHook) ImportUtil.GetAnnotationHook(
                statementRawInfo.Annotations,
                HookType.INTERNAL_FILTERSPEC,
                typeof(FilterSpecCompileHook),
                compileTimeServices.ImportServiceCompileTime);
            hook?.FilterIndexPlan(eventType, unwound, plan);

            if (compileTimeServices.Configuration.Compiler.Logging.IsEnableFilterPlan) {
                LogFilterPlans(unwound, plan, eventType, optionalStreamName, statementRawInfo);
            }

            if (Log.IsDebugEnabled) {
                Log.Debug(".makeFilterSpec spec=" + plan);
            }

            return new FilterSpecCompiled(eventType, eventTypeName, plan, optionalPropertyEvaluator);
        }
示例#3
0
 public OnSplitItemForge(
     ExprNode whereClause,
     bool isNamedWindowInsert,
     TableMetaData insertIntoTable,
     ResultSetProcessorDesc resultSetProcessorDesc,
     PropertyEvaluatorForge propertyEvaluator)
 {
     WhereClause = whereClause;
     IsNamedWindowInsert = isNamedWindowInsert;
     InsertIntoTable = insertIntoTable;
     ResultSetProcessorDesc = resultSetProcessorDesc;
     PropertyEvaluator = propertyEvaluator;
 }
示例#4
0
 public NamedWindowConsumerStreamSpec(
     NamedWindowMetaData namedWindow,
     string optionalAsName,
     ViewSpec[] viewSpecs,
     IList<ExprNode> filterExpressions,
     StreamSpecOptions streamSpecOptions,
     PropertyEvaluatorForge optPropertyEvaluator)
     : base(optionalAsName, viewSpecs, streamSpecOptions)
 {
     NamedWindow = namedWindow;
     FilterExpressions = filterExpressions;
     OptPropertyEvaluator = optPropertyEvaluator;
 }
示例#5
0
 public ViewableActivatorNamedWindowForge(
     NamedWindowConsumerStreamSpec spec,
     NamedWindowMetaData namedWindow,
     ExprNode filterEvaluator,
     QueryGraphForge filterQueryGraph,
     bool subquery,
     PropertyEvaluatorForge optPropertyEvaluator)
 {
     this.spec = spec;
     this.namedWindow = namedWindow;
     this.filterEvaluator = filterEvaluator;
     this.filterQueryGraph = filterQueryGraph;
     this.subquery = subquery;
     this.optPropertyEvaluator = optPropertyEvaluator;
 }
示例#6
0
        public bool CompareTo(PropertyEvaluatorForge otherEval)
        {
            if (!(otherEval is PropertyEvaluatorSimpleForge)) {
                return false;
            }

            var other = (PropertyEvaluatorSimpleForge) otherEval;
            if (!other.ExpressionText.Equals(ExpressionText)) {
                return false;
            }

            if (other.Filter == null && Filter == null) {
                return true;
            }

            return false;
        }
示例#7
0
        public static FilterSpecCompiled BuildNoStmtCtx(
            IList<ExprNode> validatedNodes,
            EventType eventType,
            string eventTypeName,
            string optionalStreamName,
            PropertyEvalSpec optionalPropertyEvalSpec,
            IDictionary<string, Pair<EventType, string>> taggedEventTypes,
            IDictionary<string, Pair<EventType, string>> arrayEventTypes,
            StreamTypeService streamTypeService,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices compileTimeServices
        )
        {
            PropertyEvaluatorForge optionalPropertyEvaluator = null;
            if (optionalPropertyEvalSpec != null) {
                optionalPropertyEvaluator = PropertyEvaluatorForgeFactory.MakeEvaluator(
                    optionalPropertyEvalSpec,
                    eventType,
                    optionalStreamName,
                    statementRawInfo,
                    compileTimeServices);
            }

            var args = new FilterSpecCompilerArgs(
                taggedEventTypes,
                arrayEventTypes,
                streamTypeService,
                null,
                statementRawInfo,
                compileTimeServices);
            IList<FilterSpecParamForge>[] spec = FilterSpecCompilerPlanner.PlanFilterParameters(validatedNodes, args);

            if (Log.IsDebugEnabled) {
                Log.Debug(".makeFilterSpec spec=" + spec);
            }

            return new FilterSpecCompiled(eventType, eventTypeName, spec, optionalPropertyEvaluator);
        }
示例#8
0
 private static OnSplitItemForge OnSplitValidate(
     StreamTypeService typeServiceTrigger,
     StatementSpecCompiled statementSpecCompiled,
     ContextPropertyRegistry contextPropertyRegistry,
     PropertyEvaluatorForge optionalPropertyEval,
     StatementRawInfo rawInfo,
     StatementCompileTimeServices services)
 {
     var insertIntoName = statementSpecCompiled.Raw.InsertIntoDesc.EventTypeName;
     var isNamedWindowInsert = services.NamedWindowCompileTimeResolver.Resolve(insertIntoName) != null;
     var table = services.TableCompileTimeResolver.Resolve(insertIntoName);
     EPStatementStartMethodHelperValidate.ValidateNodes(
         statementSpecCompiled.Raw,
         typeServiceTrigger,
         null,
         rawInfo,
         services);
     var spec = new ResultSetSpec(statementSpecCompiled);
     var factoryDescs = ResultSetProcessorFactoryFactory.GetProcessorPrototype(
         spec,
         typeServiceTrigger,
         null,
         new bool[0],
         false,
         contextPropertyRegistry,
         false,
         true,
         rawInfo,
         services);
     return new OnSplitItemForge(
         statementSpecCompiled.Raw.WhereClause,
         isNamedWindowInsert,
         table,
         factoryDescs,
         optionalPropertyEval);
 }
示例#9
0
        public static StreamSpecCompiled CompileFilter(
            FilterStreamSpecRaw streamSpec,
            bool isInsertInto,
            bool isJoin,
            bool isContextDeclaration,
            bool isOnTrigger,
            string optionalStreamName,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            // Determine the event type
            var rawFilterSpec = streamSpec.RawFilterSpec;
            var eventTypeName = rawFilterSpec.EventTypeName;

            var table = services.TableCompileTimeResolver.Resolve(eventTypeName);
            if (table != null) {
                if (streamSpec.ViewSpecs != null && streamSpec.ViewSpecs.Length > 0) {
                    throw new ExprValidationException("Views are not supported with tables");
                }

                if (streamSpec.RawFilterSpec.OptionalPropertyEvalSpec != null) {
                    throw new ExprValidationException("Contained-event expressions are not supported with tables");
                }

                StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                    new[] {table.InternalEventType},
                    new[] {optionalStreamName},
                    new[] {true},
                    false,
                    false);
                var validatedNodes = FilterSpecCompiler.ValidateAllowSubquery(
                    ExprNodeOrigin.FILTER,
                    rawFilterSpec.FilterExpressions,
                    streamTypeService,
                    null,
                    null,
                    statementRawInfo,
                    services);
                return new TableQueryStreamSpec(
                    streamSpec.OptionalStreamName,
                    streamSpec.ViewSpecs,
                    streamSpec.Options,
                    table,
                    validatedNodes);
            }

            // Could be a named window
            var namedWindowInfo = services.NamedWindowCompileTimeResolver.Resolve(eventTypeName);
            if (namedWindowInfo != null) {
                StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                    new[] {namedWindowInfo.EventType},
                    new[] {optionalStreamName},
                    new[] {true},
                    false,
                    false);

                var validatedNodes = FilterSpecCompiler.ValidateAllowSubquery(
                    ExprNodeOrigin.FILTER,
                    rawFilterSpec.FilterExpressions,
                    streamTypeService,
                    null,
                    null,
                    statementRawInfo,
                    services);

                PropertyEvaluatorForge optionalPropertyEvaluator = null;
                if (rawFilterSpec.OptionalPropertyEvalSpec != null) {
                    optionalPropertyEvaluator = PropertyEvaluatorForgeFactory.MakeEvaluator(
                        rawFilterSpec.OptionalPropertyEvalSpec,
                        namedWindowInfo.EventType,
                        streamSpec.OptionalStreamName,
                        statementRawInfo,
                        services);
                }

                return new NamedWindowConsumerStreamSpec(
                    namedWindowInfo,
                    streamSpec.OptionalStreamName,
                    streamSpec.ViewSpecs,
                    validatedNodes,
                    streamSpec.Options,
                    optionalPropertyEvaluator);
            }

            var eventType = ResolveTypeName(eventTypeName, services.EventTypeCompileTimeResolver);

            // Validate all nodes, make sure each returns a boolean and types are good;
            // Also decompose all AND super nodes into individual expressions
            StreamTypeService streamTypeServiceX = new StreamTypeServiceImpl(
                new[] {eventType},
                new[] {streamSpec.OptionalStreamName},
                new[] {true},
                false,
                false);

            var spec = FilterSpecCompiler.MakeFilterSpec(
                eventType,
                eventTypeName,
                rawFilterSpec.FilterExpressions,
                rawFilterSpec.OptionalPropertyEvalSpec,
                null,
                null, // no tags
                streamTypeServiceX,
                streamSpec.OptionalStreamName,
                statementRawInfo,
                services);

            return new FilterStreamSpecCompiled(
                spec,
                streamSpec.ViewSpecs,
                streamSpec.OptionalStreamName,
                streamSpec.Options);
        }
示例#10
0
        public static OnTriggerPlan HandleSplitStream(
            string aiFactoryProviderClassName,
            CodegenNamespaceScope namespaceScope,
            string classPostfix,
            OnTriggerSplitStreamDesc desc,
            StreamSpecCompiled streamSpec,
            OnTriggerActivatorDesc activatorResult,
            IDictionary<ExprSubselectNode, SubSelectActivationPlan> subselectActivation,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var raw = @base.StatementSpec.Raw;
            if (raw.InsertIntoDesc == null) {
                throw new ExprValidationException(
                    "Required insert-into clause is not provided, the clause is required for split-stream syntax");
            }

            if (raw.GroupByExpressions != null && raw.GroupByExpressions.Count > 0 ||
                raw.HavingClause != null ||
                raw.OrderByList.Count > 0) {
                throw new ExprValidationException(
                    "A group-by clause, having-clause or order-by clause is not allowed for the split stream syntax");
            }

            var streamName = streamSpec.OptionalStreamName;
            if (streamName == null) {
                streamName = "stream_0";
            }

            StreamTypeService typeServiceTrigger = new StreamTypeServiceImpl(
                new[] {activatorResult.ActivatorResultEventType},
                new[] {streamName},
                new[] {true},
                false,
                false);

            // materialize sub-select views
            var subselectForges = SubSelectHelperForgePlanner.PlanSubSelect(
                @base,
                subselectActivation,
                new[] {streamSpec.OptionalStreamName},
                new[] {activatorResult.ActivatorResultEventType},
                new[] {activatorResult.TriggerEventTypeName},
                services);

            // compile top-level split
            var items = new OnSplitItemForge[desc.SplitStreams.Count + 1];
            items[0] = OnSplitValidate(
                typeServiceTrigger,
                @base.StatementSpec,
                @base.ContextPropertyRegistry,
                null,
                @base.StatementRawInfo,
                services);

            // compile each additional split
            var index = 1;
            foreach (var splits in desc.SplitStreams) {
                var splitSpec = new StatementSpecCompiled();

                splitSpec.Raw.InsertIntoDesc = splits.InsertInto;
                splitSpec.SelectClauseCompiled = CompileSelectAllowSubselect(splits.SelectClause);
                splitSpec.Raw.WhereClause = splits.WhereClause;

                PropertyEvaluatorForge optionalPropertyEvaluator = null;
                StreamTypeService typeServiceProperty;
                if (splits.FromClause != null) {
                    optionalPropertyEvaluator = PropertyEvaluatorForgeFactory.MakeEvaluator(
                        splits.FromClause.PropertyEvalSpec,
                        activatorResult.ActivatorResultEventType,
                        streamName,
                        @base.StatementRawInfo,
                        services);
                    typeServiceProperty = new StreamTypeServiceImpl(
                        new[] {optionalPropertyEvaluator.FragmentEventType},
                        new[] {splits.FromClause.OptionalStreamName},
                        new[] {true},
                        false,
                        false);
                }
                else {
                    typeServiceProperty = typeServiceTrigger;
                }

                items[index] = OnSplitValidate(
                    typeServiceProperty,
                    splitSpec,
                    @base.ContextPropertyRegistry,
                    optionalPropertyEvaluator,
                    @base.StatementRawInfo,
                    services);
                index++;
            }

            // handle result set processor classes
            IList<StmtClassForgable> forgables = new List<StmtClassForgable>();
            for (var i = 0; i < items.Length; i++) {
                var classNameRSP = CodeGenerationIDGenerator.GenerateClassNameSimple(
                    typeof(ResultSetProcessorFactoryProvider),
                    classPostfix + "_" + i);
                forgables.Add(
                    new StmtClassForgableRSPFactoryProvider(
                        classNameRSP,
                        items[i].ResultSetProcessorDesc,
                        namespaceScope,
                        @base.StatementRawInfo));
                items[i].ResultSetProcessorClassName = classNameRSP;
            }

            // plan table access
            var tableAccessForges = ExprTableEvalHelperPlan.PlanTableAccess(@base.StatementSpec.TableAccessNodes);

            // build forge
            var splitStreamForge = new StatementAgentInstanceFactoryOnTriggerSplitStreamForge(
                activatorResult.Activator,
                activatorResult.ActivatorResultEventType,
                subselectForges,
                tableAccessForges,
                items,
                desc.IsFirst);
            var triggerForge = new StmtClassForgableAIFactoryProviderOnTrigger(
                aiFactoryProviderClassName,
                namespaceScope,
                splitStreamForge);

            return new OnTriggerPlan(triggerForge, forgables, new SelectSubscriberDescriptor());
        }
示例#11
0
 public bool CompareTo(PropertyEvaluatorForge other)
 {
     return false;
 }