public OnTriggerWindowPlan( OnTriggerWindowDesc onTriggerDesc, string contextName, OnTriggerActivatorDesc activatorResult, StreamSelector? optionalStreamSelector, IDictionary<ExprSubselectNode, SubSelectActivationPlan> subselectActivation, StreamSpecCompiled streamSpec) { OnTriggerDesc = onTriggerDesc; ContextName = contextName; ActivatorResult = activatorResult; OptionalStreamSelector = optionalStreamSelector; SubselectActivation = subselectActivation; StreamSpec = streamSpec; }
public static OnTriggerPlan HandleSplitStream( string aiFactoryProviderClassName, CodegenNamespaceScope namespaceScope, string classPostfix, OnTriggerSplitStreamDesc desc, StreamSpecCompiled streamSpec, OnTriggerActivatorDesc activatorResult, IDictionary<ExprSubselectNode, SubSelectActivationPlan> subselectActivation, StatementBaseInfo @base, StatementCompileTimeServices services) { var raw = @base.StatementSpec.Raw; if (raw.InsertIntoDesc == null) { throw new ExprValidationException( "Required insert-into clause is not provided, the clause is required for split-stream syntax"); } if (raw.GroupByExpressions != null && raw.GroupByExpressions.Count > 0 || raw.HavingClause != null || raw.OrderByList.Count > 0) { throw new ExprValidationException( "A group-by clause, having-clause or order-by clause is not allowed for the split stream syntax"); } var streamName = streamSpec.OptionalStreamName; if (streamName == null) { streamName = "stream_0"; } StreamTypeService typeServiceTrigger = new StreamTypeServiceImpl( new[] {activatorResult.ActivatorResultEventType}, new[] {streamName}, new[] {true}, false, false); // materialize sub-select views var subselectForges = SubSelectHelperForgePlanner.PlanSubSelect( @base, subselectActivation, new[] {streamSpec.OptionalStreamName}, new[] {activatorResult.ActivatorResultEventType}, new[] {activatorResult.TriggerEventTypeName}, services); // compile top-level split var items = new OnSplitItemForge[desc.SplitStreams.Count + 1]; items[0] = OnSplitValidate( typeServiceTrigger, @base.StatementSpec, @base.ContextPropertyRegistry, null, @base.StatementRawInfo, services); // compile each additional split var index = 1; foreach (var splits in desc.SplitStreams) { var splitSpec = new StatementSpecCompiled(); splitSpec.Raw.InsertIntoDesc = splits.InsertInto; splitSpec.SelectClauseCompiled = CompileSelectAllowSubselect(splits.SelectClause); splitSpec.Raw.WhereClause = splits.WhereClause; PropertyEvaluatorForge optionalPropertyEvaluator = null; StreamTypeService typeServiceProperty; if (splits.FromClause != null) { optionalPropertyEvaluator = PropertyEvaluatorForgeFactory.MakeEvaluator( splits.FromClause.PropertyEvalSpec, activatorResult.ActivatorResultEventType, streamName, @base.StatementRawInfo, services); typeServiceProperty = new StreamTypeServiceImpl( new[] {optionalPropertyEvaluator.FragmentEventType}, new[] {splits.FromClause.OptionalStreamName}, new[] {true}, false, false); } else { typeServiceProperty = typeServiceTrigger; } items[index] = OnSplitValidate( typeServiceProperty, splitSpec, @base.ContextPropertyRegistry, optionalPropertyEvaluator, @base.StatementRawInfo, services); index++; } // handle result set processor classes IList<StmtClassForgable> forgables = new List<StmtClassForgable>(); for (var i = 0; i < items.Length; i++) { var classNameRSP = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(ResultSetProcessorFactoryProvider), classPostfix + "_" + i); forgables.Add( new StmtClassForgableRSPFactoryProvider( classNameRSP, items[i].ResultSetProcessorDesc, namespaceScope, @base.StatementRawInfo)); items[i].ResultSetProcessorClassName = classNameRSP; } // plan table access var tableAccessForges = ExprTableEvalHelperPlan.PlanTableAccess(@base.StatementSpec.TableAccessNodes); // build forge var splitStreamForge = new StatementAgentInstanceFactoryOnTriggerSplitStreamForge( activatorResult.Activator, activatorResult.ActivatorResultEventType, subselectForges, tableAccessForges, items, desc.IsFirst); var triggerForge = new StmtClassForgableAIFactoryProviderOnTrigger( aiFactoryProviderClassName, namespaceScope, splitStreamForge); return new OnTriggerPlan(triggerForge, forgables, new SelectSubscriberDescriptor()); }
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); }
public static OnTriggerSetPlan HandleSetVariable( string className, CodegenNamespaceScope namespaceScope, string classPostfix, OnTriggerActivatorDesc activatorResult, string optionalStreamName, IDictionary<ExprSubselectNode, SubSelectActivationPlan> subselectActivation, OnTriggerSetDesc desc, StatementBaseInfo @base, StatementCompileTimeServices services) { StreamTypeService typeService = new StreamTypeServiceImpl( new[] {activatorResult.ActivatorResultEventType}, new[] {optionalStreamName}, new[] {true}, false, false); var validationContext = new ExprValidationContextBuilder(typeService, @base.StatementRawInfo, services) .WithAllowBindingConsumption(true) .Build(); // handle subselects var subselectForges = SubSelectHelperForgePlanner.PlanSubSelect( @base, subselectActivation, new[] {optionalStreamName}, new[] {activatorResult.ActivatorResultEventType}, new[] {activatorResult.TriggerEventTypeName}, services); // validate assignments foreach (var assignment in desc.Assignments) { var validated = ExprNodeUtilityValidate.GetValidatedAssignment(assignment, validationContext); assignment.Expression = validated; } // create read-write logic var variableReadWritePackageForge = new VariableReadWritePackageForge(desc.Assignments, services); // plan table access var tableAccessForges = ExprTableEvalHelperPlan.PlanTableAccess(@base.StatementSpec.TableAccessNodes); // create output event type var eventTypeName = services.EventTypeNameGeneratorStatement.AnonymousTypeName; var eventTypeMetadata = new EventTypeMetadata( eventTypeName, @base.ModuleName, EventTypeTypeClass.STATEMENTOUT, EventTypeApplicationType.MAP, NameAccessModifier.TRANSIENT, EventTypeBusModifier.NONBUS, false, EventTypeIdPair.Unassigned()); var eventType = BaseNestableEventUtil.MakeMapTypeCompileTime( eventTypeMetadata, variableReadWritePackageForge.VariableTypes, null, null, null, null, services.BeanEventTypeFactoryPrivate, services.EventTypeCompileTimeResolver); services.EventTypeCompileTimeRegistry.NewType(eventType); // Handle output format var defaultSelectAllSpec = new StatementSpecCompiled(); defaultSelectAllSpec.SelectClauseCompiled.WithSelectExprList(new SelectClauseElementWildcard()); defaultSelectAllSpec.Raw.SelectStreamDirEnum = SelectClauseStreamSelectorEnum.RSTREAM_ISTREAM_BOTH; StreamTypeService streamTypeService = new StreamTypeServiceImpl( new EventType[] {eventType}, new[] {"trigger_stream"}, new[] {true}, false, false); var resultSetProcessor = ResultSetProcessorFactoryFactory.GetProcessorPrototype( new ResultSetSpec(defaultSelectAllSpec), streamTypeService, null, new bool[1], false, @base.ContextPropertyRegistry, false, false, @base.StatementRawInfo, services); var classNameRSP = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(ResultSetProcessorFactoryProvider), classPostfix); var forge = new StatementAgentInstanceFactoryOnTriggerSetForge( activatorResult.Activator, eventType, subselectForges, tableAccessForges, variableReadWritePackageForge, classNameRSP); IList<StmtClassForgable> forgables = new List<StmtClassForgable>(); forgables.Add( new StmtClassForgableRSPFactoryProvider( classNameRSP, resultSetProcessor, namespaceScope, @base.StatementRawInfo)); var onTrigger = new StmtClassForgableAIFactoryProviderOnTrigger(className, namespaceScope, forge); return new OnTriggerSetPlan(onTrigger, forgables, resultSetProcessor.SelectSubscriberDescriptor); }