Пример #1
0
        public ExprDeclaredNodeImpl(
            ExpressionDeclItem prototype,
            IList<ExprNode> chainParameters,
            ContextCompileTimeDescriptor contextDescriptor,
            ExprNode expressionBodyCopy)
        {
            PrototypeWVisibility = prototype;
            ChainParameters = chainParameters;
            ExpressionBodyCopy = expressionBodyCopy;

            // replace context-properties where they are currently identifiers
            if (contextDescriptor == null) {
                return;
            }

            var visitorWParent = new ExprNodeIdentVisitorWParent();
            expressionBodyCopy.Accept(visitorWParent);
            foreach (var pair in visitorWParent.IdentNodes) {
                var streamOrProp = pair.Second.StreamOrPropertyName;
                if (streamOrProp != null &&
                    contextDescriptor.ContextPropertyRegistry.IsContextPropertyPrefix(streamOrProp)) {
                    var context =
                        new ExprContextPropertyNodeImpl(pair.Second.UnresolvedPropertyName);
                    if (pair.First == null) {
                        ExpressionBodyCopy = context;
                    }
                    else {
                        ExprNodeUtilityModify.ReplaceChildNode(pair.First, pair.Second, context);
                    }
                }
            }
        }
Пример #2
0
        private static ExprNode HandlePreviousFunctions(
            ExprNode defineItemExpression,
            IOrderedDictionary<int, IList<ExprPreviousMatchRecognizeNode>> previousNodes)
        {
            var previousVisitor = new ExprNodePreviousVisitorWParent();
            defineItemExpression.Accept(previousVisitor);

            if (previousVisitor.Previous == null) {
                return defineItemExpression;
            }

            foreach (var previousNodePair in previousVisitor.Previous) {
                var previousNode = previousNodePair.Second;
                var matchRecogPrevNode = new ExprPreviousMatchRecognizeNode();

                if (previousNodePair.Second.ChildNodes.Length == 1) {
                    matchRecogPrevNode.AddChildNode(previousNode.ChildNodes[0]);
                    matchRecogPrevNode.AddChildNode(new ExprConstantNodeImpl(1));
                }
                else if (previousNodePair.Second.ChildNodes.Length == 2) {
                    var first = previousNode.ChildNodes[0];
                    var second = previousNode.ChildNodes[1];
                    if (first is ExprConstantNode && !(second is ExprConstantNode)) {
                        matchRecogPrevNode.AddChildNode(second);
                        matchRecogPrevNode.AddChildNode(first);
                    }
                    else if (!(first is ExprConstantNode) && second is ExprConstantNode) {
                        matchRecogPrevNode.AddChildNode(first);
                        matchRecogPrevNode.AddChildNode(second);
                    }
                    else {
                        throw new ExprValidationException("PREV operator requires a constant index");
                    }
                }

                if (previousNodePair.First == null) {
                    defineItemExpression = matchRecogPrevNode;
                }
                else {
                    ExprNodeUtilityModify.ReplaceChildNode(
                        previousNodePair.First,
                        previousNodePair.Second,
                        matchRecogPrevNode);
                }

                // store in a list per index such that we can consolidate this into a single buffer
                var index = matchRecogPrevNode.ConstantIndexNumber;
                var callbackList = previousNodes.Get(index);
                if (callbackList == null) {
                    callbackList = new List<ExprPreviousMatchRecognizeNode>();
                    previousNodes.Put(index, callbackList);
                }

                callbackList.Add(matchRecogPrevNode);
            }

            return defineItemExpression;
        }
        internal static FilterSpecParamForge HandleBooleanLimited(
            ExprNode constituent,
            IDictionary<string, Pair<EventType, string>> taggedEventTypes,
            IDictionary<string, Pair<EventType, string>> arrayEventTypes,
            ISet<string> allTagNamesOrdered,
            StreamTypeService streamTypeService,
            StatementRawInfo raw,
            StatementCompileTimeServices services)
        {
            if (!HasLevelOrHint(FilterSpecCompilerIndexPlannerHint.BOOLCOMPOSITE, raw, services)) {
                return null;
            }

            // prequalify
            var prequalified = Prequalify(constituent);
            if (!prequalified) {
                return null;
            }

            // determine rewrite
            var desc = FindRewrite(constituent);
            if (desc == null) {
                return null;
            }

            // there is no value expression, i.e. "select * from SupportBean(theString = intPrimitive)"
            if (desc is RewriteDescriptorNoValueExpr) {
                var reboolExpression = ExprNodeUtilityPrint.ToExpressionStringMinPrecedence(constituent, new ExprNodeRenderableFlags(false));
                var lookupable = new ExprFilterSpecLookupableForge(reboolExpression, null, constituent.Forge, null, true, null);
                return new FilterSpecParamValueNullForge(lookupable, FilterOperator.REBOOL);
            }

            // there is no value expression, i.e. "select * from SupportBean(theString regexp 'abc')"
            var withValueExpr = (RewriteDescriptorWithValueExpr) desc;
            ExprNode valueExpression = withValueExpr.ValueExpression;
            var valueExpressionType = valueExpression.Forge.EvaluationType;
            var replacement = new ExprFilterReboolValueNode(valueExpressionType);
            ExprNodeUtilityModify.ReplaceChildNode(withValueExpr.ValueExpressionParent, valueExpression, replacement);
            var validationContext = new ExprValidationContextBuilder(streamTypeService, raw, services).WithIsFilterExpression(true).Build();
            var rebool = ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.FILTER, constituent, validationContext);
            DataInputOutputSerdeForge serde = services.SerdeResolver.SerdeForFilter(valueExpressionType, raw);
            var convertor = GetMatchEventConvertor(valueExpression, taggedEventTypes, arrayEventTypes, allTagNamesOrdered);

            var reboolExpressionX = ExprNodeUtilityPrint.ToExpressionStringMinPrecedence(constituent, new ExprNodeRenderableFlags(false));
            var lookupableX = new ExprFilterSpecLookupableForge(reboolExpressionX, null, rebool.Forge, valueExpressionType, true, serde);
            return new FilterSpecParamValueLimitedExprForge(lookupableX, FilterOperator.REBOOL, valueExpression, convertor, null);
        }
Пример #4
0
        private compat.collections.Pair<ExprAggregateNode, IList<StmtClassForgeableFactory>> ValidateAggregationExpr(
            ExprNode columnExpressionType,
            EventType optionalProvidedType,
            StatementCompileTimeServices services)
        {
            var classpathImportService = services.ImportServiceCompileTime;

            // determine validation context types and istream/irstream
            EventType[] types;
            string[] streamNames;
            bool[] istreamOnly;
            if (optionalProvidedType != null) {
                types = new[] {optionalProvidedType};
                streamNames = new[] {types[0].Name};
                istreamOnly = new[] {
                    false
                }; // always false (expected to be bound by data window), use "ever"-aggregation functions otherwise
            }
            else {
                types = new EventType[0];
                streamNames = new string[0];
                istreamOnly = new bool[0];
            }

            var streamTypeService = new StreamTypeServiceImpl(types, streamNames, istreamOnly, false, false);
            var validationContext =
                new ExprValidationContextBuilder(streamTypeService, @base.StatementRawInfo, services).Build();

            // substitute parameter nodes
            foreach (var childNode in columnExpressionType.ChildNodes) {
                if (childNode is ExprIdentNode) {
                    var identNode = (ExprIdentNode) childNode;
                    var propname = identNode.FullUnresolvedName.Trim();
                    var clazz = TypeHelper.GetTypeForSimpleName(
                        propname,
                        classpathImportService.ClassForNameProvider);
                    if (propname.ToLowerInvariant().Trim().Equals("@object")) {
                        clazz = typeof(object);
                    }

                    ImportException ex = null;
                    if (clazz == null) {
                        try {
                            clazz = classpathImportService.ResolveClass(propname, false, services.ClassProvidedExtension);
                        }
                        catch (ImportException e) {
                            ex = e;
                        }
                    }

                    if (clazz != null) {
                        var typeNode = new ExprTypedNoEvalNode(propname, clazz);
                        ExprNodeUtilityModify.ReplaceChildNode(columnExpressionType, identNode, typeNode);
                    }
                    else {
                        if (optionalProvidedType == null) {
                            if (ex != null) {
                                throw new ExprValidationException(
                                    "Failed to resolve type '" + propname + "': " + ex.Message,
                                    ex);
                            }

                            throw new ExprValidationException("Failed to resolve type '" + propname + "'");
                        }
                    }
                }
            }

            // validate
            var validated = ExprNodeUtilityValidate.GetValidatedSubtree(
                ExprNodeOrigin.CREATETABLECOLUMN,
                columnExpressionType,
                validationContext);
            if (!(validated is ExprAggregateNode)) {
                throw new ExprValidationException(
                    "Expression '" +
                    ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(validated) +
                    "' is not an aggregation");
            }

            return new compat.collections.Pair<ExprAggregateNode, IList<StmtClassForgeableFactory>>(
                (ExprAggregateNode) validated,
                validationContext.AdditionalForgeables);
        }