public static string GetSubqueryInfoText(ExprSubselectNode subselect) { string text = "subquery number " + (subselect.SubselectNumber + 1); StreamSpecRaw streamRaw = subselect.StatementSpecRaw.StreamSpecs[0]; if (streamRaw is FilterStreamSpecRaw) { text += " querying " + ((FilterStreamSpecRaw) streamRaw).RawFilterSpec.EventTypeName; } return text; }
internal static bool DetermineStatelessSelect( StatementType type, StatementSpecRaw spec, bool hasSubselects) { if (hasSubselects) { return false; } if (type != StatementType.SELECT) { return false; } if (spec.StreamSpecs == null || spec.StreamSpecs.Count > 1 || spec.StreamSpecs.IsEmpty()) { return false; } StreamSpecRaw singleStream = spec.StreamSpecs[0]; if (!(singleStream is FilterStreamSpecRaw) && !(singleStream is NamedWindowConsumerStreamSpec)) { return false; } if (singleStream.ViewSpecs != null && singleStream.ViewSpecs.Length > 0) { return false; } if (spec.OutputLimitSpec != null) { return false; } if (spec.MatchRecognizeSpec != null) { return false; } IList<ExprNode> expressions = StatementSpecRawWalkerExpr.CollectExpressionsShallow(spec); if (expressions.IsEmpty()) { return true; } var visitor = new ExprNodeSummaryVisitor(); foreach (var expr in expressions) { if (expr == null) { continue; } expr.Accept(visitor); } return !visitor.HasAggregation && !visitor.HasPreviousPrior && !visitor.HasSubselect; }
public static StreamSpecCompiledDesc Compile( StreamSpecRaw spec, ISet<string> eventTypeReferences, bool isInsertInto, bool isJoin, bool isContextDeclaration, bool isOnTrigger, string optionalStreamName, int streamNum, StatementRawInfo statementRawInfo, StatementCompileTimeServices services) { if (spec is DBStatementStreamSpec dbStatementStreamSpec) { return new StreamSpecCompiledDesc(dbStatementStreamSpec, EmptyList<StmtClassForgeableFactory>.Instance); } if (spec is FilterStreamSpecRaw filterStreamSpecRaw) { return CompileFilter( filterStreamSpecRaw, isInsertInto, isJoin, isContextDeclaration, isOnTrigger, optionalStreamName, statementRawInfo, services); } if (spec is PatternStreamSpecRaw patternStreamSpecRaw) { return CompilePattern( patternStreamSpecRaw, eventTypeReferences, isInsertInto, isJoin, isContextDeclaration, isOnTrigger, optionalStreamName, streamNum, statementRawInfo, services); } if (spec is MethodStreamSpec methodStreamSpec) { return new StreamSpecCompiledDesc( CompileMethod(methodStreamSpec), EmptyList<StmtClassForgeableFactory>.Instance); } throw new IllegalStateException("Unrecognized stream spec " + spec); }
public static StreamSpecCompiled Compile( StreamSpecRaw spec, ISet<string> eventTypeReferences, bool isInsertInto, bool isJoin, bool isContextDeclaration, bool isOnTrigger, string optionalStreamName, int streamNum, StatementRawInfo statementRawInfo, StatementCompileTimeServices services) { if (spec is DBStatementStreamSpec) { return (DBStatementStreamSpec) spec; } if (spec is FilterStreamSpecRaw) { return CompileFilter( (FilterStreamSpecRaw) spec, isInsertInto, isJoin, isContextDeclaration, isOnTrigger, optionalStreamName, statementRawInfo, services); } if (spec is PatternStreamSpecRaw) { return CompilePattern( (PatternStreamSpecRaw) spec, eventTypeReferences, isInsertInto, isJoin, isContextDeclaration, isOnTrigger, optionalStreamName, streamNum, statementRawInfo, services); } if (spec is MethodStreamSpec) { return CompileMethod((MethodStreamSpec) spec); } throw new IllegalStateException("Unrecognized stream spec " + spec); }
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; }