Пример #1
0
        private AggregationMultiFunctionMethodDesc HandleMethodWindow(
            ExprNode[] childNodes,
            ExprValidationContext validationContext)
        {
            if (childNodes.Length == 0 || (childNodes.Length == 1 && childNodes[0] is ExprWildcard)) {
                var componentType = ContainedEventType.UnderlyingType;
                var forge = new AggregationMethodLinearWindowForge(
                    TypeHelper.GetArrayType(componentType),
                    null);
                return new AggregationMultiFunctionMethodDesc(forge, ContainedEventType, null, null);
            }

            if (childNodes.Length == 1) {
                // Expressions apply to events held, thereby validate in terms of event value expressions
                var paramNode = childNodes[0];
                var streams = TableCompileTimeUtil.StreamTypeFromTableColumn(ContainedEventType);
                var localValidationContext = new ExprValidationContext(streams, validationContext);
                paramNode = ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.AGGPARAM, paramNode, localValidationContext);
                var paramNodeType = paramNode.Forge.EvaluationType.GetBoxedType();
                var forge = new AggregationMethodLinearWindowForge(TypeHelper.GetArrayType(paramNodeType), paramNode);
                return new AggregationMultiFunctionMethodDesc(forge, null, paramNodeType, null);
            }

            throw new ExprValidationException("Invalid number of parameters");
        }
Пример #2
0
 public static void ValidateFilterWQueryGraphSafe(
     QueryGraphForge queryGraph,
     ExprNode filterExpression,
     StreamTypeServiceImpl typeService,
     StatementRawInfo statementRawInfo,
     StatementCompileTimeServices services)
 {
     try {
         var validationContext = new ExprValidationContextBuilder(typeService, statementRawInfo, services)
             .WithAllowBindingConsumption(true)
             .WithIsFilterExpression(true)
             .Build();
         var validated = ExprNodeUtilityValidate.GetValidatedSubtree(
             ExprNodeOrigin.FILTER,
             filterExpression,
             validationContext);
         FilterExprAnalyzer.Analyze(validated, queryGraph, false);
     }
     catch (Exception ex) {
         Log.Warn(
             "Unexpected exception analyzing filterable expression '" +
             ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(filterExpression) +
             "': " +
             ex.Message,
             ex);
     }
 }
Пример #3
0
        protected internal static ExprNode ValidateJoinNamedWindow(
            ExprNodeOrigin exprNodeOrigin,
            ExprNode deleteJoinExpr,
            EventType namedWindowType,
            string namedWindowStreamName,
            string namedWindowName,
            EventType filteredType,
            string filterStreamName,
            string filteredTypeName,
            string optionalTableName,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices compileTimeServices
        )
        {
            if (deleteJoinExpr == null) {
                return null;
            }

            var namesAndTypes = new LinkedHashMap<string, Pair<EventType, string>>();
            namesAndTypes.Put(namedWindowStreamName, new Pair<EventType, string>(namedWindowType, namedWindowName));
            namesAndTypes.Put(filterStreamName, new Pair<EventType, string>(filteredType, filteredTypeName));
            StreamTypeService typeService = new StreamTypeServiceImpl(namesAndTypes, false, false);

            var validationContext = new ExprValidationContextBuilder(typeService, statementRawInfo, compileTimeServices)
                .WithAllowBindingConsumption(true)
                .Build();
            return ExprNodeUtilityValidate.GetValidatedSubtree(exprNodeOrigin, deleteJoinExpr, validationContext);
        }
Пример #4
0
        public static IList<ExprNode> ValidateAllowSubquery(
            ExprNodeOrigin exprNodeOrigin,
            IList<ExprNode> exprNodes,
            StreamTypeService streamTypeService,
            IDictionary<string, Pair<EventType, string>> taggedEventTypes,
            IDictionary<string, Pair<EventType, string>> arrayEventTypes,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            IList<ExprNode> validatedNodes = new List<ExprNode>();

            ExprValidationContext validationContext =
                new ExprValidationContextBuilder(streamTypeService, statementRawInfo, services)
                    .WithAllowBindingConsumption(true)
                    .WithIsFilterExpression(true)
                    .Build();
            foreach (var node in exprNodes) {
                // Determine subselects
                var visitor = new ExprNodeSubselectDeclaredDotVisitor();
                node.Accept(visitor);

                // Compile subselects
                if (!visitor.Subselects.IsEmpty()) {
                    // The outer event type is the filtered-type itself
                    foreach (var subselect in visitor.Subselects) {
                        try {
                            SubSelectHelperFilters.HandleSubselectSelectClauses(
                                subselect,
                                streamTypeService.EventTypes[0],
                                streamTypeService.StreamNames[0],
                                streamTypeService.StreamNames[0],
                                taggedEventTypes,
                                arrayEventTypes,
                                statementRawInfo,
                                services);
                        }
                        catch (ExprValidationException ex) {
                            throw new ExprValidationException(
                                "Failed to validate " +
                                ExprNodeUtilityMake.GetSubqueryInfoText(subselect) +
                                ": " +
                                ex.Message,
                                ex);
                        }
                    }
                }

                var validated = ExprNodeUtilityValidate.GetValidatedSubtree(exprNodeOrigin, node, validationContext);
                validatedNodes.Add(validated);

                if (validated.Forge.EvaluationType != typeof(bool?) && validated.Forge.EvaluationType != typeof(bool)) {
                    throw new ExprValidationException(
                        "Filter expression not returning a boolean value: '" +
                        ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(validated) +
                        "'");
                }
            }

            return validatedNodes;
        }
Пример #5
0
        public static ExprForge[] CrontabScheduleValidate(
            ExprNodeOrigin origin,
            IList<ExprNode> scheduleSpecExpressionList,
            bool allowBindingConsumption,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            // Validate the expressions
            ExprForge[] expressions = new ExprForge[scheduleSpecExpressionList.Count];
            int count = 0;
            ExprValidationContext validationContext =
                new ExprValidationContextBuilder(new StreamTypeServiceImpl(false), statementRawInfo, services)
                    .WithAllowBindingConsumption(allowBindingConsumption)
                    .Build();
            foreach (ExprNode parameters in scheduleSpecExpressionList) {
                ExprNode node = ExprNodeUtilityValidate.GetValidatedSubtree(origin, parameters, validationContext);
                expressions[count++] = node.Forge;
            }

            if (expressions.Length <= 4 || expressions.Length >= 8) {
                throw new ExprValidationException(
                    "Invalid schedule specification: " +
                    ScheduleSpecUtil.GetExpressionCountException(expressions.Length));
            }

            return expressions;
        }
Пример #6
0
        public void TestGetType()
        {
            log.Debug(".testGetType");
            _bitWiseNode = new ExprBitWiseNode(BitWiseOpEnum.BAND);
            _bitWiseNode.AddChildNode(new SupportExprNode(typeof(double?)));
            _bitWiseNode.AddChildNode(new SupportExprNode(typeof(int?)));
            try
            {
                _bitWiseNode.Validate(SupportExprValidationContextFactory.MakeEmpty(container));
                Assert.Fail();
            }
            catch (ExprValidationException)
            {
                // Expected
            }

            _bitWiseNode = new ExprBitWiseNode(BitWiseOpEnum.BAND);
            _bitWiseNode.AddChildNode(new SupportExprNode(typeof(long?)));
            _bitWiseNode.AddChildNode(new SupportExprNode(typeof(long?)));
            ExprNodeUtilityValidate.GetValidatedSubtree(
                ExprNodeOrigin.SELECT,
                _bitWiseNode,
                SupportExprValidationContextFactory.MakeEmpty(container));
            Assert.AreEqual(typeof(long?), _bitWiseNode.Forge.EvaluationType);
        }
Пример #7
0
        public AggregationTableReadDesc ValidateAggregationTableRead(
            ExprValidationContext context,
            TableMetadataColumnAggregation tableAccessColumn,
            TableMetaData table)
        {
            if (AggType == CountMinSketchAggType.STATE || AggType == CountMinSketchAggType.ADD) {
                throw new ExprValidationException(MessagePrefix + "cannot not be used for table access");
            }

            if (!(tableAccessColumn.AggregationPortableValidation is AggregationPortableValidationCountMinSketch)) {
                throw new ExprValidationException(MessagePrefix + "can only be used with count-min-sketch");
            }

            AggregationTableAccessAggReaderForge forge;
            if (AggType == CountMinSketchAggType.FREQ) {
                if (positionalParams.Length == 0 || positionalParams.Length > 1) {
                    throw new ExprValidationException(MessagePrefix + "requires a single parameter expression");
                }

                ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.AGGPARAM, ChildNodes, context);
                var frequencyEval = ChildNodes[0];
                forge = new AgregationTAAReaderCountMinSketchFreqForge(frequencyEval);
            }
            else {
                if (positionalParams.Length != 0) {
                    throw new ExprValidationException(MessagePrefix + "requires a no parameter expressions");
                }

                forge = new AgregationTAAReaderCountMinSketchTopKForge();
            }

            return new AggregationTableReadDesc(forge, null, null, null);
        }
Пример #8
0
        public static ExprNode ValidateExpr(
            string viewName,
            ExprNode expression,
            StreamTypeService streamTypeService,
            ViewForgeEnv viewForgeEnv,
            int expressionNumber,
            int streamNumber)
        {
            ExprNode validated;
            try {
                var names = new ExprValidationMemberNameQualifiedView(streamNumber);
                var validationContext = new ExprValidationContextBuilder(
                        streamTypeService,
                        viewForgeEnv.StatementRawInfo,
                        viewForgeEnv.StatementCompileTimeServices)
                    .WithMemberName(names)
                    .Build();
                validated = ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.VIEWPARAMETER,
                    expression,
                    validationContext);
            }
            catch (ExprValidationException ex) {
                var message = "Invalid parameter expression " + expressionNumber + GetViewDesc(viewName);
                if (ex.Message != null) {
                    message += ": " + ex.Message;
                }

                throw new ViewParameterException(message, ex);
            }

            return validated;
        }
Пример #9
0
        protected override void InitExec(
            string aliasName,
            StatementSpecCompiled spec,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            StreamTypeServiceImpl assignmentTypeService = new StreamTypeServiceImpl(
                new EventType[] {
                    processor.EventTypeRspInputEvents, null,
                    processor.EventTypeRspInputEvents
                },
                new string[] {aliasName, "", INITIAL_VALUE_STREAM_NAME},
                new bool[] {true, true, true},
                true,
                false);
            assignmentTypeService.IsStreamZeroUnambigous = true;
            ExprValidationContext validationContext =
                new ExprValidationContextBuilder(assignmentTypeService, statementRawInfo, services)
                    .WithAllowBindingConsumption(true)
                    .Build();

            // validate update expressions
            FireAndForgetSpecUpdate updateSpec = (FireAndForgetSpecUpdate) spec.Raw.FireAndForgetSpec;
            try {
                foreach (OnTriggerSetAssignment assignment in updateSpec.Assignments) {
                    ExprNode validated = ExprNodeUtilityValidate.GetValidatedSubtree(
                        ExprNodeOrigin.UPDATEASSIGN,
                        assignment.Expression,
                        validationContext);
                    assignment.Expression = validated;
                    EPStatementStartMethodHelperValidate.ValidateNoAggregations(
                        validated,
                        "Aggregation functions may not be used within an update-clause");
                }
            }
            catch (ExprValidationException e) {
                throw new EPException(e.Message, e);
            }

            // make updater
            //TableUpdateStrategy tableUpdateStrategy = null;
            try {
                bool copyOnWrite = processor is FireAndForgetProcessorNamedWindowForge;
                updateHelper = EventBeanUpdateHelperForgeFactory.Make(
                    processor.NamedWindowOrTableName,
                    (EventTypeSPI) processor.EventTypeRspInputEvents,
                    updateSpec.Assignments,
                    aliasName,
                    null,
                    copyOnWrite,
                    statementRawInfo.StatementName,
                    services.EventTypeAvroHandler);
            }
            catch (ExprValidationException e) {
                throw new EPException(e.Message, e);
            }
        }
Пример #10
0
        private AggregationMultiFunctionMethodDesc HandleMethodFirstLast(
            ExprNode[] childNodes,
            AggregationAccessorLinearType methodType,
            ExprValidationContext validationContext)
        {
            var underlyingType = ContainedEventType.UnderlyingType;
            if (childNodes.Length == 0) {
                var forge = new AggregationMethodLinearFirstLastForge(underlyingType, methodType, null);
                return new AggregationMultiFunctionMethodDesc(forge, null, null, ContainedEventType);
            }

            if (childNodes.Length == 1) {
                if (childNodes[0] is ExprWildcard) {
                    var forgeX = new AggregationMethodLinearFirstLastForge(underlyingType, methodType, null);
                    return new AggregationMultiFunctionMethodDesc(forgeX, null, null, ContainedEventType);
                }

                if (childNodes[0] is ExprStreamUnderlyingNode) {
                    throw new ExprValidationException("Stream-wildcard is not allowed for table column access");
                }

                // Expressions apply to events held, thereby validate in terms of event value expressions
                var paramNode = childNodes[0];
                var streams = TableCompileTimeUtil.StreamTypeFromTableColumn(ContainedEventType);
                var localValidationContext = new ExprValidationContext(streams, validationContext);
                paramNode = ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.AGGPARAM, paramNode, localValidationContext);
                var forge = new AggregationMethodLinearFirstLastForge(paramNode.Forge.EvaluationType, methodType, paramNode);
                return new AggregationMultiFunctionMethodDesc(forge, null, null, null);
            }

            if (childNodes.Length == 2) {
                int? constant = null;
                var indexEvalNode = childNodes[1];
                var indexEvalType = indexEvalNode.Forge.EvaluationType;
                if (indexEvalType != typeof(int?) && indexEvalType != typeof(int)) {
                    throw new ExprValidationException(GetErrorPrefix(methodType) + " requires a constant index expression that returns an integer value");
                }

                ExprNode indexExpr;
                if (indexEvalNode.Forge.ForgeConstantType == ExprForgeConstantType.COMPILETIMECONST) {
                    constant = indexEvalNode.Forge.ExprEvaluator.Evaluate(null, true, null).AsBoxedInt32();
                    indexExpr = null;
                }
                else {
                    indexExpr = indexEvalNode;
                }

                var forge = new AggregationMethodLinearFirstLastIndexForge(
                    underlyingType,
                    methodType,
                    constant,
                    indexExpr);
                return new AggregationMultiFunctionMethodDesc(forge, null, null, ContainedEventType);
            }

            throw new ExprValidationException("Invalid number of parameters");
        }
Пример #11
0
 public override void Validate(
     ExprNodeOrigin origin,
     ExprValidationContext validationContext)
 {
     var index = _indexExpressions[0];
     index = ExprNodeUtilityValidate.GetValidatedSubtree(origin, index, validationContext);
     _indexExpressions = Collections.SingletonList(index);
     ChainableArray.ValidateSingleIndexExpr(_indexExpressions, () => "expression '" + Ident + "'");
     EPStatementStartMethodHelperValidate.ValidateNoAggregations(index, ExprAssignment.ValidationAggMsg);
 }
Пример #12
0
 public void TestEvaluate()
 {
     log.Debug(".testEvaluate");
     _bitWiseNode.AddChildNode(new SupportExprNode(10));
     _bitWiseNode.AddChildNode(new SupportExprNode(12));
     ExprNodeUtilityValidate.GetValidatedSubtree(
         ExprNodeOrigin.SELECT,
         _bitWiseNode,
         SupportExprValidationContextFactory.MakeEmpty(container));
     Assert.AreEqual(8, _bitWiseNode.Forge.ExprEvaluator.Evaluate(null, false, null));
 }
    private void ValidateParamsUnless(
            ExprValidationContext validationContext,
            ExprNode[] parameters)
        {
            if (ParametersValidated) {
                return;
            }

            ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.AGGPARAM, parameters, validationContext);
            ParametersValidated = true;
        }
Пример #14
0
        public ExprNode CompileValidate(
            string expression,
            EventType[] eventTypes,
            string[] streamNames)
        {
            var services = new StatementCompileTimeServices(0, moduleServices);

            ExprNode node;
            try {
                node = services.CompilerServices.CompileExpression(expression, services);
            }
            catch (ExprValidationException e) {
                throw new EPCompileException(
                    "Failed to compile expression '" + expression + "': " + e.Message,
                    e,
                    new EmptyList<EPCompileExceptionItem>());
            }

            try {
                ExprNodeUtilityValidate.ValidatePlainExpression(ExprNodeOrigin.API, node);

                StreamTypeService streamTypeService;

                if (eventTypes == null || eventTypes.Length == 0) {
                    streamTypeService = new StreamTypeServiceImpl(true);
                }
                else {
                    var istreamOnly = new bool[eventTypes.Length];
                    istreamOnly.Fill(true);
                    streamTypeService = new StreamTypeServiceImpl(eventTypes, streamNames, istreamOnly, true, false);
                }
                
                var statementRawInfo = new StatementRawInfo(
                    0,
                    "API-provided",
                    null,
                    StatementType.INTERNAL_USE_API_COMPILE_EXPR,
                    null,
                    null,
                    new CompilableEPL(expression),
                    "API-provided");
                var validationContext = new ExprValidationContextBuilder(streamTypeService, statementRawInfo, services).Build();
                node = ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.API, node, validationContext);
            }
            catch (ExprValidationException e) {
                throw new EPCompileException(
                    "Failed to validate expression '" + expression + "': " + e.Message,
                    e,
                    new EmptyList<EPCompileExceptionItem>());
            }

            return node;
        }
Пример #15
0
        private static EventAdvancedIndexProvisionCompileTime ValidateAdvanced(
            string indexName,
            string indexType,
            CreateIndexItem columnDesc,
            EventType eventType,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            // validate index expressions: valid and plain expressions
            StreamTypeService streamTypeService = new StreamTypeServiceImpl(eventType, null, false);
            var validationContextColumns =
                new ExprValidationContextBuilder(streamTypeService, statementRawInfo, services)
                    .WithDisablePropertyExpressionEventCollCache(true)
                    .Build();
            var columns = columnDesc.Expressions.ToArray();
            ExprNodeUtilityValidate.GetValidatedSubtree(
                ExprNodeOrigin.CREATEINDEXCOLUMN,
                columns,
                validationContextColumns);
            ExprNodeUtilityValidate.ValidatePlainExpression(ExprNodeOrigin.CREATEINDEXCOLUMN, columns);

            // validate parameters, may not depend on props
            ExprNode[] parameters = null;
            if (columnDesc.Parameters != null && !columnDesc.Parameters.IsEmpty()) {
                parameters = columnDesc.Parameters.ToArray();
                ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.CREATEINDEXPARAMETER,
                    parameters,
                    validationContextColumns);
                ExprNodeUtilityValidate.ValidatePlainExpression(ExprNodeOrigin.CREATEINDEXPARAMETER, parameters);

                // validate no stream dependency of parameters
                var visitor = new ExprNodeIdentifierAndStreamRefVisitor(false);
                foreach (var param in columnDesc.Parameters) {
                    param.Accept(visitor);
                    if (!visitor.Refs.IsEmpty()) {
                        throw new ExprValidationException("Index parameters may not refer to event properties");
                    }
                }
            }

            // obtain provider
            AdvancedIndexFactoryProvider provider;
            try {
                provider = services.ImportServiceCompileTime.ResolveAdvancedIndexProvider(indexType);
            }
            catch (ImportException ex) {
                throw new ExprValidationException(ex.Message, ex);
            }

            return provider.ValidateEventIndex(indexName, indexType, columns, parameters);
        }
Пример #16
0
        public override AggregationForgeFactory ValidateAggregationChild(ExprValidationContext validationContext)
        {
            if (IsDistinct)
            {
                throw new ExprValidationException(MessagePrefix + "is not supported with distinct");
            }

            // for declaration, validate the specification and return the state factory
            if (aggType == CountMinSketchAggType.STATE)
            {
                if (validationContext.StatementRawInfo.StatementType != StatementType.CREATE_TABLE)
                {
                    throw new ExprValidationException(MessagePrefix + "can only be used in create-table statements");
                }

                CountMinSketchSpecForge             specification = ValidateSpecification(validationContext);
                AggregationStateCountMinSketchForge stateFactory  = new AggregationStateCountMinSketchForge(this, specification);
                forgeFactory = new AggregationForgeFactoryAccessCountMinSketchState(this, stateFactory);
                return(forgeFactory);
            }

            if (aggType != CountMinSketchAggType.ADD)
            {
                // other methods are only used with table-access expressions
                throw new ExprValidationException(MessagePrefix + "requires the use of a table-access expression");
            }

            if (validationContext.StatementRawInfo.IntoTableName == null)
            {
                throw new ExprValidationException(MessagePrefix + "can only be used with into-table");
            }

            if (positionalParams.Length == 0 || positionalParams.Length > 1)
            {
                throw new ExprValidationException(MessagePrefix + "requires a single parameter expression");
            }

            ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.AGGPARAM, this.ChildNodes, validationContext);

            // obtain evaluator
            ExprForge addOrFrequencyEvaluator           = null;
            Type      addOrFrequencyEvaluatorReturnType = null;

            if (aggType == CountMinSketchAggType.ADD)
            {
                addOrFrequencyEvaluator           = ChildNodes[0].Forge;
                addOrFrequencyEvaluatorReturnType = addOrFrequencyEvaluator.EvaluationType;
            }

            forgeFactory = new AggregationForgeFactoryAccessCountMinSketchAdd(this, addOrFrequencyEvaluator, addOrFrequencyEvaluatorReturnType);
            return(forgeFactory);
        }
        public ExprNode Validate(ExprValidationContext validationContext)
        {
            ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.DOTNODEPARAMETER, Lhs, validationContext);
            ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.DOTNODEPARAMETER, Rhs, validationContext);

            forge = ValidateAll(LhsName, Lhs, RhsName, Rhs, validationContext);

            if (indexNamedParameter != null) {
                ValidateIndexNamedParameter(validationContext);
            }

            return null;
        }
Пример #18
0
        private static IList<NamedWindowSelectedProps> CompileLimitedSelect(
            SelectFromInfo selectFromInfo,
            StatementBaseInfo @base,
            StatementCompileTimeServices compileTimeServices)
        {
            IList<NamedWindowSelectedProps> selectProps = new List<NamedWindowSelectedProps>();
            StreamTypeService streams = new StreamTypeServiceImpl(
                new[] {selectFromInfo.EventType},
                new[] {"stream_0"},
                new[] {false},
                false,
                false);

            var validationContext =
                new ExprValidationContextBuilder(streams, @base.StatementRawInfo, compileTimeServices).Build();
            foreach (var item in @base.StatementSpec.SelectClauseCompiled.SelectExprList) {
                if (!(item is SelectClauseExprCompiledSpec)) {
                    continue;
                }

                var exprSpec = (SelectClauseExprCompiledSpec) item;
                var validatedExpression = ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.SELECT,
                    exprSpec.SelectExpression,
                    validationContext);

                // determine an element name if none assigned
                var asName = exprSpec.ProvidedName;
                if (asName == null) {
                    asName = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(validatedExpression);
                }

                // check for fragments
                EventType fragmentType = null;
                if (validatedExpression is ExprIdentNode && !(selectFromInfo.EventType is NativeEventType)) {
                    var identNode = (ExprIdentNode) validatedExpression;
                    var fragmentEventType = selectFromInfo.EventType.GetFragmentType(identNode.FullUnresolvedName);
                    if (fragmentEventType != null && !fragmentEventType.IsNative) {
                        fragmentType = fragmentEventType.FragmentType;
                    }
                }

                var validatedElement = new NamedWindowSelectedProps(
                    validatedExpression.Forge.EvaluationType,
                    asName,
                    fragmentType);
                selectProps.Add(validatedElement);
            }

            return selectProps;
        }
Пример #19
0
        public void Validate3Stream(
            ExprNode topNode)
        {
            var streamTypeService = new SupportStreamTypeSvc3Stream(
                SupportEventTypeFactory.GetInstance(_container));
            var validationContext = SupportExprValidationContextFactory.Make(_container, streamTypeService);

            try {
                ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.SELECT, topNode, validationContext);
            }
            catch (ExprValidationException e) {
                throw new EPRuntimeException(e);
            }
        }
        public override IList<StmtClassForgeableFactory> Validate(
            StreamTypeService typeService,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            int count = 0;
            ExprValidationContext validationContext =
                new ExprValidationContextBuilder(typeService, @base.StatementRawInfo, services)
                    .WithAllowBindingConsumption(true)
                    .Build();
            ExprNode[] inputParamNodes = new ExprNode[inputParameters.Length];
            foreach (string inputParam in inputParameters) {
                ExprNode raw = FindSQLExpressionNode(StreamNum, count, @base.StatementSpec.Raw.SqlParameters);
                if (raw == null) {
                    throw new ExprValidationException(
                        "Internal error find expression for historical stream parameter " +
                        count +
                        " stream " +
                        StreamNum);
                }

                ExprNode evaluator = ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.DATABASEPOLL,
                    raw,
                    validationContext);
                inputParamNodes[count++] = evaluator;

                ExprNodeIdentifierCollectVisitor visitor = new ExprNodeIdentifierCollectVisitor();
                visitor.Visit(evaluator);
                foreach (ExprIdentNode identNode in visitor.ExprProperties) {
                    if (identNode.StreamId == StreamNum) {
                        throw new ExprValidationException(
                            "Invalid expression '" + inputParam + "' resolves to the historical data itself");
                    }

                    SubordinateStreams.Add(identNode.StreamId);
                }
            }

            InputParamEvaluators = ExprNodeUtilityQuery.GetForges(inputParamNodes);
            
            
            // plan multikey
            MultiKeyPlan multiKeyPlan = MultiKeyPlanner.PlanMultiKey(InputParamEvaluators, false, @base.StatementRawInfo, services.SerdeResolver);
            MultiKeyClassRef = multiKeyPlan.ClassRef;

            return multiKeyPlan.MultiKeyForgeables;
        }
Пример #21
0
        private static IList<ExprNode> ValidateExpressions(
            ExprNodeOrigin exprNodeOrigin,
            IList<ExprNode> objectParameters,
            ExprValidationContext validationContext)
        {
            if (objectParameters == null) {
                return objectParameters;
            }

            IList<ExprNode> validated = new List<ExprNode>();
            foreach (var node in objectParameters) {
                validated.Add(ExprNodeUtilityValidate.GetValidatedSubtree(exprNodeOrigin, node, validationContext));
            }

            return validated;
        }
Пример #22
0
        public void TestEvaluate()
        {
            arithNode.AddChildNode(new SupportExprNode(10));
            arithNode.AddChildNode(new SupportExprNode(1.5));
            ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.SELECT, arithNode, SupportExprValidationContextFactory.MakeEmpty(container));
            Assert.AreEqual(11.5d, arithNode.Forge.ExprEvaluator.Evaluate(null, false, null));

            arithNode = MakeNode(null, typeof(int?), 5d, typeof(double?));
            Assert.IsNull(arithNode.Forge.ExprEvaluator.Evaluate(null, false, null));

            arithNode = MakeNode(5, typeof(int?), null, typeof(double?));
            Assert.IsNull(arithNode.Forge.ExprEvaluator.Evaluate(null, false, null));

            arithNode = MakeNode(null, typeof(int?), null, typeof(double?));
            Assert.IsNull(arithNode.Forge.ExprEvaluator.Evaluate(null, false, null));
        }
        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);
        }
 public OutputConditionPolledCrontabFactoryForge(
     IList<ExprNode> list,
     StatementRawInfo statementRawInfo,
     StatementCompileTimeServices services)
 {
     ExprValidationContext validationContext =
         new ExprValidationContextBuilder(new StreamTypeServiceImpl(false), statementRawInfo, services).Build();
     expressions = new ExprNode[list.Count];
     int count = 0;
     foreach (ExprNode parameters in list) {
         ExprNode node = ExprNodeUtilityValidate.GetValidatedSubtree(
             ExprNodeOrigin.OUTPUTLIMIT,
             parameters,
             validationContext);
         expressions[count++] = node;
     }
 }
Пример #25
0
 public static ExprNode ValidateExprNoAgg(
     ExprNodeOrigin exprNodeOrigin,
     ExprNode exprNode,
     StreamTypeService streamTypeService,
     string errorMsg,
     bool allowTableConsumption,
     bool allowTableAggReset,
     StatementRawInfo raw,
     StatementCompileTimeServices compileTimeServices)
 {
     var validationContext = new ExprValidationContextBuilder(streamTypeService, raw, compileTimeServices)
             .WithAllowBindingConsumption(allowTableConsumption)
             .WithAllowTableAggReset(allowTableAggReset)
             .Build();
     var validated = ExprNodeUtilityValidate.GetValidatedSubtree(exprNodeOrigin, exprNode, validationContext);
     ValidateNoAggregations(validated, errorMsg);
     return validated;
 }
Пример #26
0
 public override AggregationForgeFactory ValidateAggregationChild(ExprValidationContext validationContext)
 {
     ValidatePositionals(validationContext);
     // validate using the context provided by the 'outside' streams to determine parameters
     // at this time 'inside' expressions like 'window(IntPrimitive)' are not handled
     ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.AGGPARAM, ChildNodes, validationContext);
     var ctx = new AggregationMultiFunctionValidationContext(
         functionName,
         validationContext.StreamTypeService.EventTypes,
         positionalParams,
         validationContext.StatementName,
         validationContext,
         config,
         null,
         ChildNodes,
         optionalFilter);
     var handlerPlugin = aggregationMultiFunctionForge.ValidateGetHandler(ctx);
     factory = new AggregationForgeFactoryAccessPlugin(this, handlerPlugin);
     return factory;
 }
Пример #27
0
        private static ExprNode ValidateBounds(
            ExprNode bounds,
            ExprValidationContext validationContext)
        {
            var message = "Match-until bounds value expressions must return a numeric value";
            if (bounds != null) {
                var validated = ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.PATTERNMATCHUNTILBOUNDS,
                    bounds,
                    validationContext);
                var returnType = validated.Forge.EvaluationType;
                if (returnType == null || !returnType.IsNumeric()) {
                    throw new ExprValidationException(message);
                }

                return validated;
            }

            return null;
        }
Пример #28
0
        private static ExprNode ValidateMeasureClause(
            ExprNode measureNode,
            StreamTypeService typeServiceMeasure,
            ISet<string> variablesMultiple,
            ISet<string> variablesSingle,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            try {
                var validationContext = new ExprValidationContextBuilder(typeServiceMeasure, statementRawInfo, services)
                    .WithAllowBindingConsumption(true)
                    .WithDisablePropertyExpressionEventCollCache(true)
                    .WithAggregationFutureNameAlreadySet(true)
                    .Build();
                return ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.MATCHRECOGMEASURE,
                    measureNode,
                    validationContext);
            }
            catch (ExprValidationPropertyException e) {
                var grouped = CollectionUtil.ToString(variablesMultiple);
                var single = CollectionUtil.ToString(variablesSingle);
                var message = e.Message;
                if (!variablesMultiple.IsEmpty()) {
                    message += ", ensure that grouped variables (variables " +
                               grouped +
                               ") are accessed via index (i.e. variable[0].property) or appear within an aggregation";
                }

                if (!variablesSingle.IsEmpty()) {
                    message += ", ensure that singleton variables (variables " +
                               single +
                               ") are not accessed via index";
                }

                throw new ExprValidationPropertyException(message, e);
            }
        }
Пример #29
0
        public AggregationTableReadDesc ValidateAggregationTableRead(
            ExprValidationContext validationContext,
            TableMetadataColumnAggregation tableAccessColumn,
            TableMetaData table)
        {
            // child node validation
            ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.AGGPARAM, ChildNodes, validationContext);

            // portable validation
            var validation = tableAccessColumn.AggregationPortableValidation;
            if (!(validation is AggregationPortableValidationPluginMultiFunc)) {
                throw new ExprValidationException("Invalid aggregation column type");
            }

            // obtain handler
            var ctx = new AggregationMultiFunctionValidationContext(
                functionName,
                validationContext.StreamTypeService.EventTypes,
                positionalParams,
                validationContext.StatementName,
                validationContext,
                config,
                null,
                ChildNodes,
                optionalFilter);
            var handler = aggregationMultiFunctionForge.ValidateGetHandler(ctx);

            // set of reader
            var epType = handler.ReturnType;
            Type returnType = EPTypeHelper.GetNormalizedClass(epType);
            var forge = new AggregationTableAccessAggReaderForgePlugIn(
                returnType,
                (AggregationMultiFunctionTableReaderModeManaged) handler.TableReaderMode);
            EventType eventTypeCollection = EPTypeHelper.OptionalIsEventTypeColl(epType);
            EventType eventTypeSingle = EPTypeHelper.OptionalIsEventTypeSingle(epType);
            Type componentTypeCollection = EPTypeHelper.OptionalIsComponentTypeColl(epType);
            return new AggregationTableReadDesc(forge, eventTypeCollection, componentTypeCollection, eventTypeSingle);
        }
Пример #30
0
        public static ExprNode ValidateSimpleGetSubtree(
            ExprNodeOrigin origin,
            ExprNode expression,
            EventType optionalEventType,
            bool allowBindingConsumption,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            ExprNodeUtilityValidate.ValidatePlainExpression(origin, expression);

            StreamTypeServiceImpl streamTypes;
            if (optionalEventType != null) {
                streamTypes = new StreamTypeServiceImpl(optionalEventType, null, true);
            }
            else {
                streamTypes = new StreamTypeServiceImpl(false);
            }

            var validationContext = new ExprValidationContextBuilder(streamTypes, statementRawInfo, services)
                .WithAllowBindingConsumption(allowBindingConsumption)
                .Build();
            return ExprNodeUtilityValidate.GetValidatedSubtree(origin, expression, validationContext);
        }