public OutputProcessViewConditionForge( OutputStrategyPostProcessForge outputStrategyPostProcessForge, bool isDistinct, MultiKeyClassRef distinctMultiKey, ExprTimePeriod afterTimePeriodExpr, int? afterNumberOfEvents, OutputConditionFactoryForge outputConditionFactoryForge, int streamCount, ResultSetProcessorOutputConditionType conditionType, bool terminable, bool hasAfter, bool unaggregatedUngrouped, SelectClauseStreamSelectorEnum selectClauseStreamSelector, EventType[] eventTypes, EventType resultEventType) { _outputStrategyPostProcessForge = outputStrategyPostProcessForge; _isDistinct = isDistinct; _distinctMultiKey = distinctMultiKey; _afterTimePeriodExpr = afterTimePeriodExpr; _afterNumberOfEvents = afterNumberOfEvents; _outputConditionFactoryForge = outputConditionFactoryForge; _streamCount = streamCount; _conditionType = conditionType; _terminable = terminable; _hasAfter = hasAfter; _unaggregatedUngrouped = unaggregatedUngrouped; _selectClauseStreamSelector = selectClauseStreamSelector; _eventTypes = eventTypes; _resultEventType = resultEventType; }
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); }