public ResultSetSpec( SelectClauseStreamSelectorEnum selectClauseStreamSelector, IList<OrderByItem> orderByList, SelectClauseSpecCompiled selectClauseSpec, InsertIntoDesc insertIntoDesc, GroupByClauseExpressions groupByClauseExpressions, ExprNode whereClause, ExprNode havingClause, OutputLimitSpec optionalOutputLimitSpec, RowLimitSpec rowLimitSpec, string contextName, ForClauseSpec forClauseSpec, IntoTableSpec intoTableSpec, StreamSpecCompiled[] streamSpecs, Attribute[] annotations) { this.SelectClauseStreamSelector = selectClauseStreamSelector; this.OrderByList = orderByList; this.SelectClauseSpec = selectClauseSpec; this.InsertIntoDesc = insertIntoDesc; this.GroupByClauseExpressions = groupByClauseExpressions; this.WhereClause = whereClause; this.HavingClause = havingClause; this.OptionalOutputLimitSpec = optionalOutputLimitSpec; this.RowLimitSpec = rowLimitSpec; this.ContextName = contextName; this.ForClauseSpec = forClauseSpec; this.IntoTableSpec = intoTableSpec; this.StreamSpecs = streamSpecs; this.Annotations = annotations; }
public StatementSpecCompiled( StatementSpecRaw raw, StreamSpecCompiled[] streamSpecs, SelectClauseSpecCompiled selectClauseCompiled, Attribute[] annotations, GroupByClauseExpressions groupByExpressions, IList<ExprSubselectNode> subselectNodes, IList<ExprDeclaredNode> exprDeclaredNodes, IList<ExprTableAccessNode> tableAccessNodes) { Raw = raw; StreamSpecs = streamSpecs; SelectClauseCompiled = selectClauseCompiled; Annotations = annotations; GroupByExpressions = groupByExpressions; SubselectNodes = subselectNodes; this.exprDeclaredNodes = exprDeclaredNodes; TableAccessNodes = tableAccessNodes; }
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) })); }
private static bool Grouped(GroupByClauseExpressions groupByExpressions) { return(groupByExpressions != null && groupByExpressions.GroupByNodes != null && groupByExpressions.GroupByNodes.Length != 0); }
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; }