Ejemplo n.º 1
0
        private static IList<FilterSpecParam> ComputePermutation(
            FilterParamExprMap filterParamExprMap,
            object[] permutation,
            FilterParamExprMap[][] orNodesMaps,
            FilterSpecCompilerArgs args)
        {
            var mapAll = new FilterParamExprMap();
            mapAll.Add(filterParamExprMap);

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

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

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

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

            FilterSpecParamExprNode node = MakeRemainingNode(mapAll.UnassignedExpressions, args);
            filterParams.Add(node);
            return filterParams;
        }
Ejemplo n.º 2
0
        internal static IList<FilterSpecParam>[] PlanFilterParameters(
            IList<ExprNode> validatedNodes,
            FilterSpecCompilerArgs args)
        {
            if (validatedNodes.IsEmpty())
            {
                return AllocateListArray(0);
            }

            var filterParamExprMap = new FilterParamExprMap();

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

            // Use all filter parameter and unassigned expressions
            IList<FilterSpecParam> filterParams = new List<FilterSpecParam>();
            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.ConfigurationInformation.EngineDefaults.ExecutionConfig.FilterServiceMaxFilterWidth;
            HintAttribute hint = HintEnum.MAX_FILTER_WIDTH.GetHint(args.Annotations);
            if (hint != null)
            {
                string hintValue = HintEnum.MAX_FILTER_WIDTH.GetHintAssignedValue(hint);
                filterServiceMaxFilterWidth = int.Parse(hintValue);
            }

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

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

            // handle no-plan
            FilterSpecParamExprNode node = MakeRemainingNode(filterParamExprMap.UnassignedExpressions, args);
            filterParams.Add(node);
            return AllocateListArraySizeOne(filterParams);
        }
Ejemplo n.º 3
0
        private static void DecomposePopulateConsolidate(
            FilterParamExprMap 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)
            {
                FilterSpecParam param = FilterSpecCompilerMakeParamUtil.MakeFilterParam(
                    constituent, args.ArrayEventTypes, args.ExprEvaluatorContext, args.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.StatementName);
        }
Ejemplo n.º 4
0
        private static FilterSpecParamExprNode MakeRemainingNode(
            IList<ExprNode> unassignedExpressions,
            FilterSpecCompilerArgs args)

        {
            if (unassignedExpressions.IsEmpty())
            {
                throw new ArgumentException();
            }

            // any unoptimized expression nodes are put under one AND
            ExprNode exprNode;
            if (unassignedExpressions.Count == 1)
            {
                exprNode = unassignedExpressions[0];
            }
            else
            {
                exprNode = MakeValidateAndNode(unassignedExpressions, args);
            }
            return MakeBooleanExprParam(exprNode, args);
        }
Ejemplo n.º 5
0
        public static FilterSpecCompiled BuildNoStmtCtx(
            IList <ExprNode> validatedFilterNodes,
            EventType eventType,
            string eventTypeName,
            PropertyEvalSpec optionalPropertyEvalSpec,
            IDictionary <string, Pair <EventType, string> > taggedEventTypes,
            IDictionary <string, Pair <EventType, string> > arrayEventTypes,
            StreamTypeService streamTypeService,
            string optionalStreamName,
            ICollection <int> assignedTypeNumberStack,
            ExprEvaluatorContext exprEvaluatorContext,
            string statementId,
            string statementName,
            Attribute[] annotations,
            ContextDescriptor contextDescriptor,
            MethodResolutionService methodResolutionService,
            EventAdapterService eventAdapterService,
            TimeProvider timeProvider,
            VariableService variableService,
            ScriptingService scriptingService,
            TableService tableService,
            ConfigurationInformation configurationInformation,
            NamedWindowService namedWindowService)
        {
            var args = new FilterSpecCompilerArgs(
                taggedEventTypes,
                arrayEventTypes,
                exprEvaluatorContext,
                statementName,
                statementId,
                streamTypeService,
                methodResolutionService,
                timeProvider,
                variableService,
                tableService,
                eventAdapterService,
                scriptingService,
                annotations,
                contextDescriptor,
                configurationInformation);
            var parameters = FilterSpecCompilerPlanner.PlanFilterParameters(validatedFilterNodes, args);

            PropertyEvaluator optionalPropertyEvaluator = null;

            if (optionalPropertyEvalSpec != null)
            {
                optionalPropertyEvaluator = PropertyEvaluatorFactory.MakeEvaluator(
                    optionalPropertyEvalSpec,
                    eventType,
                    optionalStreamName,
                    eventAdapterService,
                    methodResolutionService,
                    timeProvider,
                    variableService,
                    scriptingService,
                    tableService,
                    streamTypeService.EngineURIQualifier,
                    statementId,
                    statementName,
                    annotations,
                    assignedTypeNumberStack,
                    configurationInformation,
                    namedWindowService);
            }

            var spec = new FilterSpecCompiled(eventType, eventTypeName, parameters, optionalPropertyEvaluator);

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

            return(spec);
        }
Ejemplo n.º 6
0
        private static IList<FilterSpecParam>[] PlanRemainingNodesIfFeasible(
            FilterParamExprMap overallExpressions,
            FilterSpecCompilerArgs args,
            int filterServiceMaxFilterWidth)

        {
            IList<ExprNode> unassigned = overallExpressions.UnassignedExpressions;
            IList<ExprOrNode> orNodes = new List<ExprOrNode>(unassigned.Count);

            foreach (ExprNode node in unassigned)
            {
                if (node is ExprOrNode)
                {
                    orNodes.Add((ExprOrNode) node);
                }
            }

            var expressionsWithoutOr = new FilterParamExprMap();
            expressionsWithoutOr.Add(overallExpressions);

            // first dimension: or-node index
            // second dimension: or child node index
            var orNodesMaps = new FilterParamExprMap[orNodes.Count][];
            int countOr = 0;
            int sizeFactorized = 1;
            var sizePerOr = new int[orNodes.Count];
            foreach (ExprOrNode orNode in orNodes)
            {
                expressionsWithoutOr.RemoveNode(orNode);
                orNodesMaps[countOr] = new FilterParamExprMap[orNode.ChildNodes.Length];
                int len = orNode.ChildNodes.Length;

                for (int i = 0; i < len; i++)
                {
                    var map = new FilterParamExprMap();
                    orNodesMaps[countOr][i] = map;
                    IList<ExprNode> nodes = Collections.SingletonList(orNode.ChildNodes[i]);
                    DecomposePopulateConsolidate(map, nodes, args);
                }

                sizePerOr[countOr] = len;
                sizeFactorized = sizeFactorized*len;
                countOr++;
            }

            // we become too large
            if (sizeFactorized > filterServiceMaxFilterWidth)
            {
                return null;
            }

            // combine
            var result = new IList<FilterSpecParam>[sizeFactorized];
            IEnumerable<object[]> permutations = CombinationEnumeration.FromZeroBasedRanges(sizePerOr);
            int count = 0;
            foreach (var permutation in permutations)
            {
                result[count] = ComputePermutation(expressionsWithoutOr, permutation, orNodesMaps, args);
                count++;
            }
            return result;
        }
Ejemplo n.º 7
0
 private static ExprAndNode MakeValidateAndNode(IList<ExprNode> remainingExprNodes, FilterSpecCompilerArgs args)
 {
     ExprAndNode andNode = ExprNodeUtility.ConnectExpressionsByLogicalAnd(remainingExprNodes);
     var validationContext = new ExprValidationContext(
         args.StreamTypeService,
         args.MethodResolutionService, null,
         args.TimeProvider,
         args.VariableService,
         args.TableService,
         args.ExprEvaluatorContext,
         args.EventAdapterService,
         args.StatementName,
         args.StatementId,
         args.Annotations,
         args.ContextDescriptor,
         args.ScriptingService,
         false, false, true, false, null, false);
     andNode.Validate(validationContext);
     return andNode;
 }
Ejemplo n.º 8
0
 private static FilterSpecParamExprNode MakeBooleanExprParam(ExprNode exprNode, FilterSpecCompilerArgs args)
 {
     bool hasSubselectFilterStream = DetermineSubselectFilterStream(exprNode);
     bool hasTableAccess = DetermineTableAccessFilterStream(exprNode);
     var lookupable = new FilterSpecLookupable(
         FilterSpecCompiler.PROPERTY_NAME_BOOLEAN_EXPRESSION, null, exprNode.ExprEvaluator.ReturnType);
     return new FilterSpecParamExprNode(
         lookupable, FilterOperator.BOOLEAN_EXPRESSION, exprNode, args.TaggedEventTypes, args.ArrayEventTypes,
         args.VariableService, args.TableService, args.EventAdapterService, args.ConfigurationInformation,
         args.StatementName, hasSubselectFilterStream, hasTableAccess);
 }