/// <summary> /// Ctor. /// </summary> /// <param name="selectExprProcessor">for processing the select expression and generting the readonly output rows</param> /// <param name="groupKeyNodeExpressions">The group key node expressions.</param> /// <param name="groupKeyNodes">list of group-by expression nodes needed for building the group-by keys</param> /// <param name="optionalHavingNode">expression node representing validated HAVING clause, or null if none given.Aggregation functions in the having node must have been pointed to the AggregationService for evaluation.</param> /// <param name="isSelectRStream">true if remove stream events should be generated</param> /// <param name="isUnidirectional">true if unidirectional join</param> /// <param name="outputLimitSpec">The output limit spec.</param> /// <param name="isSorting">if set to <c>true</c> [is sorting].</param> /// <param name="isHistoricalOnly">if set to <c>true</c> [is historical only].</param> /// <param name="resultSetProcessorHelperFactory">The result set processor helper factory.</param> /// <param name="optionalOutputFirstConditionFactory">The optional output first condition factory.</param> /// <param name="enableOutputLimitOpt">if set to <c>true</c> [enable output limit opt].</param> /// <param name="numStreams">The number streams.</param> public ResultSetProcessorAggregateGroupedFactory( SelectExprProcessor selectExprProcessor, ExprNode[] groupKeyNodeExpressions, ExprEvaluator[] groupKeyNodes, ExprEvaluator optionalHavingNode, bool isSelectRStream, bool isUnidirectional, OutputLimitSpec outputLimitSpec, bool isSorting, bool isHistoricalOnly, ResultSetProcessorHelperFactory resultSetProcessorHelperFactory, OutputConditionPolledFactory optionalOutputFirstConditionFactory, bool enableOutputLimitOpt, int numStreams) { _selectExprProcessor = selectExprProcessor; GroupKeyNodeExpressions = groupKeyNodeExpressions; GroupKeyNode = groupKeyNodes.Length == 1 ? groupKeyNodes[0] : null; GroupKeyNodes = groupKeyNodes; OptionalHavingNode = optionalHavingNode; IsSorting = isSorting; IsSelectRStream = isSelectRStream; IsUnidirectional = isUnidirectional; IsHistoricalOnly = isHistoricalOnly; OutputLimitSpec = outputLimitSpec; ResultSetProcessorHelperFactory = resultSetProcessorHelperFactory; OptionalOutputFirstConditionFactory = optionalOutputFirstConditionFactory; IsEnableOutputLimitOpt = enableOutputLimitOpt; NumStreams = numStreams; }
public ResultSetProcessorAggregateGroupedForge( EventType resultEventType, ExprNode[] groupKeyNodeExpressions, ExprForge optionalHavingNode, bool isSelectRStream, bool isUnidirectional, OutputLimitSpec outputLimitSpec, bool isSorting, bool isHistoricalOnly, ResultSetProcessorOutputConditionType? outputConditionType, OutputConditionPolledFactoryForge optionalOutputFirstConditionFactory, EventType[] eventTypes, MultiKeyClassRef multiKeyClassRef) { ResultEventType = resultEventType; GroupKeyNodeExpressions = groupKeyNodeExpressions; OptionalHavingNode = optionalHavingNode; IsSorting = isSorting; IsSelectRStream = isSelectRStream; IsUnidirectional = isUnidirectional; OutputLimitSpec = outputLimitSpec; IsHistoricalOnly = isHistoricalOnly; OutputConditionType = outputConditionType; OptionalOutputFirstConditionFactory = optionalOutputFirstConditionFactory; EventTypes = eventTypes; GroupKeyTypes = ExprNodeUtilityQuery.GetExprResultTypes(groupKeyNodeExpressions); MultiKeyClassRef = multiKeyClassRef; }
/// <summary> /// Ctor. /// </summary> /// <param name="selectExprProcessor">for processing the select expression and generting the final output rows</param> /// <param name="groupKeyNodeExpressions">The group key node expressions.</param> /// <param name="groupKeyNodes">list of group-by expression nodes needed for building the group-by keys</param> /// <param name="optionalHavingNode">expression node representing validated HAVING clause, or null if none given.Aggregation functions in the having node must have been pointed to the AggregationService for evaluation.</param> /// <param name="isSelectRStream">true if remove stream events should be generated</param> /// <param name="isUnidirectional">true if unidirectional join</param> /// <param name="outputLimitSpec">The output limit spec.</param> /// <param name="isSorting">if set to <c>true</c> [is sorting].</param> /// <param name="noDataWindowSingleStream">if set to <c>true</c> [no data window single stream].</param> /// <param name="isHistoricalOnly">if set to <c>true</c> [is historical only].</param> /// <param name="iterateUnbounded">if set to <c>true</c> [iterate unbounded].</param> /// <param name="resultSetProcessorHelperFactory">The result set processor helper factory.</param> /// <param name="enableOutputLimitOpt">if set to <c>true</c> [enable output limit opt].</param> /// <param name="numStreams">The number streams.</param> /// <param name="optionalOutputFirstConditionFactory">The optional output first condition factory.</param> public ResultSetProcessorRowPerGroupFactory( SelectExprProcessor selectExprProcessor, ExprNode[] groupKeyNodeExpressions, ExprEvaluator[] groupKeyNodes, ExprEvaluator optionalHavingNode, bool isSelectRStream, bool isUnidirectional, OutputLimitSpec outputLimitSpec, bool isSorting, bool noDataWindowSingleStream, bool isHistoricalOnly, bool iterateUnbounded, ResultSetProcessorHelperFactory resultSetProcessorHelperFactory, bool enableOutputLimitOpt, int numStreams, OutputConditionPolledFactory optionalOutputFirstConditionFactory) { _groupKeyNodeExpressions = groupKeyNodeExpressions; _selectExprProcessor = selectExprProcessor; _groupKeyNodes = groupKeyNodes; _groupKeyNode = groupKeyNodes.Length == 1 ? groupKeyNodes[0] : null; _optionalHavingNode = optionalHavingNode; _isSorting = isSorting; _isSelectRStream = isSelectRStream; _isUnidirectional = isUnidirectional; _outputLimitSpec = outputLimitSpec; _noDataWindowSingleSnapshot = iterateUnbounded || (outputLimitSpec != null && outputLimitSpec.DisplayLimit == OutputLimitLimitType.SNAPSHOT && noDataWindowSingleStream); _isHistoricalOnly = isHistoricalOnly; ResultSetProcessorHelperFactory = resultSetProcessorHelperFactory; IsEnableOutputLimitOpt = enableOutputLimitOpt; NumStreams = numStreams; OptionalOutputFirstConditionFactory = optionalOutputFirstConditionFactory; }
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; }
/// <summary> /// Ctor. /// </summary> /// <param name="perLevelExpression">The per level expression.</param> /// <param name="groupKeyNodeExpressions">The group key node expressions.</param> /// <param name="groupKeyNodes">list of group-by expression nodes needed for building the group-by keysAggregation functions in the having node must have been pointed to the AggregationService for evaluation.</param> /// <param name="isSelectRStream">true if remove stream events should be generated</param> /// <param name="isUnidirectional">true if unidirectional join</param> /// <param name="outputLimitSpec">The output limit spec.</param> /// <param name="isSorting">if set to <c>true</c> [is sorting].</param> /// <param name="noDataWindowSingleStream">if set to <c>true</c> [no data window single stream].</param> /// <param name="groupByRollupDesc">The group by rollup desc.</param> /// <param name="isJoin">if set to <c>true</c> [is join].</param> /// <param name="isHistoricalOnly">if set to <c>true</c> [is historical only].</param> public ResultSetProcessorRowPerGroupRollupFactory( GroupByRollupPerLevelExpression perLevelExpression, ExprNode[] groupKeyNodeExpressions, ExprEvaluator[] groupKeyNodes, bool isSelectRStream, bool isUnidirectional, OutputLimitSpec outputLimitSpec, bool isSorting, bool noDataWindowSingleStream, AggregationGroupByRollupDesc groupByRollupDesc, bool isJoin, bool isHistoricalOnly, bool iterateUnbounded) { GroupKeyNodeExpressions = groupKeyNodeExpressions; PerLevelExpression = perLevelExpression; GroupKeyNodes = groupKeyNodes; GroupKeyNode = groupKeyNodes.Length == 1 ? groupKeyNodes[0] : null; IsSorting = isSorting; IsSelectRStream = isSelectRStream; IsUnidirectional = isUnidirectional; OutputLimitSpec = outputLimitSpec; _noDataWindowSingleSnapshot = iterateUnbounded || (outputLimitSpec != null && outputLimitSpec.DisplayLimit == OutputLimitLimitType.SNAPSHOT && noDataWindowSingleStream); GroupByRollupDesc = groupByRollupDesc; IsJoin = isJoin; IsHistoricalOnly = isHistoricalOnly; }
/// <summary> /// Ctor. /// </summary> /// <param name="selectExprProcessor">for processing the select expression and generting the final output rows</param> /// <param name="groupKeyNodeExpressions">The group key node expressions.</param> /// <param name="groupKeyNodes">list of group-by expression nodes needed for building the group-by keys</param> /// <param name="optionalHavingNode">expression node representing validated HAVING clause, or null if none given.Aggregation functions in the having node must have been pointed to the AggregationService for evaluation.</param> /// <param name="isSelectRStream">true if remove stream events should be generated</param> /// <param name="isUnidirectional">true if unidirectional join</param> /// <param name="outputLimitSpec">The output limit spec.</param> /// <param name="isSorting">if set to <c>true</c> [is sorting].</param> /// <param name="noDataWindowSingleStream">if set to <c>true</c> [no data window single stream].</param> /// <param name="isHistoricalOnly">if set to <c>true</c> [is historical only].</param> public ResultSetProcessorRowPerGroupFactory( SelectExprProcessor selectExprProcessor, ExprNode[] groupKeyNodeExpressions, ExprEvaluator[] groupKeyNodes, ExprEvaluator optionalHavingNode, bool isSelectRStream, bool isUnidirectional, OutputLimitSpec outputLimitSpec, bool isSorting, bool noDataWindowSingleStream, bool isHistoricalOnly, bool iterateUnbounded) { _groupKeyNodeExpressions = groupKeyNodeExpressions; _selectExprProcessor = selectExprProcessor; _groupKeyNodes = groupKeyNodes; _groupKeyNode = groupKeyNodes.Length == 1 ? groupKeyNodes[0] : null; _optionalHavingNode = optionalHavingNode; _isSorting = isSorting; _isSelectRStream = isSelectRStream; _isUnidirectional = isUnidirectional; _outputLimitSpec = outputLimitSpec; _noDataWindowSingleSnapshot = iterateUnbounded || (outputLimitSpec != null && outputLimitSpec.DisplayLimit == OutputLimitLimitType.SNAPSHOT && noDataWindowSingleStream); _isHistoricalOnly = isHistoricalOnly; }
public ResultSetProcessorRowPerGroupForge( EventType resultEventType, EventType[] typesPerStream, ExprNode[] groupKeyNodeExpressions, ExprForge optionalHavingNode, bool isSelectRStream, bool isUnidirectional, OutputLimitSpec outputLimitSpec, bool isSorting, bool isHistoricalOnly, ResultSetProcessorOutputConditionType? outputConditionType, EventType[] eventTypes, OutputConditionPolledFactoryForge optionalOutputFirstConditionFactory, MultiKeyClassRef multiKeyClassRef, bool unboundedProcessor) { ResultEventType = resultEventType; this.typesPerStream = typesPerStream; GroupKeyNodeExpressions = groupKeyNodeExpressions; OptionalHavingNode = optionalHavingNode; IsSorting = isSorting; IsSelectRStream = isSelectRStream; IsUnidirectional = isUnidirectional; OutputLimitSpec = outputLimitSpec; IsHistoricalOnly = isHistoricalOnly; OutputConditionType = outputConditionType; EventTypes = eventTypes; OptionalOutputFirstConditionFactory = optionalOutputFirstConditionFactory; groupKeyTypes = ExprNodeUtilityQuery.GetExprResultTypes(groupKeyNodeExpressions); this.multiKeyClassRef = multiKeyClassRef; this.unboundedProcessor = unboundedProcessor; }
/// <summary>Ctor. </summary> /// <param name="selectExprProcessor">for processing the select expression and generting the readonly output rows</param> /// <param name="optionalHavingNode">having clause expression node</param> /// <param name="isSelectRStream">true if remove stream events should be generated</param> public ResultSetProcessorSimpleFactory( SelectExprProcessor selectExprProcessor, ExprEvaluator optionalHavingNode, bool isSelectRStream, OutputLimitSpec outputLimitSpec) { _selectExprProcessor = selectExprProcessor; _optionalHavingExpr = optionalHavingNode; _isSelectRStream = isSelectRStream; _outputLimitSpec = outputLimitSpec; }
public static OutputConditionPolledFactoryForge CreateConditionFactory( OutputLimitSpec outputLimitSpec, StatementRawInfo statementRawInfo, StatementCompileTimeServices compileTimeServices) { if (outputLimitSpec == null) { throw new ArgumentNullException("Output condition requires a non-null callback"); } // check variable use VariableMetaData variableMetaData = null; if (outputLimitSpec.VariableName != null) { variableMetaData = compileTimeServices.VariableCompileTimeResolver.Resolve(outputLimitSpec.VariableName); if (variableMetaData == null) { throw new ArgumentException( "Variable named '" + outputLimitSpec.VariableName + "' has not been declared"); } } if (outputLimitSpec.RateType == OutputLimitRateType.CRONTAB) { return new OutputConditionPolledCrontabFactoryForge( outputLimitSpec.CrontabAtSchedule, statementRawInfo, compileTimeServices); } if (outputLimitSpec.RateType == OutputLimitRateType.WHEN_EXPRESSION) { return new OutputConditionPolledExpressionFactoryForge( outputLimitSpec.WhenExpressionNode, outputLimitSpec.ThenExpressions, statementRawInfo.StatementName, compileTimeServices); } if (outputLimitSpec.RateType == OutputLimitRateType.EVENTS) { var rate = -1; if (outputLimitSpec.Rate != null) { rate = outputLimitSpec.Rate.AsInt32(); } return new OutputConditionPolledCountFactoryForge(rate, variableMetaData); } if (variableMetaData != null && !variableMetaData.Type.IsNumeric()) { throw new ArgumentException( "Variable named '" + outputLimitSpec.VariableName + "' must be of numeric type"); } return new OutputConditionPolledTimeFactoryForge(outputLimitSpec.TimePeriodExpr); }
/// <summary> /// Ctor. /// </summary> /// <param name="selectExprProcessor">for processing the select expression and generting the readonly output rows</param> /// <param name="optionalHavingNode">having clause expression node</param> /// <param name="isSelectRStream">true if remove stream events should be generated</param> /// <param name="isUnidirectional">true if unidirectional join</param> /// <param name="isHistoricalOnly">if set to <c>true</c> [is historical only].</param> public ResultSetProcessorRowForAllFactory( SelectExprProcessor selectExprProcessor, ExprEvaluator optionalHavingNode, bool isSelectRStream, bool isUnidirectional, bool isHistoricalOnly, OutputLimitSpec outputLimitSpec) { _selectExprProcessor = selectExprProcessor; OutputLimitSpec = outputLimitSpec; OptionalHavingNode = optionalHavingNode; IsSelectRStream = isSelectRStream; IsUnidirectional = isUnidirectional; IsHistoricalOnly = isHistoricalOnly; }
/// <summary> /// Ctor. /// </summary> /// <param name="selectExprProcessor">for processing the select expression and generting the readonly output rows</param> /// <param name="optionalHavingNode">having clause expression node</param> /// <param name="isSelectRStream">true if remove stream events should be generated</param> /// <param name="outputLimitSpec">The output limit spec.</param> /// <param name="enableOutputLimitOpt">if set to <c>true</c> [enable output limit opt].</param> /// <param name="resultSetProcessorHelperFactory">The result set processor helper factory.</param> /// <param name="numStreams">The number streams.</param> public ResultSetProcessorSimpleFactory( SelectExprProcessor selectExprProcessor, ExprEvaluator optionalHavingNode, bool isSelectRStream, OutputLimitSpec outputLimitSpec, bool enableOutputLimitOpt, ResultSetProcessorHelperFactory resultSetProcessorHelperFactory, int numStreams) { _selectExprProcessor = selectExprProcessor; _optionalHavingExpr = optionalHavingNode; _isSelectRStream = isSelectRStream; _outputLimitSpec = outputLimitSpec; IsEnableOutputLimitOpt = enableOutputLimitOpt; ResultSetProcessorHelperFactory = resultSetProcessorHelperFactory; NumStreams = numStreams; }
public OutputConditionFirstFactory(OutputLimitSpec outputLimitSpec, StatementContext statementContext, bool isGrouped, bool isWithHavingClause, ResultSetProcessorHelperFactory resultSetProcessorHelperFactory) { var innerSpec = new OutputLimitSpec(outputLimitSpec.Rate, outputLimitSpec.VariableName, outputLimitSpec.RateType, OutputLimitLimitType.DEFAULT, outputLimitSpec.WhenExpressionNode, outputLimitSpec.ThenExpressions, outputLimitSpec.CrontabAtSchedule, outputLimitSpec.TimePeriodExpr, outputLimitSpec.AfterTimePeriodExpr, outputLimitSpec.AfterNumberOfEvents, outputLimitSpec.IsAndAfterTerminate, outputLimitSpec.AndAfterTerminateExpr, outputLimitSpec.AndAfterTerminateThenExpressions); _innerConditionFactory = OutputConditionFactoryFactory.CreateCondition(innerSpec, statementContext, isGrouped, isWithHavingClause, false, resultSetProcessorHelperFactory); }
public static OutputConditionPolledFactory CreateConditionFactory(OutputLimitSpec outputLimitSpec, StatementContext statementContext) { if (outputLimitSpec == null) { throw new ArgumentNullException("Output condition by count requires a non-null callback"); } // check variable use VariableMetaData variableMetaData = null; if (outputLimitSpec.VariableName != null) { variableMetaData = statementContext.VariableService.GetVariableMetaData(outputLimitSpec.VariableName); if (variableMetaData == null) { throw new ArgumentException("Variable named '" + outputLimitSpec.VariableName + "' has not been declared"); } } if (outputLimitSpec.RateType == OutputLimitRateType.CRONTAB) { return(new OutputConditionPolledCrontabFactory(outputLimitSpec.CrontabAtSchedule, statementContext)); } else if (outputLimitSpec.RateType == OutputLimitRateType.WHEN_EXPRESSION) { return(new OutputConditionPolledExpressionFactory(outputLimitSpec.WhenExpressionNode, outputLimitSpec.ThenExpressions, statementContext)); } else if (outputLimitSpec.RateType == OutputLimitRateType.EVENTS) { int rate = -1; if (outputLimitSpec.Rate != null) { rate = outputLimitSpec.Rate.AsInt(); } return(new OutputConditionPolledCountFactory(rate, statementContext, outputLimitSpec.VariableName)); } else { if (variableMetaData != null && (!variableMetaData.VariableType.IsNumeric())) { throw new ArgumentException("Variable named '" + outputLimitSpec.VariableName + "' must be of numeric type"); } return(new OutputConditionPolledTimeFactory(outputLimitSpec.TimePeriodExpr, statementContext)); } }
public ResultSetProcessorSimpleForge( EventType resultEventType, SelectExprProcessorForge selectExprProcessorForge, ExprForge optionalHavingNode, bool isSelectRStream, OutputLimitSpec outputLimitSpec, ResultSetProcessorOutputConditionType? outputConditionType, bool isSorting, EventType[] eventTypes) { ResultEventType = resultEventType; this.selectExprProcessorForge = selectExprProcessorForge; OptionalHavingNode = optionalHavingNode; IsSelectRStream = isSelectRStream; this.outputLimitSpec = outputLimitSpec; OutputConditionType = outputConditionType; IsSorting = isSorting; EventTypes = eventTypes; }
private StatementSpecCompiled MakeSpec(SelectClauseSpecCompiled selectClauseSpec, InsertIntoDesc insertIntoDesc, IList <ExprNode> groupByNodes, ExprNode optionalHavingNode, OutputLimitSpec outputLimitSpec, IList <OrderByItem> orderByList) { return(new StatementSpecCompiled(null, // on trigger null, // create win null, // create index null, // create var null, // create agg var null, // create schema insertIntoDesc, SelectClauseStreamSelectorEnum.ISTREAM_ONLY, selectClauseSpec, new StreamSpecCompiled[0], // stream specs null, // outer join null, optionalHavingNode, outputLimitSpec, OrderByItem.ToArray(orderByList), null, null, null, null, null, CollectionUtil.EMPTY_STRING_ARRAY, new Attribute[0], null, null, null, null, null, null, null, null, null, new GroupByClauseExpressions(ExprNodeUtility.ToArray(groupByNodes)), null, null )); }
/// <summary> /// Ctor. /// </summary> /// <param name="selectExprProcessor">for processing the select expression and generting the readonly output rows</param> /// <param name="optionalHavingNode">having clause expression node</param> /// <param name="isSelectRStream">true if remove stream events should be generated</param> /// <param name="isUnidirectional">true if unidirectional join</param> /// <param name="isHistoricalOnly">if set to <c>true</c> [is historical only].</param> /// <param name="outputLimitSpec">The output limit spec.</param> /// <param name="enableOutputLimitOpt">if set to <c>true</c> [enable output limit opt].</param> /// <param name="resultSetProcessorHelperFactory">The result set processor helper factory.</param> public ResultSetProcessorAggregateAllFactory( SelectExprProcessor selectExprProcessor, ExprEvaluator optionalHavingNode, bool isSelectRStream, bool isUnidirectional, bool isHistoricalOnly, OutputLimitSpec outputLimitSpec, bool enableOutputLimitOpt, ResultSetProcessorHelperFactory resultSetProcessorHelperFactory) { _selectExprProcessor = selectExprProcessor; OutputLimitSpec = outputLimitSpec; OptionalHavingNode = optionalHavingNode; IsSelectRStream = isSelectRStream; IsUnidirectional = isUnidirectional; IsHistoricalOnly = isHistoricalOnly; IsEnableOutputLimitOpt = enableOutputLimitOpt; ResultSetProcessorHelperFactory = resultSetProcessorHelperFactory; }
public ResultSetProcessorRowForAllForge( EventType resultEventType, SelectExprProcessorForge selectExprProcessorForge, ExprForge optionalHavingNode, bool isSelectRStream, bool isUnidirectional, bool isHistoricalOnly, OutputLimitSpec outputLimitSpec, bool hasOrderBy, ResultSetProcessorOutputConditionType? outputConditionType) { ResultEventType = resultEventType; this.selectExprProcessorForge = selectExprProcessorForge; OptionalHavingNode = optionalHavingNode; IsSelectRStream = isSelectRStream; IsUnidirectional = isUnidirectional; IsHistoricalOnly = isHistoricalOnly; OutputLimitSpec = outputLimitSpec; IsSorting = hasOrderBy; this.outputConditionType = outputConditionType; }
public ResultSetProcessorRowPerGroupRollupForge( EventType resultEventType, GroupByRollupPerLevelForge perLevelForges, ExprNode[] groupKeyNodeExpressions, bool isSelectRStream, bool isUnidirectional, OutputLimitSpec outputLimitSpec, bool isSorting, bool noDataWindowSingleStream, AggregationGroupByRollupDescForge groupByRollupDesc, bool isJoin, bool isHistoricalOnly, bool iterateUnbounded, ResultSetProcessorOutputConditionType? outputConditionType, OutputConditionPolledFactoryForge optionalOutputFirstConditionFactory, EventType[] eventTypes, MultiKeyClassRef multiKeyClassRef) { ResultEventType = resultEventType; GroupKeyNodeExpressions = groupKeyNodeExpressions; PerLevelForges = perLevelForges; IsSorting = isSorting; IsSelectRStream = isSelectRStream; IsUnidirectional = isUnidirectional; OutputLimitSpec = outputLimitSpec; var noDataWindowSingleSnapshot = iterateUnbounded || outputLimitSpec != null && outputLimitSpec.DisplayLimit == OutputLimitLimitType.SNAPSHOT && noDataWindowSingleStream; unbounded = noDataWindowSingleSnapshot && !isHistoricalOnly; GroupByRollupDesc = groupByRollupDesc; IsJoin = isJoin; IsHistoricalOnly = isHistoricalOnly; OutputConditionType = outputConditionType; OptionalOutputFirstConditionFactory = optionalOutputFirstConditionFactory; EventTypes = eventTypes; GroupKeyTypes = ExprNodeUtilityQuery.GetExprResultTypes(groupKeyNodeExpressions); MultiKeyClassRef = multiKeyClassRef; }
/// <summary> /// Ctor. /// </summary> /// <param name="selectExprProcessor">for processing the select expression and generting the readonly output rows</param> /// <param name="groupKeyNodeExpressions">The group key node expressions.</param> /// <param name="groupKeyNodes">list of group-by expression nodes needed for building the group-by keys</param> /// <param name="optionalHavingNode">expression node representing validated HAVING clause, or null if none given.Aggregation functions in the having node must have been pointed to the AggregationService for evaluation.</param> /// <param name="isSelectRStream">true if remove stream events should be generated</param> /// <param name="isUnidirectional">true if unidirectional join</param> /// <param name="outputLimitSpec">The output limit spec.</param> /// <param name="isSorting">if set to <c>true</c> [is sorting].</param> public ResultSetProcessorAggregateGroupedFactory( SelectExprProcessor selectExprProcessor, ExprNode[] groupKeyNodeExpressions, ExprEvaluator[] groupKeyNodes, ExprEvaluator optionalHavingNode, bool isSelectRStream, bool isUnidirectional, OutputLimitSpec outputLimitSpec, bool isSorting, bool isHistoricalOnly) { _selectExprProcessor = selectExprProcessor; GroupKeyNodeExpressions = groupKeyNodeExpressions; GroupKeyNode = groupKeyNodes.Length == 1 ? groupKeyNodes[0] : null; GroupKeyNodes = groupKeyNodes; OptionalHavingNode = optionalHavingNode; IsSorting = isSorting; IsSelectRStream = isSelectRStream; IsUnidirectional = isUnidirectional; IsHistoricalOnly = isHistoricalOnly; OutputLimitSpec = outputLimitSpec; }
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) })); }
/// <summary> /// Creates an output condition instance. /// </summary> /// <param name="outputLimitSpec">specifies what kind of condition to create</param> /// <param name="agentInstanceContext">The agent instance context.</param> /// <returns>instance for handling output condition</returns> public static OutputConditionPolled CreateCondition( OutputLimitSpec outputLimitSpec, AgentInstanceContext agentInstanceContext) { if (outputLimitSpec == null) { throw new ArgumentNullException("outputLimitSpec", "Output condition by count requires a non-null callback"); } // Check if a variable is present VariableReader reader = null; if (outputLimitSpec.VariableName != null) { reader = agentInstanceContext.StatementContext.VariableService.GetReader( outputLimitSpec.VariableName, agentInstanceContext.AgentInstanceId); if (reader == null) { throw new ArgumentException( "Variable named '" + outputLimitSpec.VariableName + "' has not been declared"); } } if (outputLimitSpec.RateType == OutputLimitRateType.CRONTAB) { return(new OutputConditionPolledCrontab(outputLimitSpec.CrontabAtSchedule, agentInstanceContext)); } else if (outputLimitSpec.RateType == OutputLimitRateType.WHEN_EXPRESSION) { return(new OutputConditionPolledExpression( outputLimitSpec.WhenExpressionNode, outputLimitSpec.ThenExpressions, agentInstanceContext)); } else if (outputLimitSpec.RateType == OutputLimitRateType.EVENTS) { if (Log.IsDebugEnabled) { Log.Debug(".createCondition creating OutputConditionCount with event rate " + outputLimitSpec); } if ((reader != null) && (!TypeHelper.IsNumericNonFP(reader.VariableMetaData.VariableType))) { throw new ArgumentException( "Variable named '" + outputLimitSpec.VariableName + "' must be type integer, long or short"); } int rate = -1; if (outputLimitSpec.Rate != null) { rate = outputLimitSpec.Rate.AsInt(); } return(new OutputConditionPolledCount(rate, reader)); } else { if ((reader != null) && (!TypeHelper.IsNumeric(reader.VariableMetaData.VariableType))) { throw new ArgumentException( "Variable named '" + outputLimitSpec.VariableName + "' must be of numeric type"); } return(new OutputConditionPolledTime(outputLimitSpec.TimePeriodExpr, agentInstanceContext)); } }
public static OutputConditionFactory CreateCondition( OutputLimitSpec outputLimitSpec, StatementContext statementContext, bool isGrouped, bool isWithHavingClause, bool isStartConditionOnCreation, ResultSetProcessorHelperFactory resultSetProcessorHelperFactory) { if (outputLimitSpec == null) { return new OutputConditionNullFactory(); } // Check if a variable is present VariableMetaData variableMetaData = null; if (outputLimitSpec.VariableName != null) { variableMetaData = statementContext.VariableService.GetVariableMetaData(outputLimitSpec.VariableName); if (variableMetaData == null) { throw new ExprValidationException( "Variable named '" + outputLimitSpec.VariableName + "' has not been declared"); } string message = VariableServiceUtil.CheckVariableContextName( statementContext.ContextDescriptor, variableMetaData); if (message != null) { throw new ExprValidationException(message); } } if (outputLimitSpec.DisplayLimit == OutputLimitLimitType.FIRST && isGrouped) { return new OutputConditionNullFactory(); } if (outputLimitSpec.RateType == OutputLimitRateType.CRONTAB) { return resultSetProcessorHelperFactory.MakeOutputConditionCrontab( outputLimitSpec.CrontabAtSchedule, statementContext, isStartConditionOnCreation); } else if (outputLimitSpec.RateType == OutputLimitRateType.WHEN_EXPRESSION) { return resultSetProcessorHelperFactory.MakeOutputConditionExpression( outputLimitSpec.WhenExpressionNode, outputLimitSpec.ThenExpressions, statementContext, outputLimitSpec.AndAfterTerminateExpr, outputLimitSpec.AndAfterTerminateThenExpressions, isStartConditionOnCreation); } else if (outputLimitSpec.RateType == OutputLimitRateType.EVENTS) { if (Log.IsDebugEnabled) { Log.Debug(".createCondition creating OutputConditionCount with event rate " + outputLimitSpec); } if ((variableMetaData != null) && (!variableMetaData.VariableType.IsNumericNonFP())) { throw new ArgumentException( "Variable named '" + outputLimitSpec.VariableName + "' must be type integer, long or short"); } int rate = -1; if (outputLimitSpec.Rate != null) { rate = outputLimitSpec.Rate.AsInt(); } return resultSetProcessorHelperFactory.MakeOutputConditionCount( rate, variableMetaData, statementContext); } else if (outputLimitSpec.RateType == OutputLimitRateType.TERM) { if (outputLimitSpec.AndAfterTerminateExpr == null && (outputLimitSpec.AndAfterTerminateThenExpressions == null || outputLimitSpec.AndAfterTerminateThenExpressions.IsEmpty())) { return new OutputConditionTermFactory(); } else { return resultSetProcessorHelperFactory.MakeOutputConditionExpression( new ExprConstantNodeImpl(false), Collections.GetEmptyList<OnTriggerSetAssignment>(), statementContext, outputLimitSpec.AndAfterTerminateExpr, outputLimitSpec.AndAfterTerminateThenExpressions, isStartConditionOnCreation); } } else { if (Log.IsDebugEnabled) { Log.Debug( ".createCondition creating OutputConditionTime with interval length " + outputLimitSpec.Rate); } if ((variableMetaData != null) && (!variableMetaData.VariableType.IsNumeric())) { throw new ArgumentException( "Variable named '" + outputLimitSpec.VariableName + "' must be of numeric type"); } return resultSetProcessorHelperFactory.MakeOutputConditionTime( outputLimitSpec.TimePeriodExpr, isStartConditionOnCreation); } }
public static OutputProcessViewFactory Make( StatementSpecCompiled statementSpec, InternalEventRouter internalEventRouter, StatementContext statementContext, EventType resultEventType, OutputProcessViewCallback optionalOutputProcessViewCallback, TableService tableService, ResultSetProcessorType resultSetProcessorType, ResultSetProcessorHelperFactory resultSetProcessorHelperFactory, StatementVariableRef statementVariableRef) { // determine direct-callback if (optionalOutputProcessViewCallback != null) { return(new OutputProcessViewFactoryCallback(optionalOutputProcessViewCallback)); } // determine routing bool isRouted = false; bool routeToFront = false; if (statementSpec.InsertIntoDesc != null) { isRouted = true; routeToFront = statementContext.NamedWindowMgmtService.IsNamedWindow(statementSpec.InsertIntoDesc.EventTypeName); } OutputStrategyPostProcessFactory outputStrategyPostProcessFactory = null; if ((statementSpec.InsertIntoDesc != null) || (statementSpec.SelectStreamSelectorEnum == SelectClauseStreamSelectorEnum.RSTREAM_ONLY)) { SelectClauseStreamSelectorEnum?insertIntoStreamSelector = null; string tableName = null; if (statementSpec.InsertIntoDesc != null) { insertIntoStreamSelector = statementSpec.InsertIntoDesc.StreamSelector; TableMetadata tableMetadata = tableService.GetTableMetadata(statementSpec.InsertIntoDesc.EventTypeName); if (tableMetadata != null) { tableName = tableMetadata.TableName; EPLValidationUtil.ValidateContextName( true, tableName, tableMetadata.ContextName, statementSpec.OptionalContextName, true); statementVariableRef.AddReferences(statementContext.StatementName, tableMetadata.TableName); } } outputStrategyPostProcessFactory = new OutputStrategyPostProcessFactory( isRouted, insertIntoStreamSelector, statementSpec.SelectStreamSelectorEnum, internalEventRouter, statementContext.EpStatementHandle, routeToFront, tableService, tableName); } // Do we need to enforce an output policy? int streamCount = statementSpec.StreamSpecs.Length; OutputLimitSpec outputLimitSpec = statementSpec.OutputLimitSpec; bool isDistinct = statementSpec.SelectClauseSpec.IsDistinct; bool isGrouped = statementSpec.GroupByExpressions != null && statementSpec.GroupByExpressions.GroupByNodes.Length > 0; OutputProcessViewFactory outputProcessViewFactory; if (outputLimitSpec == null) { if (!isDistinct) { outputProcessViewFactory = new OutputProcessViewDirectFactory( statementContext, outputStrategyPostProcessFactory, resultSetProcessorHelperFactory); } else { outputProcessViewFactory = new OutputProcessViewDirectDistinctOrAfterFactory( statementContext, outputStrategyPostProcessFactory, resultSetProcessorHelperFactory, isDistinct, null, null, resultEventType); } } else if (outputLimitSpec.RateType == OutputLimitRateType.AFTER) { outputProcessViewFactory = new OutputProcessViewDirectDistinctOrAfterFactory( statementContext, outputStrategyPostProcessFactory, resultSetProcessorHelperFactory, isDistinct, outputLimitSpec.AfterTimePeriodExpr, outputLimitSpec.AfterNumberOfEvents, resultEventType); } else { try { bool isWithHavingClause = statementSpec.HavingExprRootNode != null; bool isStartConditionOnCreation = HasOnlyTables(statementSpec.StreamSpecs); OutputConditionFactory outputConditionFactory = OutputConditionFactoryFactory.CreateCondition( outputLimitSpec, statementContext, isGrouped, isWithHavingClause, isStartConditionOnCreation, resultSetProcessorHelperFactory); bool hasOrderBy = statementSpec.OrderByList != null && statementSpec.OrderByList.Length > 0; OutputProcessViewConditionFactory.ConditionType conditionType; bool hasAfter = outputLimitSpec.AfterNumberOfEvents != null || outputLimitSpec.AfterTimePeriodExpr != null; bool isUnaggregatedUngrouped = resultSetProcessorType == ResultSetProcessorType.HANDTHROUGH || resultSetProcessorType == ResultSetProcessorType.UNAGGREGATED_UNGROUPED; // hint checking with order-by bool hasOptHint = HintEnum.ENABLE_OUTPUTLIMIT_OPT.GetHint(statementSpec.Annotations) != null; if (hasOptHint && hasOrderBy) { throw new ExprValidationException( "The " + HintEnum.ENABLE_OUTPUTLIMIT_OPT + " hint is not supported with order-by"); } if (outputLimitSpec.DisplayLimit == OutputLimitLimitType.SNAPSHOT) { conditionType = OutputProcessViewConditionFactory.ConditionType.SNAPSHOT; } else if (outputLimitSpec.DisplayLimit == OutputLimitLimitType.FIRST && statementSpec.GroupByExpressions == null) { // For FIRST without groups we are using a special logic that integrates the first-flag, in order to still conveniently use all sorts of output conditions. // FIRST with group-by is handled by setting the output condition to null (OutputConditionNull) and letting the ResultSetProcessor handle first-per-group. // Without having-clause there is no required order of processing, thus also use regular policy. conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_FIRST; } else if (isUnaggregatedUngrouped && outputLimitSpec.DisplayLimit == OutputLimitLimitType.LAST) { conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_LASTALL_UNORDERED; } else if (hasOptHint && outputLimitSpec.DisplayLimit == OutputLimitLimitType.ALL && !hasOrderBy) { conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_LASTALL_UNORDERED; } else if (hasOptHint && outputLimitSpec.DisplayLimit == OutputLimitLimitType.LAST && !hasOrderBy) { conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_LASTALL_UNORDERED; } else { conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_NONFIRST; } SelectClauseStreamSelectorEnum selectClauseStreamSelectorEnum = statementSpec.SelectStreamSelectorEnum; bool terminable = outputLimitSpec.RateType == OutputLimitRateType.TERM || outputLimitSpec.IsAndAfterTerminate; outputProcessViewFactory = new OutputProcessViewConditionFactory( statementContext, outputStrategyPostProcessFactory, isDistinct, outputLimitSpec.AfterTimePeriodExpr, outputLimitSpec.AfterNumberOfEvents, resultEventType, outputConditionFactory, streamCount, conditionType, outputLimitSpec.DisplayLimit, terminable, hasAfter, isUnaggregatedUngrouped, selectClauseStreamSelectorEnum, resultSetProcessorHelperFactory); } catch (Exception ex) { throw new ExprValidationException("Error in the output rate limiting clause: " + ex.Message, ex); } } return(outputProcessViewFactory); }
public static OutputConditionFactoryForge CreateCondition( OutputLimitSpec outputLimitSpec, bool isGrouped, bool isWithHavingClause, bool isStartConditionOnCreation, StatementRawInfo statementRawInfo, StatementCompileTimeServices services) { if (outputLimitSpec == null) { return OutputConditionNullFactoryForge.INSTANCE; } // Check if a variable is present VariableMetaData variableMetaData = null; if (outputLimitSpec.VariableName != null) { variableMetaData = services.VariableCompileTimeResolver.Resolve(outputLimitSpec.VariableName); if (variableMetaData == null) { throw new ExprValidationException( "Variable named '" + outputLimitSpec.VariableName + "' has not been declared"); } var message = VariableUtil.CheckVariableContextName(statementRawInfo.ContextName, variableMetaData); if (message != null) { throw new ExprValidationException(message); } } if (outputLimitSpec.DisplayLimit == OutputLimitLimitType.FIRST && isGrouped) { return OutputConditionNullFactoryForge.INSTANCE; } if (outputLimitSpec.RateType == OutputLimitRateType.CRONTAB) { return new OutputConditionCrontabForge( outputLimitSpec.CrontabAtSchedule, isStartConditionOnCreation, statementRawInfo, services); } if (outputLimitSpec.RateType == OutputLimitRateType.WHEN_EXPRESSION) { return new OutputConditionExpressionForge( outputLimitSpec.WhenExpressionNode, outputLimitSpec.ThenExpressions, outputLimitSpec.AndAfterTerminateExpr, outputLimitSpec.AndAfterTerminateThenExpressions, isStartConditionOnCreation, statementRawInfo, services); } if (outputLimitSpec.RateType == OutputLimitRateType.EVENTS) { if (variableMetaData != null && !variableMetaData.Type.IsNumericNonFP()) { throw new ArgumentException( "Variable named '" + outputLimitSpec.VariableName + "' must be type integer, long or short"); } var rate = -1; if (outputLimitSpec.Rate != null) { rate = outputLimitSpec.Rate.AsInt32(); } return new OutputConditionCountForge(rate, variableMetaData); } if (outputLimitSpec.RateType == OutputLimitRateType.TERM) { if (outputLimitSpec.AndAfterTerminateExpr == null && (outputLimitSpec.AndAfterTerminateThenExpressions == null || outputLimitSpec.AndAfterTerminateThenExpressions.IsEmpty())) { return new OutputConditionTermFactoryForge(); } return new OutputConditionExpressionForge( new ExprConstantNodeImpl(false), Collections.GetEmptyList<OnTriggerSetAssignment>(), outputLimitSpec.AndAfterTerminateExpr, outputLimitSpec.AndAfterTerminateThenExpressions, isStartConditionOnCreation, statementRawInfo, services); } if (Log.IsDebugEnabled) { Log.Debug(".createCondition creating OutputConditionTime with interval length " + outputLimitSpec.Rate); } if (variableMetaData != null && !variableMetaData.Type.IsNumeric()) { throw new ArgumentException( "Variable named '" + outputLimitSpec.VariableName + "' must be of numeric type"); } return new OutputConditionTimeForge(outputLimitSpec.TimePeriodExpr, isStartConditionOnCreation); }
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 OutputProcessViewFactoryForgeDesc Make( EventType[] typesPerStream, EventType resultEventType, ResultSetProcessorType resultSetProcessorType, StatementSpecCompiled statementSpec, StatementRawInfo statementRawInfo, StatementCompileTimeServices services) { InsertIntoDesc insertIntoDesc = statementSpec.Raw.InsertIntoDesc; SelectClauseStreamSelectorEnum selectStreamSelector = statementSpec.Raw.SelectStreamSelectorEnum; OutputLimitSpec outputLimitSpec = statementSpec.Raw.OutputLimitSpec; int streamCount = statementSpec.StreamSpecs.Length; bool isDistinct = statementSpec.Raw.SelectClauseSpec.IsDistinct; bool isGrouped = statementSpec.GroupByExpressions != null && statementSpec.GroupByExpressions.GroupByNodes.Length > 0; List<StmtClassForgeableFactory> additionalForgeables = new List<StmtClassForgeableFactory>(); // determine routing bool isRouted = false; bool routeToFront = false; if (insertIntoDesc != null) { isRouted = true; routeToFront = services.NamedWindowCompileTimeResolver.Resolve(insertIntoDesc.EventTypeName) != null; } OutputStrategyPostProcessForge outputStrategyPostProcessForge = null; if ((insertIntoDesc != null) || (selectStreamSelector == SelectClauseStreamSelectorEnum.RSTREAM_ONLY)) { SelectClauseStreamSelectorEnum? insertIntoStreamSelector = null; TableMetaData table = null; if (insertIntoDesc != null) { insertIntoStreamSelector = insertIntoDesc.StreamSelector; table = services.TableCompileTimeResolver.Resolve(statementSpec.Raw.InsertIntoDesc.EventTypeName); if (table != null) { EPLValidationUtil.ValidateContextName( true, table.TableName, table.OptionalContextName, statementSpec.Raw.OptionalContextName, true); } } bool audit = AuditEnum.INSERT.GetAudit(statementSpec.Annotations) != null; outputStrategyPostProcessForge = new OutputStrategyPostProcessForge( isRouted, insertIntoStreamSelector, selectStreamSelector, routeToFront, table, audit); } MultiKeyPlan multiKeyPlan = MultiKeyPlanner.PlanMultiKeyDistinct( isDistinct, resultEventType, statementRawInfo, SerdeCompileTimeResolverNonHA.INSTANCE); MultiKeyClassRef distinctMultiKey = multiKeyPlan.ClassRef; additionalForgeables.AddRange(multiKeyPlan.MultiKeyForgeables); OutputProcessViewFactoryForge outputProcessViewFactoryForge; if (outputLimitSpec == null) { if (!isDistinct) { if (outputStrategyPostProcessForge == null || !outputStrategyPostProcessForge.HasTable) { // without table we have a shortcut implementation outputProcessViewFactoryForge = new OutputProcessViewDirectSimpleForge(outputStrategyPostProcessForge); } else { outputProcessViewFactoryForge = new OutputProcessViewDirectForge(outputStrategyPostProcessForge); } } else { outputProcessViewFactoryForge = new OutputProcessViewDirectDistinctOrAfterFactoryForge( outputStrategyPostProcessForge, isDistinct, distinctMultiKey, null, null, resultEventType); } } else if (outputLimitSpec.RateType == OutputLimitRateType.AFTER) { outputProcessViewFactoryForge = new OutputProcessViewDirectDistinctOrAfterFactoryForge( outputStrategyPostProcessForge, isDistinct, distinctMultiKey, outputLimitSpec.AfterTimePeriodExpr, outputLimitSpec.AfterNumberOfEvents, resultEventType); } else { try { bool isWithHavingClause = statementSpec.Raw.HavingClause != null; bool isStartConditionOnCreation = HasOnlyTables(statementSpec.StreamSpecs); OutputConditionFactoryForge outputConditionFactoryForge = OutputConditionFactoryFactory.CreateCondition( outputLimitSpec, isGrouped, isWithHavingClause, isStartConditionOnCreation, statementRawInfo, services); bool hasOrderBy = statementSpec.Raw.OrderByList != null && statementSpec.Raw.OrderByList.Count > 0; bool hasAfter = outputLimitSpec.AfterNumberOfEvents != null || outputLimitSpec.AfterTimePeriodExpr != null; // hint checking with order-by bool hasOptHint = ResultSetProcessorOutputConditionTypeExtensions .GetOutputLimitOpt(statementSpec.Annotations, services.Configuration, hasOrderBy); ResultSetProcessorOutputConditionType conditionType = ResultSetProcessorOutputConditionTypeExtensions .GetConditionType( outputLimitSpec.DisplayLimit, resultSetProcessorType.IsAggregated(), hasOrderBy, hasOptHint, resultSetProcessorType.IsGrouped()); // plan serdes foreach (EventType eventType in typesPerStream) { IList<StmtClassForgeableFactory> serdeForgeables = SerdeEventTypeUtility.Plan( eventType, statementRawInfo, services.SerdeEventTypeRegistry, services.SerdeResolver); additionalForgeables.AddRange(serdeForgeables); } bool terminable = outputLimitSpec.RateType == OutputLimitRateType.TERM || outputLimitSpec.IsAndAfterTerminate; outputProcessViewFactoryForge = new OutputProcessViewConditionForge( outputStrategyPostProcessForge, isDistinct, distinctMultiKey, outputLimitSpec.AfterTimePeriodExpr, outputLimitSpec.AfterNumberOfEvents, outputConditionFactoryForge, streamCount, conditionType, terminable, hasAfter, resultSetProcessorType.IsUnaggregatedUngrouped(), selectStreamSelector, typesPerStream, resultEventType); } catch (Exception ex) { throw new ExprValidationException("Failed to validate the output rate limiting clause: " + ex.Message, ex); } } return new OutputProcessViewFactoryForgeDesc(outputProcessViewFactoryForge, additionalForgeables); }