Пример #1
0
 public override void Validate(
     ExprNodeOrigin origin,
     ExprValidationContext validationContext)
 {
     Expression = GetValidatedSubtree(origin, Expression, validationContext);
     EPStatementStartMethodHelperValidate.ValidateNoAggregations(Expression, ValidationAggMsg);
 }
Пример #2
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);
            }
        }
Пример #3
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);
 }
Пример #4
0
        public StmtForgeMethodResult Make(
            string @namespace,
            string classPostfix,
            StatementCompileTimeServices services)
        {
            var statementSpec = @base.StatementSpec;

            // determine context
            var contextName = @base.StatementSpec.Raw.OptionalContextName;
            if (contextName != null) {
                throw new ExprValidationException("Update IStream is not supported in conjunction with a context");
            }

            var streamSpec = statementSpec.StreamSpecs[0];
            var updateSpec = statementSpec.Raw.UpdateDesc;
            string triggereventTypeName;
            EventType streamEventType;

            if (streamSpec is FilterStreamSpecCompiled) {
                var filterStreamSpec = (FilterStreamSpecCompiled) streamSpec;
                triggereventTypeName = filterStreamSpec.FilterSpecCompiled.FilterForEventTypeName;
                streamEventType = filterStreamSpec.FilterSpecCompiled.FilterForEventType;
            }
            else if (streamSpec is NamedWindowConsumerStreamSpec) {
                var namedSpec = (NamedWindowConsumerStreamSpec) streamSpec;
                streamEventType = namedSpec.NamedWindow.EventType;
                triggereventTypeName = streamEventType.Name;
            }
            else if (streamSpec is TableQueryStreamSpec) {
                throw new ExprValidationException("Tables cannot be used in an update-istream statement");
            }
            else {
                throw new ExprValidationException("Unknown stream specification streamEventType: " + streamSpec);
            }

            // determine a stream name
            var streamName = triggereventTypeName;
            if (updateSpec.OptionalStreamName != null) {
                streamName = updateSpec.OptionalStreamName;
            }

            StreamTypeService typeService = new StreamTypeServiceImpl(
                new[] {streamEventType},
                new[] {streamName},
                new[] {true},
                false,
                false);

            // create subselect information
            IList<FilterSpecCompiled> filterSpecCompileds = new List<FilterSpecCompiled>();
            IList<NamedWindowConsumerStreamSpec> namedWindowConsumers = new List<NamedWindowConsumerStreamSpec>();
            var subselectActivation = SubSelectHelperActivations.CreateSubSelectActivation(
                filterSpecCompileds,
                namedWindowConsumers,
                @base,
                services);

            // handle subselects
            var subselectForges = SubSelectHelperForgePlanner.PlanSubSelect(
                @base,
                subselectActivation,
                typeService.StreamNames,
                typeService.EventTypes,
                new[] {triggereventTypeName},
                services);

            var validationContext =
                new ExprValidationContextBuilder(typeService, @base.StatementRawInfo, services).Build();

            foreach (var assignment in updateSpec.Assignments) {
                var validated = ExprNodeUtilityValidate.GetValidatedAssignment(assignment, validationContext);
                assignment.Expression = validated;
                EPStatementStartMethodHelperValidate.ValidateNoAggregations(
                    validated,
                    "Aggregation functions may not be used within an update-clause");
            }

            if (updateSpec.OptionalWhereClause != null) {
                var validated = ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.WHERE,
                    updateSpec.OptionalWhereClause,
                    validationContext);
                updateSpec.OptionalWhereClause = validated;
                EPStatementStartMethodHelperValidate.ValidateNoAggregations(
                    validated,
                    "Aggregation functions may not be used within an update-clause");
            }

            // build route information
            var routerDesc = InternalEventRouterDescFactory.GetValidatePreprocessing(
                streamEventType,
                updateSpec,
                @base.StatementRawInfo.Annotations);

            var statementFieldsClassName =
                CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementFields), classPostfix);
            var packageScope = new CodegenNamespaceScope(
                @namespace,
                statementFieldsClassName,
                services.IsInstrumented);

            var aiFactoryProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(
                typeof(StatementAIFactoryProvider),
                classPostfix);
            var forge = new StatementAgentInstanceFactoryUpdateForge(routerDesc, subselectForges);
            var aiFactoryForgable = new StmtClassForgableAIFactoryProviderUpdate(
                aiFactoryProviderClassName,
                packageScope,
                forge);

            var selectSubscriberDescriptor = new SelectSubscriberDescriptor(
                new[] {streamEventType.UnderlyingType},
                new[] {"*"},
                false,
                null);
            var informationals = StatementInformationalsUtil.GetInformationals(
                @base,
                filterSpecCompileds,
                Collections.GetEmptyList<ScheduleHandleCallbackProvider>(),
                Collections.GetEmptyList<NamedWindowConsumerStreamSpec>(),
                false,
                selectSubscriberDescriptor,
                packageScope,
                services);
            var statementProviderClassName =
                CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementProvider), classPostfix);
            var stmtProvider = new StmtClassForgableStmtProvider(
                aiFactoryProviderClassName,
                statementProviderClassName,
                informationals,
                packageScope);

            IList<StmtClassForgable> forgables = new List<StmtClassForgable>();
            forgables.Add(aiFactoryForgable);
            forgables.Add(stmtProvider);
            forgables.Add(new StmtClassForgableStmtFields(statementFieldsClassName, packageScope, 0));
            return new StmtForgeMethodResult(
                forgables,
                filterSpecCompileds,
                Collections.GetEmptyList<ScheduleHandleCallbackProvider>(),
                namedWindowConsumers,
                Collections.GetEmptyList<FilterSpecParamExprNodeForge>());
        }
Пример #5
0
        private static IList<SelectClauseElementCompiled> ValidateInsertSelect(
            IList<SelectClauseElementRaw> selectClause,
            StreamTypeService insertTypeSvc,
            IList<string> insertColumns,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            var colIndex = 0;
            IList<SelectClauseElementCompiled> compiledSelect = new List<SelectClauseElementCompiled>();
            foreach (var raw in selectClause) {
                if (raw is SelectClauseStreamRawSpec) {
                    var rawStreamSpec = (SelectClauseStreamRawSpec) raw;
                    int? foundStreamNum = null;
                    for (var s = 0; s < insertTypeSvc.StreamNames.Length; s++) {
                        if (rawStreamSpec.StreamName.Equals(insertTypeSvc.StreamNames[s])) {
                            foundStreamNum = s;
                            break;
                        }
                    }

                    if (foundStreamNum == null) {
                        throw new ExprValidationException(
                            "Stream by name '" + rawStreamSpec.StreamName + "' was not found");
                    }

                    var streamSelectSpec = new SelectClauseStreamCompiledSpec(
                        rawStreamSpec.StreamName,
                        rawStreamSpec.OptionalAsName);
                    streamSelectSpec.StreamNumber = foundStreamNum.Value;
                    compiledSelect.Add(streamSelectSpec);
                }
                else if (raw is SelectClauseExprRawSpec) {
                    var exprSpec = (SelectClauseExprRawSpec) raw;
                    var validationContext = new ExprValidationContextBuilder(insertTypeSvc, statementRawInfo, services)
                        .WithAllowBindingConsumption(true)
                        .Build();
                    var exprCompiled = ExprNodeUtilityValidate.GetValidatedSubtree(
                        ExprNodeOrigin.SELECT,
                        exprSpec.SelectExpression,
                        validationContext);
                    var resultName = exprSpec.OptionalAsName;
                    if (resultName == null) {
                        if (insertColumns.Count > colIndex) {
                            resultName = insertColumns[colIndex];
                        }
                        else {
                            resultName = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(exprCompiled);
                        }
                    }

                    compiledSelect.Add(
                        new SelectClauseExprCompiledSpec(
                            exprCompiled,
                            resultName,
                            exprSpec.OptionalAsName,
                            exprSpec.IsEvents));
                    EPStatementStartMethodHelperValidate.ValidateNoAggregations(
                        exprCompiled,
                        "Expression in a merge-selection may not utilize aggregation functions");
                }
                else if (raw is SelectClauseElementWildcard) {
                    compiledSelect.Add(new SelectClauseElementWildcard());
                }
                else {
                    throw new IllegalStateException("Unknown select clause item:" + raw);
                }

                colIndex++;
            }

            return compiledSelect;
        }
Пример #6
0
        public static OnTriggerPlanValidationResult ValidateOnTriggerPlan(
            EventType namedWindowOrTableType,
            OnTriggerWindowDesc onTriggerDesc,
            StreamSpecCompiled streamSpec,
            OnTriggerActivatorDesc activatorResult,
            IDictionary<ExprSubselectNode, SubSelectActivationPlan> subselectActivation,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var zeroStreamAliasName = onTriggerDesc.OptionalAsName;
            if (zeroStreamAliasName == null) {
                zeroStreamAliasName = "stream_0";
            }

            var streamName = streamSpec.OptionalStreamName;
            if (streamName == null) {
                streamName = "stream_1";
            }

            var namedWindowTypeName = onTriggerDesc.WindowName;

            // Materialize sub-select views
            // 0 - named window stream
            // 1 - arriving stream
            // 2 - initial value before update
            string[] subselectStreamNames = {zeroStreamAliasName, streamSpec.OptionalStreamName};
            EventType[] subselectEventTypes = {namedWindowOrTableType, activatorResult.ActivatorResultEventType};
            string[] subselectEventTypeNames = {namedWindowTypeName, activatorResult.TriggerEventTypeName};
            var subselectForges = SubSelectHelperForgePlanner.PlanSubSelect(
                @base,
                subselectActivation,
                subselectStreamNames,
                subselectEventTypes,
                subselectEventTypeNames,
                services);

            var typeService = new StreamTypeServiceImpl(
                new[] {namedWindowOrTableType, activatorResult.ActivatorResultEventType},
                new[] {zeroStreamAliasName, streamName},
                new[] {false, true},
                true,
                false);

            // allow "initial" as a prefix to properties
            StreamTypeServiceImpl assignmentTypeService;
            if (zeroStreamAliasName.Equals(INITIAL_VALUE_STREAM_NAME) || streamName.Equals(INITIAL_VALUE_STREAM_NAME)) {
                assignmentTypeService = typeService;
            }
            else {
                assignmentTypeService = new StreamTypeServiceImpl(
                    new[] {namedWindowOrTableType, activatorResult.ActivatorResultEventType, namedWindowOrTableType},
                    new[] {zeroStreamAliasName, streamName, INITIAL_VALUE_STREAM_NAME},
                    new[] {false, true, true},
                    false,
                    false);
                assignmentTypeService.IsStreamZeroUnambigous = true;
            }

            if (onTriggerDesc is OnTriggerWindowUpdateDesc) {
                var updateDesc = (OnTriggerWindowUpdateDesc) onTriggerDesc;
                var validationContext = new ExprValidationContextBuilder(
                        assignmentTypeService,
                        @base.StatementRawInfo,
                        services)
                    .WithAllowBindingConsumption(true)
                    .Build();
                foreach (var assignment in updateDesc.Assignments) {
                    var validated = ExprNodeUtilityValidate.GetValidatedAssignment(assignment, validationContext);
                    assignment.Expression = validated;
                    EPStatementStartMethodHelperValidate.ValidateNoAggregations(
                        validated,
                        "Aggregation functions may not be used within an on-update-clause");
                }
            }

            if (onTriggerDesc is OnTriggerMergeDesc) {
                var mergeDesc = (OnTriggerMergeDesc) onTriggerDesc;
                ValidateMergeDesc(
                    mergeDesc,
                    namedWindowOrTableType,
                    zeroStreamAliasName,
                    activatorResult.ActivatorResultEventType,
                    streamName,
                    @base.StatementRawInfo,
                    services);
            }

            // validate join expression
            var validatedJoin = ValidateJoinNamedWindow(
                ExprNodeOrigin.WHERE,
                @base.StatementSpec.Raw.WhereClause,
                namedWindowOrTableType,
                zeroStreamAliasName,
                namedWindowTypeName,
                activatorResult.ActivatorResultEventType,
                streamName,
                activatorResult.TriggerEventTypeName,
                null,
                @base.StatementRawInfo,
                services);

            // validate filter, output rate limiting
            EPStatementStartMethodHelperValidate.ValidateNodes(
                @base.StatementSpec.Raw,
                typeService,
                null,
                @base.StatementRawInfo,
                services);

            // Construct a processor for results; for use in on-select to process selection results
            // Use a wildcard select if the select-clause is empty, such as for on-delete.
            // For on-select the select clause is not empty.
            if (@base.StatementSpec.SelectClauseCompiled.SelectExprList.Length == 0) {
                @base.StatementSpec.SelectClauseCompiled.WithSelectExprList(new SelectClauseElementWildcard());
            }

            var resultSetProcessorPrototype = ResultSetProcessorFactoryFactory.GetProcessorPrototype(
                new ResultSetSpec(@base.StatementSpec),
                typeService,
                null,
                new bool[0],
                true,
                @base.ContextPropertyRegistry,
                false,
                true,
                @base.StatementRawInfo,
                services);

            // plan table access
            var tableAccessForges = ExprTableEvalHelperPlan.PlanTableAccess(@base.StatementSpec.TableAccessNodes);

            return new OnTriggerPlanValidationResult(
                subselectForges,
                tableAccessForges,
                resultSetProcessorPrototype,
                validatedJoin,
                zeroStreamAliasName);
        }