private static FilterSpecPlanPathForge ComputePermutation(
            FilterSpecParaForgeMap filterParamExprMap,
            object[] permutation,
            FilterSpecParaForgeMap[][] orNodesMaps,
            FilterSpecCompilerArgs args)
        {
            var mapAll = new FilterSpecParaForgeMap();
            mapAll.Add(filterParamExprMap);

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

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

            IList<FilterSpecPlanPathTripletForge> filterParams = new List<FilterSpecPlanPathTripletForge>(mapAll.Triplets);
            var countUnassigned = mapAll.CountUnassignedExpressions();

            if (countUnassigned != 0) {
                FilterSpecPlanPathTripletForge node = MakeRemainingNode(mapAll.UnassignedExpressions, args);
                filterParams.Add(node);
            }

            FilterSpecPlanPathTripletForge[] triplets = filterParams.ToArray();
            return new FilterSpecPlanPathForge(triplets, null);
        }
 public void RemoveNode(ExprNode node)
 {
     FilterSpecPlanPathTripletForge param = exprNodes.Delete(node);
     if (param != null) {
         specParams.Remove(param);
     }
 }
        private static FilterSpecPlanPathTripletForge HandleOrAlternateExpression(
            ExprOrNode orNode,
            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)
        {
            IList <ExprNode> valueExpressions = new List <ExprNode>(orNode.ChildNodes.Length);

            foreach (ExprNode child in orNode.ChildNodes)
            {
                FilterSpecExprNodeVisitorValueLimitedExpr visitor = new FilterSpecExprNodeVisitorValueLimitedExpr();
                child.Accept(visitor);
                if (visitor.IsLimited)
                {
                    valueExpressions.Add(child);
                }
            }

            // The or-node must have a single constituent and one or more value expressions
            if (orNode.ChildNodes.Length != valueExpressions.Count + 1)
            {
                return(null);
            }

            IList <ExprNode> constituents = new List <ExprNode>(orNode.ChildNodes);

            constituents.RemoveAll(valueExpressions);
            if (constituents.Count != 1)
            {
                throw new IllegalStateException("Found multiple constituents");
            }

            ExprNode constituent = constituents[0];

            FilterSpecPlanPathTripletForge triplet = MakeFilterParam(
                constituent,
                performConditionPlanning,
                taggedEventTypes,
                arrayEventTypes,
                allTagNamesOrdered,
                statementName,
                streamTypeService,
                raw,
                services);

            if (triplet == null)
            {
                return(null);
            }

            ExprNode controlConfirm = ExprNodeUtilityMake.ConnectExpressionsByLogicalOrWhenNeeded(valueExpressions);

            return(new FilterSpecPlanPathTripletForge(triplet.Param, controlConfirm));
        }
        public bool EqualsFilter(FilterSpecPlanPathTripletForge other)
        {
            if (!ExprNodeUtilityCompare.DeepEqualsNullChecked(TripletConfirm, other.TripletConfirm, true)) {
                return false;
            }

            return Param.Equals(other.Param);
        }
 /// <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,
     FilterSpecPlanPathTripletForge param)
 {
     exprNodes.Put(exprNode, param);
     if (param != null) {
         specParams.Put(param, exprNode);
     }
 }
        /// <summary>
        ///     Remove a filter parameter leaving the expression node in place.
        /// </summary>
        /// <param name="param">filter parameter to remove</param>
        public void RemoveValue(FilterSpecPlanPathTripletForge 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);
        }
        /// <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(FilterSpecPlanPathTripletForge 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;
        }
        // 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);
        }