private static void AddFilters(StreamSpecCompiled[] streams, IList <FilterSpecCompiled> filters, IList <NamedWindowConsumerStreamSpec> namedWindows) { foreach (StreamSpecCompiled compiled in streams) { if (compiled is FilterStreamSpecCompiled) { FilterStreamSpecCompiled c = (FilterStreamSpecCompiled)compiled; filters.Add(c.FilterSpec); } if (compiled is PatternStreamSpecCompiled) { PatternStreamSpecCompiled r = (PatternStreamSpecCompiled)compiled; EvalNodeAnalysisResult evalNodeAnalysisResult = EvalNodeUtil.RecursiveAnalyzeChildNodes((r.EvalFactoryNode)); IList <EvalFilterFactoryNode> filterNodes = evalNodeAnalysisResult.FilterNodes; foreach (EvalFilterFactoryNode filterNode in filterNodes) { filters.Add(filterNode.FilterSpec); } } if (compiled is NamedWindowConsumerStreamSpec) { namedWindows.Add((NamedWindowConsumerStreamSpec)compiled); } } }
public ViewableActivator CreateStreamReuseView( EPServicesContext services, StatementContext statementContext, StatementSpecCompiled statementSpec, FilterStreamSpecCompiled filterStreamSpec, bool isJoin, ExprEvaluatorContextStatement evaluatorContextStmt, bool filterSubselectSameStream, int streamNum, bool isCanIterateUnbound) { if (ProcCreateStreamReuseView == null) { throw new NotSupportedException(); } return(ProcCreateStreamReuseView.Invoke( services, statementContext, statementSpec, filterStreamSpec, isJoin, evaluatorContextStmt, filterSubselectSameStream, streamNum, isCanIterateUnbound)); }
private OnTriggerActivatorDesc ActivatorFilter( FilterStreamSpecCompiled filterStreamSpec, StatementCompileTimeServices services) { var triggerEventTypeName = filterStreamSpec.FilterSpecCompiled.FilterForEventTypeName; var activator = new ViewableActivatorFilterForge(filterStreamSpec.FilterSpecCompiled, false, 0, false, -1); var activatorResultEventType = filterStreamSpec.FilterSpecCompiled.ResultEventType; return new OnTriggerActivatorDesc(activator, triggerEventTypeName, activatorResultEventType); }
public ViewableActivator CreateActivatorSimple( FilterStreamSpecCompiled filterStreamSpec) { if (ProcCreateActivatorSimple == null) { throw new NotSupportedException(); } return(ProcCreateActivatorSimple.Invoke( filterStreamSpec)); }
internal ViewableActivatorStreamReuseView(EPServicesContext services, StatementContext statementContext, StatementSpecCompiled statementSpec, FilterStreamSpecCompiled filterStreamSpec, bool join, ExprEvaluatorContextStatement evaluatorContextStmt, bool filterSubselectSameStream, int streamNum, bool isCanIterateUnbound) { _services = services; _statementContext = statementContext; _statementSpec = statementSpec; _filterStreamSpec = filterStreamSpec; _join = join; _evaluatorContextStmt = evaluatorContextStmt; _filterSubselectSameStream = filterSubselectSameStream; _streamNum = streamNum; _isCanIterateUnbound = isCanIterateUnbound; }
internal static bool DetermineSubquerySameStream(StatementSpecCompiled statementSpec, FilterStreamSpecCompiled filterStreamSpec) { foreach (ExprSubselectNode subselect in statementSpec.SubSelectExpressions) { StreamSpecCompiled streamSpec = subselect.StatementSpecCompiled.StreamSpecs[0]; if (!(streamSpec is FilterStreamSpecCompiled)) { continue; } FilterStreamSpecCompiled filterStream = (FilterStreamSpecCompiled)streamSpec; EventType typeSubselect = filterStream.FilterSpec.FilterForEventType; EventType typeFiltered = filterStreamSpec.FilterSpec.FilterForEventType; if (EventTypeUtility.IsTypeOrSubTypeOf(typeSubselect, typeFiltered) || EventTypeUtility.IsTypeOrSubTypeOf(typeFiltered, typeSubselect)) { return(true); } } return(false); }
public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext context) { if (context.InputPorts.IsEmpty()) { throw new ArgumentException("Select operator requires at least one input stream"); } if (context.OutputPorts.Count != 1) { throw new ArgumentException("Select operator requires one output stream but produces " + context.OutputPorts.Count + " streams"); } DataFlowOpOutputPort portZero = context.OutputPorts[0]; if (portZero.OptionalDeclaredType != null && !portZero.OptionalDeclaredType.IsUnderlying) { _submitEventBean = true; } // determine adapter factories for each type int numStreams = context.InputPorts.Count; _adapterFactories = new EventBeanAdapterFactory[numStreams]; for (int i = 0; i < numStreams; i++) { EventType eventType = context.InputPorts.Get(i).TypeDesc.EventType; _adapterFactories[i] = context.StatementContext.EventAdapterService.GetAdapterFactoryForType(eventType); } // Compile and prepare execution // StatementContext statementContext = context.StatementContext; EPServicesContext servicesContext = context.ServicesContext; AgentInstanceContext agentInstanceContext = context.AgentInstanceContext; // validate if (select.InsertIntoDesc != null) { throw new ExprValidationException("Insert-into clause is not supported"); } if (select.SelectStreamSelectorEnum != SelectClauseStreamSelectorEnum.ISTREAM_ONLY) { throw new ExprValidationException("Selecting remove-stream is not supported"); } ExprNodeSubselectDeclaredDotVisitor visitor = StatementSpecRawAnalyzer.WalkSubselectAndDeclaredDotExpr(select); GroupByClauseExpressions groupByExpressions = GroupByExpressionHelper.GetGroupByRollupExpressions( servicesContext.Container, select.GroupByExpressions, select.SelectClauseSpec, select.HavingExprRootNode, select.OrderByList, visitor); if (!visitor.Subselects.IsEmpty()) { throw new ExprValidationException("Subselects are not supported"); } IDictionary <int, FilterStreamSpecRaw> streams = new Dictionary <int, FilterStreamSpecRaw>(); for (int streamNum = 0; streamNum < select.StreamSpecs.Count; streamNum++) { var rawStreamSpec = select.StreamSpecs[streamNum]; if (!(rawStreamSpec is FilterStreamSpecRaw)) { throw new ExprValidationException("From-clause must contain only streams and cannot contain patterns or other constructs"); } streams.Put(streamNum, (FilterStreamSpecRaw)rawStreamSpec); } // compile offered streams IList <StreamSpecCompiled> streamSpecCompileds = new List <StreamSpecCompiled>(); for (int streamNum = 0; streamNum < select.StreamSpecs.Count; streamNum++) { var filter = streams.Get(streamNum); var inputPort = FindInputPort(filter.RawFilterSpec.EventTypeName, context.InputPorts); if (inputPort == null) { throw new ExprValidationException( string.Format("Failed to find stream '{0}' among input ports, input ports are {1}", filter.RawFilterSpec.EventTypeName, GetInputPortNames(context.InputPorts).Render(", ", "[]"))); } var eventType = inputPort.Value.Value.TypeDesc.EventType; var streamAlias = filter.OptionalStreamName; var filterSpecCompiled = new FilterSpecCompiled(eventType, streamAlias, new IList <FilterSpecParam>[] { Collections.GetEmptyList <FilterSpecParam>() }, null); var filterStreamSpecCompiled = new FilterStreamSpecCompiled(filterSpecCompiled, select.StreamSpecs[0].ViewSpecs, streamAlias, StreamSpecOptions.DEFAULT); streamSpecCompileds.Add(filterStreamSpecCompiled); } // create compiled statement spec SelectClauseSpecCompiled selectClauseCompiled = StatementLifecycleSvcUtil.CompileSelectClause(select.SelectClauseSpec); // determine if snapshot output is needed OutputLimitSpec outputLimitSpec = select.OutputLimitSpec; _isOutputLimited = outputLimitSpec != null; if (iterate) { if (outputLimitSpec != null) { throw new ExprValidationException("Output rate limiting is not supported with 'iterate'"); } outputLimitSpec = new OutputLimitSpec(OutputLimitLimitType.SNAPSHOT, OutputLimitRateType.TERM); } var mergedAnnotations = AnnotationUtil.MergeAnnotations(statementContext.Annotations, context.OperatorAnnotations); var orderByArray = OrderByItem.ToArray(select.OrderByList); var outerJoinArray = OuterJoinDesc.ToArray(select.OuterJoinDescList); var streamSpecArray = streamSpecCompileds.ToArray(); var compiled = new StatementSpecCompiled(null, null, null, null, null, null, null, SelectClauseStreamSelectorEnum.ISTREAM_ONLY, selectClauseCompiled, streamSpecArray, outerJoinArray, select.FilterExprRootNode, select.HavingExprRootNode, outputLimitSpec, orderByArray, ExprSubselectNode.EMPTY_SUBSELECT_ARRAY, ExprNodeUtility.EMPTY_DECLARED_ARR, ExprNodeUtility.EMPTY_SCRIPTS, select.ReferencedVariables, select.RowLimitSpec, CollectionUtil.EMPTY_STRING_ARRAY, mergedAnnotations, null, null, null, null, null, null, null, null, null, groupByExpressions, null, null); // create viewable per port var viewables = new EPLSelectViewable[context.InputPorts.Count]; _viewablesPerPort = viewables; foreach (var entry in context.InputPorts) { EPLSelectViewable viewable = new EPLSelectViewable(entry.Value.TypeDesc.EventType); viewables[entry.Key] = viewable; } var activatorFactory = new ProxyViewableActivatorFactory { ProcCreateActivatorSimple = filterStreamSpec => { EPLSelectViewable found = null; foreach (EPLSelectViewable sviewable in viewables) { if (sviewable.EventType == filterStreamSpec.FilterSpec.FilterForEventType) { found = sviewable; } } if (found == null) { throw new IllegalStateException("Failed to find viewable for filter"); } EPLSelectViewable viewable = found; return(new ProxyViewableActivator( (agentInstanceContext2, isSubselect, isRecoveringResilient) => new ViewableActivationResult( viewable, new ProxyStopCallback(() => { }), null, null, null, false, false, null))); } }; // for per-row deliver, register select expression result callback OutputProcessViewCallback optionalOutputProcessViewCallback = null; if (!iterate && !_isOutputLimited) { _deliveryCallback = new EPLSelectDeliveryCallback(); optionalOutputProcessViewCallback = this; } // prepare EPStatementStartMethodSelectDesc selectDesc = EPStatementStartMethodSelectUtil.Prepare(compiled, servicesContext, statementContext, false, agentInstanceContext, false, activatorFactory, optionalOutputProcessViewCallback, _deliveryCallback); // start _selectResult = (StatementAgentInstanceFactorySelectResult)selectDesc.StatementAgentInstanceFactorySelect.NewContext(agentInstanceContext, false); // for output-rate-limited, register a dispatch view if (_isOutputLimited) { _selectResult.FinalView.AddView(new EPLSelectUpdateDispatchView(this)); } // assign strategies to expression nodes EPStatementStartMethodHelperAssignExpr.AssignExpressionStrategies( selectDesc, _selectResult.OptionalAggegationService, _selectResult.SubselectStrategies, _selectResult.PriorNodeStrategies, _selectResult.PreviousNodeStrategies, null, null, _selectResult.TableAccessEvalStrategies); EventType outputEventType = selectDesc.ResultSetProcessorPrototypeDesc.ResultSetProcessorFactory.ResultEventType; _agentInstanceContext = agentInstanceContext; return(new DataFlowOpInitializeResult(new GraphTypeDesc[] { new GraphTypeDesc(false, true, outputEventType) })); }
public ViewableActivator CreateStreamReuseView(EPServicesContext services, StatementContext statementContext, StatementSpecCompiled statementSpec, FilterStreamSpecCompiled filterStreamSpec, bool isJoin, ExprEvaluatorContextStatement evaluatorContextStmt, bool filterSubselectSameStream, int streamNum, bool isCanIterateUnbound) { return(new ViewableActivatorStreamReuseView(services, statementContext, statementSpec, filterStreamSpec, isJoin, evaluatorContextStmt, filterSubselectSameStream, streamNum, isCanIterateUnbound)); }
public ViewableActivator CreateActivatorSimple(FilterStreamSpecCompiled filterStreamSpec) { throw new UnsupportedOperationException(); }
public DataFlowOpForgeInitializeResult InitializeForge(DataFlowOpForgeInitializeContext context) { if (context.InputPorts.IsEmpty()) { throw new ArgumentException("Select operator requires at least one input stream"); } if (context.OutputPorts.Count != 1) { throw new ArgumentException( "Select operator requires one output stream but produces " + context.OutputPorts.Count + " streams"); } var portZero = context.OutputPorts[0]; if (portZero.OptionalDeclaredType != null && !portZero.OptionalDeclaredType.IsUnderlying) { submitEventBean = true; } // determine adapter factories for each type var numStreams = context.InputPorts.Count; eventTypes = new EventType[numStreams]; for (var i = 0; i < numStreams; i++) { eventTypes[i] = context.InputPorts.Get(i).TypeDesc.EventType; } // validate if (select.InsertIntoDesc != null) { throw new ExprValidationException("Insert-into clause is not supported"); } if (select.SelectStreamSelectorEnum != SelectClauseStreamSelectorEnum.ISTREAM_ONLY) { throw new ExprValidationException("Selecting remove-stream is not supported"); } ExprNodeSubselectDeclaredDotVisitor visitor = StatementSpecRawWalkerSubselectAndDeclaredDot.WalkSubselectAndDeclaredDotExpr(select); GroupByClauseExpressions groupByExpressions = GroupByExpressionHelper.GetGroupByRollupExpressions( select.GroupByExpressions, select.SelectClauseSpec, select.WhereClause, select.OrderByList, null); if (!visitor.Subselects.IsEmpty()) { throw new ExprValidationException("Subselects are not supported"); } IDictionary<int, FilterStreamSpecRaw> streams = new Dictionary<int, FilterStreamSpecRaw>(); for (var streamNum = 0; streamNum < select.StreamSpecs.Count; streamNum++) { StreamSpecRaw rawStreamSpec = select.StreamSpecs[streamNum]; if (!(rawStreamSpec is FilterStreamSpecRaw)) { throw new ExprValidationException( "From-clause must contain only streams and cannot contain patterns or other constructs"); } streams.Put(streamNum, (FilterStreamSpecRaw) rawStreamSpec); } // compile offered streams IList<StreamSpecCompiled> streamSpecCompileds = new List<StreamSpecCompiled>(); originatingStreamToViewableStream = new int[select.StreamSpecs.Count]; for (var streamNum = 0; streamNum < select.StreamSpecs.Count; streamNum++) { var filter = streams.Get(streamNum); var inputPort = FindInputPort(filter.RawFilterSpec.EventTypeName, context.InputPorts); if (inputPort == null) { throw new ExprValidationException( "Failed to find stream '" + filter.RawFilterSpec.EventTypeName + "' among input ports, input ports are " + CompatExtensions.RenderAny(GetInputPortNames(context.InputPorts))); } var inputPortValue = inputPort.Value; var eventType = inputPortValue.Value.TypeDesc.EventType; originatingStreamToViewableStream[inputPortValue.Key] = streamNum; var streamAlias = filter.OptionalStreamName; var filterSpecCompiled = new FilterSpecCompiled( eventType, streamAlias, new IList<FilterSpecParamForge>[] { new EmptyList<FilterSpecParamForge>() }, null); ViewSpec[] viewSpecs = select.StreamSpecs[streamNum].ViewSpecs; var filterStreamSpecCompiled = new FilterStreamSpecCompiled( filterSpecCompiled, viewSpecs, streamAlias, StreamSpecOptions.DEFAULT); streamSpecCompileds.Add(filterStreamSpecCompiled); } // create compiled statement spec var selectClauseCompiled = StatementLifecycleSvcUtil.CompileSelectClause(select.SelectClauseSpec); Attribute[] mergedAnnotations = AnnotationUtil.MergeAnnotations( context.StatementRawInfo.Annotations, context.OperatorAnnotations); mergedAnnotations = AddObjectArrayRepresentation(mergedAnnotations); var streamSpecArray = streamSpecCompileds.ToArray(); // determine if snapshot output is needed var outputLimitSpec = select.OutputLimitSpec; if (iterate) { if (outputLimitSpec != null) { throw new ExprValidationException("Output rate limiting is not supported with 'iterate'"); } outputLimitSpec = new OutputLimitSpec(OutputLimitLimitType.SNAPSHOT, OutputLimitRateType.TERM); select.OutputLimitSpec = outputLimitSpec; } // override the statement spec var compiled = new StatementSpecCompiled( select, streamSpecArray, selectClauseCompiled, mergedAnnotations, groupByExpressions, new EmptyList<ExprSubselectNode>(), new EmptyList<ExprDeclaredNode>(), new EmptyList<ExprTableAccessNode>()); var dataflowClassPostfix = context.CodegenEnv.ClassPostfix + "__dfo" + context.OperatorNumber; var containerStatement = context.Base.StatementSpec; context.Base.StatementSpec = compiled; // make forgable var forablesResult = StmtForgeMethodSelectUtil.Make( context.Container, true, context.CodegenEnv.Namespace, dataflowClassPostfix, context.Base, context.Services); // return the statement spec context.Base.StatementSpec = containerStatement; EventType outputEventType = forablesResult.EventType; var initializeResult = new DataFlowOpForgeInitializeResult(); initializeResult.TypeDescriptors = new[] {new GraphTypeDesc(false, true, outputEventType)}; initializeResult.AdditionalForgables = forablesResult.ForgeResult; foreach (StmtClassForgable forgable in forablesResult.ForgeResult.Forgables) { if (forgable.ForgableType == StmtClassForgableType.AIFACTORYPROVIDER) { classNameAIFactoryProvider = forgable.ClassName; } else if (forgable.ForgableType == StmtClassForgableType.FIELDS) { classNameFieldsFactoryProvider = forgable.ClassName; } } return initializeResult; }
public static SubSelectActivationDesc CreateSubSelectActivation( IList <FilterSpecCompiled> filterSpecCompileds, IList <NamedWindowConsumerStreamSpec> namedWindowConsumers, StatementBaseInfo statement, StatementCompileTimeServices services) { IDictionary <ExprSubselectNode, SubSelectActivationPlan> result = new LinkedHashMap <ExprSubselectNode, SubSelectActivationPlan>(); IList <StmtClassForgeableFactory> additionalForgeables = new List <StmtClassForgeableFactory>(); // Process all subselect expression nodes foreach (ExprSubselectNode subselect in statement.StatementSpec.SubselectNodes) { StatementSpecCompiled statementSpec = subselect.StatementSpecCompiled; StreamSpecCompiled streamSpec = statementSpec.StreamSpecs[0]; int subqueryNumber = subselect.SubselectNumber; if (subqueryNumber == -1) { throw new IllegalStateException("Unexpected subquery"); } ViewFactoryForgeArgs args = new ViewFactoryForgeArgs(-1, true, subqueryNumber, streamSpec.Options, null, statement.StatementRawInfo, services); if (streamSpec is FilterStreamSpecCompiled) { if (services.IsFireAndForget) { throw new ExprValidationException("Fire-and-forget queries only allow subqueries against named windows and tables"); } FilterStreamSpecCompiled filterStreamSpec = (FilterStreamSpecCompiled)statementSpec.StreamSpecs[0]; // Register filter, create view factories ViewableActivatorForge activatorDeactivator = new ViewableActivatorFilterForge( filterStreamSpec.FilterSpecCompiled, false, null, true, subqueryNumber); ViewFactoryForgeDesc viewForgeDesc = ViewFactoryForgeUtil.CreateForges( streamSpec.ViewSpecs, args, filterStreamSpec.FilterSpecCompiled.ResultEventType); IList <ViewFactoryForge> forges = viewForgeDesc.Forges; additionalForgeables.AddAll(viewForgeDesc.MultikeyForges); EventType eventType = forges.IsEmpty() ? filterStreamSpec.FilterSpecCompiled.ResultEventType : forges[forges.Count - 1].EventType; subselect.RawEventType = eventType; filterSpecCompileds.Add(filterStreamSpec.FilterSpecCompiled); // Add lookup to list, for later starts result.Put( subselect, new SubSelectActivationPlan(filterStreamSpec.FilterSpecCompiled.ResultEventType, forges, activatorDeactivator, streamSpec)); } else if (streamSpec is TableQueryStreamSpec) { TableQueryStreamSpec table = (TableQueryStreamSpec)streamSpec; ExprNode filter = ExprNodeUtilityMake.ConnectExpressionsByLogicalAndWhenNeeded(table.FilterExpressions); ViewableActivatorForge viewableActivator = new ViewableActivatorTableForge(table.Table, filter); result.Put( subselect, new SubSelectActivationPlan(table.Table.InternalEventType, EmptyList <ViewFactoryForge> .Instance, viewableActivator, streamSpec)); subselect.RawEventType = table.Table.InternalEventType; } else { NamedWindowConsumerStreamSpec namedSpec = (NamedWindowConsumerStreamSpec)statementSpec.StreamSpecs[0]; namedWindowConsumers.Add(namedSpec); NamedWindowMetaData nwinfo = namedSpec.NamedWindow; EventType namedWindowType = nwinfo.EventType; if (namedSpec.OptPropertyEvaluator != null) { namedWindowType = namedSpec.OptPropertyEvaluator.FragmentEventType; } // if named-window index sharing is disabled (the default) or filter expressions are provided then consume the insert-remove stream bool disableIndexShare = HintEnum.DISABLE_WINDOW_SUBQUERY_INDEXSHARE.GetHint(statement.StatementRawInfo.Annotations) != null; bool processorDisableIndexShare = !namedSpec.NamedWindow.IsEnableIndexShare; if (disableIndexShare && namedSpec.NamedWindow.IsVirtualDataWindow) { disableIndexShare = false; } if ((!namedSpec.FilterExpressions.IsEmpty() || processorDisableIndexShare || disableIndexShare) && (!services.IsFireAndForget)) { ExprNode filterEvaluator = null; if (!namedSpec.FilterExpressions.IsEmpty()) { filterEvaluator = ExprNodeUtilityMake.ConnectExpressionsByLogicalAndWhenNeeded(namedSpec.FilterExpressions); } ViewableActivatorForge activatorNamedWindow = new ViewableActivatorNamedWindowForge( namedSpec, nwinfo, filterEvaluator, null, true, namedSpec.OptPropertyEvaluator); ViewFactoryForgeDesc viewForgeDesc = ViewFactoryForgeUtil.CreateForges(streamSpec.ViewSpecs, args, namedWindowType); IList <ViewFactoryForge> forges = viewForgeDesc.Forges; additionalForgeables.AddAll(viewForgeDesc.MultikeyForges); subselect.RawEventType = forges.IsEmpty() ? namedWindowType : forges[forges.Count - 1].EventType; result.Put(subselect, new SubSelectActivationPlan(namedWindowType, forges, activatorNamedWindow, streamSpec)); } else { // else if there are no named window stream filter expressions and index sharing is enabled ViewFactoryForgeDesc viewForgeDesc = ViewFactoryForgeUtil.CreateForges(streamSpec.ViewSpecs, args, namedWindowType); IList <ViewFactoryForge> forges = viewForgeDesc.Forges; additionalForgeables.AddAll(viewForgeDesc.MultikeyForges); subselect.RawEventType = namedWindowType; ViewableActivatorForge activatorNamedWindow = new ViewableActivatorSubselectNoneForge(namedWindowType); result.Put(subselect, new SubSelectActivationPlan(namedWindowType, forges, activatorNamedWindow, streamSpec)); } } } return(new SubSelectActivationDesc(result, additionalForgeables)); }