Exemple #1
0
        private static IList<FilterSpecParamForge> ComputePermutation(
            FilterSpecParaForgeMap filterParamExprMap,
            object[] permutation,
            FilterSpecParaForgeMap[][] orNodesMaps,
            FilterSpecCompilerArgs args)
        {
            FilterSpecParaForgeMap mapAll = new FilterSpecParaForgeMap();
            mapAll.Add(filterParamExprMap);

            // combine
            for (int orNodeNum = 0; orNodeNum < permutation.Length; orNodeNum++) {
                int orChildNodeNum = (int) permutation[orNodeNum];
                FilterSpecParaForgeMap mapOrSub = orNodesMaps[orNodeNum][orChildNodeNum];
                mapAll.Add(mapOrSub);
            }

            // consolidate across
            FilterSpecCompilerConsolidateUtil.Consolidate(mapAll, args.statementRawInfo.StatementName);

            IList<FilterSpecParamForge> filterParams = new List<FilterSpecParamForge>();
            filterParams.AddAll(mapAll.FilterParams);
            int countUnassigned = mapAll.CountUnassignedExpressions();

            if (countUnassigned == 0) {
                return filterParams;
            }

            FilterSpecParamForge node = MakeRemainingNode(mapAll.UnassignedExpressions, args);
            filterParams.Add(node);
            return filterParams;
        }
Exemple #2
0
 public void RemoveNode(ExprNode node)
 {
     FilterSpecParamForge param = exprNodes.Delete(node);
     if (param != null) {
         specParams.Remove(param);
     }
 }
Exemple #3
0
        protected internal static FilterSpecParamForge[][] SortRemoveDups(IList<FilterSpecParamForge>[] parameters)
        {
            var processed = new FilterSpecParamForge[parameters.Length][];
            for (var i = 0; i < parameters.Length; i++) {
                processed[i] = SortRemoveDups(parameters[i]);
            }

            return processed;
        }
Exemple #4
0
 /// <summary>
 ///     Add a node and filter param.
 /// </summary>
 /// <param name="exprNode">is the node to add</param>
 /// <param name="param">is null if the expression node has not optimized form</param>
 public void Put(
     ExprNode exprNode,
     FilterSpecParamForge param)
 {
     exprNodes.Put(exprNode, param);
     if (param != null) {
         specParams.Put(param, exprNode);
     }
 }
Exemple #5
0
        /// <summary>
        ///     Remove a filter parameter leaving the expression node in place.
        /// </summary>
        /// <param name="param">filter parameter to remove</param>
        public void RemoveValue(FilterSpecParamForge param)
        {
            var exprNode = specParams.Get(param);
            if (exprNode == null) {
                throw new IllegalStateException("Not found in collection param: " + param);
            }

            specParams.Remove(param);
            exprNodes.Put(exprNode, null);
        }
Exemple #6
0
 protected static void AssertDisqualified(
     RegressionEnvironment env,
     RegressionPath path,
     string typeName,
     string epl)
 {
     SupportFilterPlanHook.Reset();
     env.Compile(epl, path);
     FilterSpecParamForge forge = SupportFilterPlanHook.AssertPlanSingleForTypeAndReset(typeName);
     Assert.AreEqual(FilterOperator.BOOLEAN_EXPRESSION, forge.FilterOperator);
 }
Exemple #7
0
        /// <summary>
        ///     Removes a filter parameter and it's associated expression node
        /// </summary>
        /// <param name="param">is the parameter to remove</param>
        /// <returns>expression node removed</returns>
        public ExprNode RemoveEntry(FilterSpecParamForge param)
        {
            var exprNode = specParams.Get(param);
            if (exprNode == null) {
                throw new IllegalStateException("Not found in collection param: " + param);
            }

            specParams.Remove(param);
            exprNodes.Remove(exprNode);

            return exprNode;
        }
Exemple #8
0
 protected static void AssertDisqualified(
     RegressionEnvironment env,
     RegressionPath path,
     string typeName,
     string filters)
 {
     string hook = "@Hook(HookType=HookType.INTERNAL_FILTERSPEC, Hook='" + typeof(SupportFilterPlanHook).Name + "')";
     string epl = hook + "select * from " + typeName + "(" + filters + ") as me";
     SupportFilterPlanHook.Reset();
     env.Compile(epl, path);
     FilterSpecParamForge forge = SupportFilterPlanHook.AssertPlanSingleTripletAndReset(typeName);
     if (forge.FilterOperator != FilterOperator.BOOLEAN_EXPRESSION && forge.FilterOperator != REBOOL) {
         Assert.Fail();
     }
 }
        // consolidate "val != 3 and val != 4 and val != 5"
        // to "val not in (3, 4, 5)"
        private static void HandleConsolidateNotEqual(
            IList<FilterSpecPlanPathTripletForge> parameters,
            FilterSpecParaForgeMap filterParamExprMap,
            string statementName)
        {
            IList<FilterSpecParamInValueForge> values = new List<FilterSpecParamInValueForge>();

            ExprNode lastNotEqualsExprNode = null;
            foreach (FilterSpecPlanPathTripletForge triplet in parameters) {
                FilterSpecParamForge paramForge = triplet.Param;
                if (paramForge is FilterSpecParamConstantForge) {
                    var constantParam = (FilterSpecParamConstantForge) paramForge;
                    var constant = constantParam.FilterConstant;
                    values.Add(new FilterForEvalConstantAnyTypeForge(constant));
                }
                else if (paramForge is FilterSpecParamEventPropForge) {
                    var eventProp = (FilterSpecParamEventPropForge) paramForge;
                    values.Add(
                        new FilterForEvalEventPropForge(
                            eventProp.ResultEventAsName,
                            eventProp.ResultEventProperty,
                            eventProp.ExprIdentNodeEvaluator,
                            eventProp.IsMustCoerce,
                            eventProp.CoercionType.GetBoxedType()));
                }
                else if (paramForge is FilterSpecParamEventPropIndexedForge) {
                    var eventProp = (FilterSpecParamEventPropIndexedForge) paramForge;
                    values.Add(
                        new FilterForEvalEventPropIndexedForge(
                            eventProp.ResultEventAsName,
                            eventProp.ResultEventIndex,
                            eventProp.ResultEventProperty,
                            eventProp.EventType,
                            eventProp.IsMustCoerce,
                            eventProp.CoercionType.GetBoxedType()));
                }
                else {
                    throw new ArgumentException("Unknown filter parameter:" + paramForge);
                }

                lastNotEqualsExprNode = filterParamExprMap.RemoveEntry(triplet);
            }

            FilterSpecParamInForge param = new FilterSpecParamInForge(
                parameters[0].Param.Lookupable, FilterOperator.NOT_IN_LIST_OF_VALUES, values);
            FilterSpecPlanPathTripletForge tripletForge = new FilterSpecPlanPathTripletForge(param, null);
            filterParamExprMap.Put(lastNotEqualsExprNode, tripletForge);
        }
Exemple #10
0
        public static IList<FilterSpecParamForge>[] PlanFilterParameters(
            IList<ExprNode> validatedNodes,
            FilterSpecCompilerArgs args)
        {
            if (validatedNodes.IsEmpty()) {
                return AllocateListArray(0);
            }

            FilterSpecParaForgeMap filterParamExprMap = new FilterSpecParaForgeMap();

            // Make filter parameter for each expression node, if it can be optimized
            DecomposePopulateConsolidate(filterParamExprMap, validatedNodes, args);

            // Use all filter parameter and unassigned expressions
            IList<FilterSpecParamForge> filterParams = new List<FilterSpecParamForge>();
            filterParams.AddAll(filterParamExprMap.FilterParams);
            int countUnassigned = filterParamExprMap.CountUnassignedExpressions();

            // we are done if there are no remaining nodes
            if (countUnassigned == 0) {
                return AllocateListArraySizeOne(filterParams);
            }

            // determine max-width
            int filterServiceMaxFilterWidth =
                args.compileTimeServices.Configuration.Compiler.Execution.FilterServiceMaxFilterWidth;
            var hint = HintEnum.MAX_FILTER_WIDTH.GetHint(args.statementRawInfo.Annotations);
            if (hint != null) {
                string hintValue = HintEnum.MAX_FILTER_WIDTH.GetHintAssignedValue(hint);
                filterServiceMaxFilterWidth = Int32.Parse(hintValue);
            }

            IList<FilterSpecParamForge>[] plan = null;
            if (filterServiceMaxFilterWidth > 0) {
                plan = PlanRemainingNodesIfFeasible(filterParamExprMap, args, filterServiceMaxFilterWidth);
            }

            if (plan != null) {
                return plan;
            }

            // handle no-plan
            FilterSpecParamForge node = MakeRemainingNode(filterParamExprMap.UnassignedExpressions, args);
            filterParams.Add(node);
            return AllocateListArraySizeOne(filterParams);
        }
Exemple #11
0
            public void Run(RegressionEnvironment env)
            {
                SupportFilterPlanHook.Reset();
                string hook = "@Hook(HookType=HookType.INTERNAL_FILTERSPEC, Hook='" + typeof(SupportFilterPlanHook).FullName + "')";
                string epl = hook + "@Name('s0') select * from SupportBean(TheString regexp '.*a.*')";
                env.CompileDeploy(epl).AddListener("s0");
                if (HasFilterIndexPlanAdvanced(env)) {
                    FilterSpecParamForge forge = SupportFilterPlanHook.AssertPlanSingleTripletAndReset("SupportBean");
                    Assert.AreEqual(FilterOperator.REBOOL, forge.FilterOperator);
                    Assert.AreEqual(".TheString regexp ?", forge.Lookupable.Expression);
                    Assert.AreEqual(typeof(string), forge.Lookupable.ReturnType);
                    AssertFilterSvcSingle(env.Statement("s0"), ".TheString regexp ?", REBOOL);
                }

                epl = "@Name('s1') select * from SupportBean(TheString regexp '.*a.*')";
                env.CompileDeploy(epl).AddListener("s1");

                epl = "@Name('s2') select * from SupportBean(TheString regexp '.*b.*')";
                env.CompileDeploy(epl).AddListener("s2");

                env.Milestone(0);

                if (HasFilterIndexPlanAdvanced(env)) {
                    IDictionary<string, FilterItem> filters = SupportFilterServiceHelper.GetFilterSvcAllStmtForTypeSingleFilter(env.Runtime, "SupportBean");
                    FilterItem s0 = filters.Get("s0");
                    FilterItem s1 = filters.Get("s1");
                    FilterItem s2 = filters.Get("s2");
                    Assert.AreEqual(FilterOperator.REBOOL, s0.Op);
                    Assert.IsNotNull(s0.OptionalValue);
                    Assert.IsNotNull(s0.Index);
                    Assert.AreSame(s0.Index, s1.Index);
                    Assert.AreSame(s0.OptionalValue, s1.OptionalValue);
                    Assert.AreSame(s0.Index, s2.Index);
                    Assert.AreNotSame(s0.OptionalValue, s2.OptionalValue);
                }

                SendSBAssert(env, "garden", true, true, false);
                SendSBAssert(env, "house", false, false, false);
                SendSBAssert(env, "grub", false, false, true);

                env.UndeployAll();
            }
Exemple #12
0
        private static void DecomposePopulateConsolidate(
            FilterSpecParaForgeMap filterParamExprMap,
            IList<ExprNode> validatedNodes,
            FilterSpecCompilerArgs args)
        {
            IList<ExprNode> constituents = DecomposeCheckAggregation(validatedNodes);

            // Make filter parameter for each expression node, if it can be optimized
            foreach (ExprNode constituent in constituents) {
                FilterSpecParamForge param = FilterSpecCompilerMakeParamUtil.MakeFilterParam(
                    constituent,
                    args.arrayEventTypes,
                    args.statementRawInfo.StatementName);
                filterParamExprMap.Put(constituent, param); // accepts null values as the expression may not be optimized
            }

            // Consolidate entries as possible, i.e. (a != 5 and a != 6) is (a not in (5,6))
            // Removes duplicates for same property and same filter operator for filter service index optimizations
            FilterSpecCompilerConsolidateUtil.Consolidate(filterParamExprMap, args.statementRawInfo.StatementName);
        }
Exemple #13
0
        public CodegenMethod MakeCodegen(
            CodegenMethodScope parent,
            SAIFFInitializeSymbol symbols,
            CodegenClassScope classScope)
        { 
            var method = parent.MakeChild(typeof(FilterSpecActivatable), typeof(FilterSpecCompiled), classScope);

            if (filterCallbackId == -1) {
                throw new IllegalStateException("Unassigned filter callback id");
            }

            var propertyEval = OptionalPropertyEvaluator == null
                ? ConstantNull()
                : OptionalPropertyEvaluator.Make(method, symbols, classScope);
            method.Block
                .DeclareVar<EventType>(
                    "eventType",
                    EventTypeUtility.ResolveTypeCodegen(FilterForEventType, EPStatementInitServicesConstants.REF))
                .DeclareVar<FilterSpecParam[][]>(
                    "parameters",
                    LocalMethod(
                        FilterSpecParamForge.MakeParamArrayArrayCodegen(Parameters, classScope, method),
                        Ref("eventType"),
                        symbols.GetAddInitSvc(method)))
                .DeclareVar<FilterSpecActivatable>(
                    "activatable",
                    NewInstance<FilterSpecActivatable>(
                        SAIFFInitializeSymbolWEventType.REF_EVENTTYPE,
                        Constant(FilterForEventType.Name),
                        Ref("parameters"),
                        propertyEval,
                        Constant(filterCallbackId)))
                .Expression(
                    ExprDotMethodChain(symbols.GetAddInitSvc(method))
                        .Get(EPStatementInitServicesConstants.FILTERSPECACTIVATABLEREGISTRY)
                        .Add("Register", Ref("activatable")))
                .MethodReturn(Ref("activatable"));

            return method;
        }
Exemple #14
0
        public CodegenMethod MakeCodegen(
            CodegenClassScope classScope,
            CodegenMethodScope parent)
        {
            CodegenMethod method = parent.MakeChild(typeof(ContextControllerDetailCategoryItem), GetType(), classScope)
                .AddParam(typeof(EventType), SAIFFInitializeSymbolWEventType.REF_EVENTTYPE.Ref)
                .AddParam(typeof(EPStatementInitServices), SAIFFInitializeSymbol.REF_STMTINITSVC.Ref);

            var makeFilter = FilterSpecParamForge.MakeParamArrayArrayCodegen(CompiledFilterParam, classScope, method);
            method.Block
                .DeclareVar<FilterSpecParam[][]>(
                    "parameters",
                    LocalMethod(
                        makeFilter,
                        SAIFFInitializeSymbolWEventType.REF_EVENTTYPE,
                        SAIFFInitializeSymbol.REF_STMTINITSVC))
                .DeclareVar<ContextControllerDetailCategoryItem>(
                    "item",
                    NewInstance(typeof(ContextControllerDetailCategoryItem)))
                .SetProperty(Ref("item"), "CompiledFilterParam", Ref("parameters"))
                .SetProperty(Ref("item"), "Name", Constant(Name))
                .MethodReturn(Ref("item"));
            return method;
        }
        /// <summary>
        /// For a given expression determine if this is optimizable and create the filter parameter
        /// representing the expression, or null if not optimizable.
        /// </summary>
        /// <param name="constituent">is the expression to look at</param>
        /// <param name="performConditionPlanning"></param>
        /// <param name="taggedEventTypes">event types that provide non-array values</param>
        /// <param name="arrayEventTypes">event types that provide array values</param>
        /// <param name="statementName">statement name</param>
        /// <param name="streamTypeService">stream type service</param>
        /// <returns>filter parameter representing the expression, or null</returns>
        /// <throws>ExprValidationException if the expression is invalid</throws>
        internal static FilterSpecPlanPathTripletForge MakeFilterParam(
            ExprNode constituent,
            bool performConditionPlanning,
            IDictionary <string, Pair <EventType, string> > taggedEventTypes,
            IDictionary <string, Pair <EventType, string> > arrayEventTypes,
            ISet <string> allTagNamesOrdered,
            string statementName,
            StreamTypeService streamTypeService,
            StatementRawInfo raw,
            StatementCompileTimeServices services)
        {
            // Is this expression node a simple compare, i.e. a=5 or b<4; these can be indexed
            if ((constituent is ExprEqualsNode) || (constituent is ExprRelationalOpNode))
            {
                FilterSpecParamForge param = HandleEqualsAndRelOp(
                    constituent,
                    taggedEventTypes,
                    arrayEventTypes,
                    allTagNamesOrdered,
                    statementName,
                    raw,
                    services);
                if (param != null)
                {
                    return(new FilterSpecPlanPathTripletForge(param, null));
                }
            }

            constituent = RewriteOrToInIfApplicable(constituent, false);

            // Is this expression node a simple compare, i.e. a=5 or b<4; these can be indexed
            if (constituent is ExprInNode)
            {
                FilterSpecParamForge param = HandleInSetNode((ExprInNode)constituent, taggedEventTypes, arrayEventTypes, allTagNamesOrdered, raw, services);
                if (param != null)
                {
                    return(new FilterSpecPlanPathTripletForge(param, null));
                }
            }

            if (constituent is ExprBetweenNode)
            {
                FilterSpecParamForge param = HandleRangeNode(
                    (ExprBetweenNode)constituent,
                    taggedEventTypes,
                    arrayEventTypes,
                    allTagNamesOrdered,
                    statementName,
                    raw,
                    services);
                if (param != null)
                {
                    return(new FilterSpecPlanPathTripletForge(param, null));
                }
            }

            if (constituent is ExprPlugInSingleRowNode)
            {
                FilterSpecParamForge param = HandlePlugInSingleRow((ExprPlugInSingleRowNode)constituent);
                if (param != null)
                {
                    return(new FilterSpecPlanPathTripletForge(param, null));
                }
            }

            if (constituent is FilterSpecCompilerAdvIndexDescProvider)
            {
                FilterSpecParamForge param = HandleAdvancedIndexDescProvider(
                    (FilterSpecCompilerAdvIndexDescProvider)constituent,
                    arrayEventTypes,
                    statementName);
                if (param != null)
                {
                    return(new FilterSpecPlanPathTripletForge(param, null));
                }
            }

            if (constituent is ExprOrNode && performConditionPlanning)
            {
                return(HandleOrAlternateExpression(
                           (ExprOrNode)constituent,
                           performConditionPlanning,
                           taggedEventTypes,
                           arrayEventTypes,
                           allTagNamesOrdered,
                           statementName,
                           streamTypeService,
                           raw,
                           services));
            }

            FilterSpecParamForge paramX = HandleBooleanLimited(
                constituent,
                taggedEventTypes,
                arrayEventTypes,
                allTagNamesOrdered,
                streamTypeService,
                raw,
                services);

            if (paramX != null)
            {
                return(new FilterSpecPlanPathTripletForge(paramX, null));
            }

            return(null);
        }
 public FilterSpecPlanPathTripletForge(FilterSpecParamForge param,
     ExprNode tripletConfirm)
 {
     Param = param;
     TripletConfirm = tripletConfirm;
 }