public static EventUnderlyingType GetRepresentation( Attribute[] annotations, Configuration configs, AssignedType assignedType) { switch (assignedType) { // assigned type has priority case AssignedType.OBJECTARRAY: return EventUnderlyingType.OBJECTARRAY; case AssignedType.MAP: return EventUnderlyingType.MAP; case AssignedType.AVRO: return EventUnderlyingType.AVRO; case AssignedType.JSON: return EventUnderlyingType.JSON; } if (assignedType == AssignedType.VARIANT || assignedType != AssignedType.NONE) { throw new IllegalStateException("Not handled by event representation: " + assignedType); } // annotation has second priority var annotation = AnnotationUtil.FindAnnotation(annotations, typeof(EventRepresentationAttribute)); if (annotation != null) { var eventRepresentation = (EventRepresentationAttribute) annotation; return eventRepresentation.Value switch { EventUnderlyingType.AVRO => EventUnderlyingType.AVRO, EventUnderlyingType.JSON => EventUnderlyingType.JSON, EventUnderlyingType.OBJECTARRAY => EventUnderlyingType.OBJECTARRAY, EventUnderlyingType.MAP => EventUnderlyingType.MAP, _ => throw new IllegalStateException("Unrecognized enum " + eventRepresentation.Value) }; } // use runtime-wide default var configured = configs.Common.EventMeta.DefaultEventRepresentation; return configured switch { EventUnderlyingType.OBJECTARRAY => EventUnderlyingType.OBJECTARRAY, EventUnderlyingType.MAP => EventUnderlyingType.MAP, EventUnderlyingType.AVRO => EventUnderlyingType.AVRO, EventUnderlyingType.JSON => EventUnderlyingType.JSON, _ => EventUnderlyingType.MAP }; } } } // end of namespace
public IReaderWriterLock GetStatementLock(String statementName, Attribute[] annotations, bool stateless) { bool foundNoLock = AnnotationUtil.FindAnnotation(annotations, typeof(NoLockAttribute)) != null; if (_disableLocking || foundNoLock || stateless) { return(ReaderWriterLockManager.VoidLock()); } if (_fairlocks) { return(ReaderWriterLockManager.FairLock()); } return(ReaderWriterLockManager.CreateDefaultLock()); }
public IReaderWriterLock GetStatementLock( string statementName, Attribute[] annotations, bool stateless, StatementType statementType) { if (statementType.IsOnTriggerInfra()) { throw new UnsupportedOperationException("Operation not available for statement type " + statementType); } bool foundNoLock = AnnotationUtil.FindAnnotation(annotations, typeof(NoLockAttribute)) != null; if (disableLocking || foundNoLock || stateless) { return new VoidReaderWriterLock(); //return new StatementAgentInstanceLockNoLockImpl(statementName); } else if (fairlocks) { return new FairReaderWriterLock(); } else { return new SlimReaderWriterLock(); } }
private void RunAssertionBuiltin(EPServiceProvider epService) { var stmtText = "@Name('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"value\") select * from Bean"; var stmt = epService.EPAdministrator.CreateEPL(stmtText); Assert.IsTrue(((EPStatementSPI)stmt).IsNameProvided); TryAssertion(stmt); stmt.Dispose(); var name = (NameAttribute)AnnotationUtil.FindAnnotation(stmt.Annotations, typeof(NameAttribute)); Assert.AreEqual("MyTestStmt", name.Value); // try lowercase var stmtTextLower = "@Name('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"value\") select * from Bean"; stmt = epService.EPAdministrator.CreateEPL(stmtTextLower); TryAssertion(stmt); stmt.Dispose(); // try pattern stmtText = "@Name('MyTestStmt') @Description('MyTestStmt description') @Tag(Name='UserId', Value='value') every Bean"; stmt = epService.EPAdministrator.CreatePattern(stmtText); TryAssertion(stmt); stmt.Dispose(); stmtText = "@" + typeof(NameAttribute).FullName + "('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"value\") every Bean"; stmt = epService.EPAdministrator.CreatePattern(stmtText); TryAssertion(stmt); epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY') select * from Bean"); epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY,DISABLE_RECLAIM_GROUP') select * from Bean"); epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY') select * from Bean"); epService.EPAdministrator.CreateEPL("@Hint(' iterate_only ') select * from Bean"); // test statement name override stmtText = "@Name('MyAnnotatedName') select * from Bean"; stmt = epService.EPAdministrator.CreateEPL(stmtText, "MyABCStmt"); Assert.AreEqual("MyABCStmt", stmt.Name); // hint tests Assert.IsNull(HintEnum.DISABLE_RECLAIM_GROUP.GetHint(null)); Assert.IsNull(HintEnum.DISABLE_RECLAIM_GROUP.GetHint(new Attribute[0])); var annos = epService.EPAdministrator.CreateEPL("@Hint('DISABLE_RECLAIM_GROUP') select * from Bean").Annotations; Assert.AreEqual("DISABLE_RECLAIM_GROUP", HintEnum.DISABLE_RECLAIM_GROUP.GetHint(annos).Value); annos = epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY,ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY') select * from Bean").Annotations; Assert.AreEqual("ITERATE_ONLY,ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY", HintEnum.DISABLE_RECLAIM_GROUP.GetHint(annos).Value); annos = epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY,reclaim_group_aged=10') select * from Bean").Annotations; var hint = HintEnum.RECLAIM_GROUP_AGED.GetHint(annos); Assert.AreEqual("10", HintEnum.RECLAIM_GROUP_AGED.GetHintAssignedValue(hint)); annos = epService.EPAdministrator.CreateEPL("@Hint('reclaim_group_aged=11') select * from Bean").Annotations; hint = HintEnum.RECLAIM_GROUP_AGED.GetHint(annos); Assert.AreEqual("11", HintEnum.RECLAIM_GROUP_AGED.GetHintAssignedValue(hint)); annos = epService.EPAdministrator.CreateEPL("@Hint('Index(one, two)') select * from Bean").Annotations; Assert.AreEqual("one, two", HintEnum.INDEX.GetHintAssignedValues(annos)[0]); stmt.Dispose(); // NoLock stmt = epService.EPAdministrator.CreateEPL("@NoLock select * from Bean"); Assert.IsNotNull(AnnotationUtil.FindAnnotation(stmt.Annotations, typeof(NoLockAttribute))); Assert.AreEqual(1, AnnotationUtil.FindAnnotations(stmt.Annotations, typeof(NoLockAttribute)).Count); stmt.Dispose(); }
public void TestBuiltin() { var configuration = SupportConfigFactory.GetConfiguration(); configuration.AddEventType("Bean", typeof(SupportBean).FullName); configuration.AddImport(typeof(MyAnnotationNestableValuesAttribute).Namespace); _epService = EPServiceProviderManager.GetDefaultProvider(configuration); _epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName); } var stmtText = "@Name('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"Value\") select * from Bean"; var stmt = _epService.EPAdministrator.CreateEPL(stmtText); Assert.IsTrue((((EPStatementSPI)stmt).IsNameProvided)); RunAssertion(stmt); stmt.Dispose(); var name = (NameAttribute)AnnotationUtil.FindAnnotation(stmt.Annotations, typeof(NameAttribute)); Assert.AreEqual("MyTestStmt", name.Value); // try lowercase var stmtTextLower = "@Name('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"Value\") select * from Bean"; stmt = _epService.EPAdministrator.CreateEPL(stmtTextLower); RunAssertion(stmt); stmt.Dispose(); // try pattern stmtText = "@Name('MyTestStmt') @Description('MyTestStmt description') @Tag(Name='UserId', Value='Value') every Bean"; stmt = _epService.EPAdministrator.CreatePattern(stmtText); RunAssertion(stmt); stmt.Dispose(); stmtText = "@Name('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"Value\") every Bean"; stmt = _epService.EPAdministrator.CreatePattern(stmtText); RunAssertion(stmt); _epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY') select * from Bean"); _epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY,DISABLE_RECLAIM_GROUP') select * from Bean"); _epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY') select * from Bean"); _epService.EPAdministrator.CreateEPL("@Hint(' iterate_only ') select * from Bean"); // test statement name override stmtText = "@Name('MyAnnotatedName') select * from Bean"; stmt = _epService.EPAdministrator.CreateEPL(stmtText, "MyABCStmt"); Assert.AreEqual("MyABCStmt", stmt.Name); // hint tests Assert.IsNull(HintEnum.DISABLE_RECLAIM_GROUP.GetHint(null)); Assert.IsNull(HintEnum.DISABLE_RECLAIM_GROUP.GetHint(new Attribute[0])); var annos = _epService.EPAdministrator.CreateEPL("@Hint('DISABLE_RECLAIM_GROUP') select * from Bean").Annotations.ToArray(); Assert.AreEqual("DISABLE_RECLAIM_GROUP", HintEnum.DISABLE_RECLAIM_GROUP.GetHint(annos).Value); annos = _epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY,ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY') select * from Bean").Annotations.ToArray(); Assert.AreEqual("ITERATE_ONLY,ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY", HintEnum.DISABLE_RECLAIM_GROUP.GetHint(annos).Value); annos = _epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY,reclaim_group_aged=10') select * from Bean").Annotations.ToArray(); var hint = HintEnum.RECLAIM_GROUP_AGED.GetHint(annos); Assert.AreEqual("10", HintEnum.RECLAIM_GROUP_AGED.GetHintAssignedValue(hint)); annos = _epService.EPAdministrator.CreateEPL("@Hint('reclaim_group_aged=11') select * from Bean").Annotations.ToArray(); hint = HintEnum.RECLAIM_GROUP_AGED.GetHint(annos); Assert.AreEqual("11", HintEnum.RECLAIM_GROUP_AGED.GetHintAssignedValue(hint)); annos = _epService.EPAdministrator.CreateEPL("@Hint('index(one, two)') select * from Bean").Annotations.ToArray(); Assert.AreEqual("one, two", HintEnum.INDEX.GetHintAssignedValues(annos)[0]); // NoLock stmt = _epService.EPAdministrator.CreateEPL("@NoLock select * from Bean"); Assert.NotNull(AnnotationUtil.FindAnnotation(stmt.Annotations.ToArray(), typeof(NoLockAttribute))); Assert.AreEqual(1, AnnotationUtil.FindAttributes(stmt.Annotations.ToArray(), typeof(NoLockAttribute)).Count); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public static EventUnderlyingType GetRepresentation( Attribute[] annotations, ConfigurationInformation configs, AssignedType assignedType) { // assigned type has priority if (assignedType == AssignedType.OBJECTARRAY) { return(EventUnderlyingType.OBJECTARRAY); } else if (assignedType == AssignedType.MAP) { return(EventUnderlyingType.MAP); } else if (assignedType == AssignedType.AVRO) { return(EventUnderlyingType.AVRO); } if (assignedType == AssignedType.VARIANT || assignedType != AssignedType.NONE) { throw new IllegalStateException("Not handled by event representation: " + assignedType); } // annotation has second priority var annotation = AnnotationUtil.FindAnnotation(annotations, typeof(EventRepresentationAttribute)); if (annotation != null) { EventRepresentationAttribute eventRepresentation = (EventRepresentationAttribute)annotation; if (eventRepresentation.Value == EventUnderlyingType.AVRO) { return(EventUnderlyingType.AVRO); } else if (eventRepresentation.Value == EventUnderlyingType.OBJECTARRAY) { return(EventUnderlyingType.OBJECTARRAY); } else if (eventRepresentation.Value == EventUnderlyingType.MAP) { return(EventUnderlyingType.MAP); } else { throw new IllegalStateException("Unrecognized enum " + eventRepresentation.Value); } } // use engine-wide default EventUnderlyingType configured = configs.EngineDefaults.EventMeta.DefaultEventRepresentation; if (configured == EventUnderlyingType.OBJECTARRAY) { return(EventUnderlyingType.OBJECTARRAY); } else if (configured == EventUnderlyingType.MAP) { return(EventUnderlyingType.MAP); } else if (configured == EventUnderlyingType.AVRO) { return(EventUnderlyingType.AVRO); } return(EventUnderlyingType.MAP); }
public void Run(RegressionEnvironment env) { string epl; epl = "@Name('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"value\") " + "select * from SupportBean"; env.CompileDeploy(epl).AddListener("MyTestStmt"); TryAssertion(env.Statement("MyTestStmt")); var name = (NameAttribute) AnnotationUtil.FindAnnotation( env.Statement("MyTestStmt").Annotations, typeof(NameAttribute)); Assert.AreEqual("MyTestStmt", name.Value); env.UndeployAll(); // try lowercase epl = "@Name('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"value\") " + " select * from SupportBean"; env.CompileDeploy(epl).AddListener("MyTestStmt"); TryAssertion(env.Statement("MyTestStmt")); env.UndeployAll(); // try fully-qualified epl = "@" + typeof(NameAttribute).Name + "('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"value\") " + "select * from SupportBean"; env.CompileDeploy(epl).AddListener("MyTestStmt"); TryAssertion(env.Statement("MyTestStmt")); env.UndeployAll(); // hint tests Assert.IsNull(HintEnum.DISABLE_RECLAIM_GROUP.GetHint(null)); Assert.IsNull(HintEnum.DISABLE_RECLAIM_GROUP.GetHint(new Attribute[0])); env.CompileDeploy("@Hint('ITERATE_ONLY') select * from SupportBean"); env.CompileDeploy("@Hint('ITERATE_ONLY,DISABLE_RECLAIM_GROUP') select * from SupportBean"); env.CompileDeploy("@Hint('ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY') select * from SupportBean"); env.CompileDeploy("@Hint(' iterate_only ') select * from SupportBean"); var annos = env .CompileDeploy("@Hint('DISABLE_RECLAIM_GROUP') @Name('s0') select * from SupportBean") .Statement("s0") .Annotations; Assert.AreEqual("DISABLE_RECLAIM_GROUP", HintEnum.DISABLE_RECLAIM_GROUP.GetHint(annos).Value); annos = env .CompileDeploy("@Hint('ITERATE_ONLY,ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY') @Name('s1') select * from SupportBean") .Statement("s1") .Annotations; Assert.AreEqual( "ITERATE_ONLY,ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY", HintEnum.DISABLE_RECLAIM_GROUP.GetHint(annos).Value); annos = env .CompileDeploy("@Hint('ITERATE_ONLY,reclaim_group_aged=10') @Name('s2') select * from SupportBean") .Statement("s2") .Annotations; var hint = HintEnum.RECLAIM_GROUP_AGED.GetHint(annos); Assert.AreEqual("10", HintEnum.RECLAIM_GROUP_AGED.GetHintAssignedValue(hint)); annos = env .CompileDeploy("@Hint('reclaim_group_aged=11') @Name('s3') select * from SupportBean") .Statement("s3") .Annotations; hint = HintEnum.RECLAIM_GROUP_AGED.GetHint(annos); Assert.AreEqual("11", HintEnum.RECLAIM_GROUP_AGED.GetHintAssignedValue(hint)); annos = env .CompileDeploy("@Hint('index(one, two)') @Name('s4') select * from SupportBean") .Statement("s4") .Annotations; Assert.AreEqual("one, two", HintEnum.INDEX.GetHintAssignedValues(annos)[0]); env.UndeployAll(); // NoLock env.CompileDeploy("@Name('s0') @NoLock select * from SupportBean"); Assert.AreEqual( 1, AnnotationUtil.FindAnnotations(env.Statement("s0").Annotations, typeof(NoLockAttribute)).Count); env.UndeployAll(); }
public static EPStatementStartMethodSelectDesc Prepare( StatementSpecCompiled statementSpec, EPServicesContext services, StatementContext statementContext, bool recoveringResilient, AgentInstanceContext defaultAgentInstanceContext, bool queryPlanLogging, ViewableActivatorFactory optionalViewableActivatorFactory, OutputProcessViewCallback optionalOutputProcessViewCallback, SelectExprProcessorDeliveryCallback selectExprProcessorDeliveryCallback) { // define stop and destroy var stopCallbacks = new List <StopCallback>(); var destroyCallbacks = new EPStatementDestroyCallbackList(); // determine context var contextName = statementSpec.OptionalContextName; var contextPropertyRegistry = (contextName != null) ? services.ContextManagementService.GetContextDescriptor(contextName).ContextPropertyRegistry : null; // Determine stream names for each stream - some streams may not have a name given var streamNames = EPStatementStartMethodHelperUtil.DetermineStreamNames(statementSpec.StreamSpecs); var numStreams = streamNames.Length; if (numStreams == 0) { throw new ExprValidationException("The from-clause is required but has not been specified"); } var isJoin = statementSpec.StreamSpecs.Length > 1; var hasContext = statementSpec.OptionalContextName != null; // First we create streams for subselects, if there are any var subSelectStreamDesc = EPStatementStartMethodHelperSubselect.CreateSubSelectActivation( services, statementSpec, statementContext, destroyCallbacks); // Create streams and views var eventStreamParentViewableActivators = new ViewableActivator[numStreams]; var unmaterializedViewChain = new ViewFactoryChain[numStreams]; var eventTypeNames = new string[numStreams]; var isNamedWindow = new bool[numStreams]; var historicalEventViewables = new HistoricalEventViewable[numStreams]; // verify for joins that required views are present var joinAnalysisResult = VerifyJoinViews(statementSpec, statementContext.NamedWindowMgmtService); var evaluatorContextStmt = new ExprEvaluatorContextStatement(statementContext, false); for (var i = 0; i < statementSpec.StreamSpecs.Length; i++) { var streamSpec = statementSpec.StreamSpecs[i]; var isCanIterateUnbound = streamSpec.ViewSpecs.Length == 0 && (services.ConfigSnapshot.EngineDefaults.ViewResources.IsIterableUnbound || AnnotationUtil.FindAnnotation( statementSpec.Annotations, typeof(IterableUnboundAttribute)) != null); // Create view factories and parent view based on a filter specification if (streamSpec is FilterStreamSpecCompiled) { var filterStreamSpec = (FilterStreamSpecCompiled)streamSpec; eventTypeNames[i] = filterStreamSpec.FilterSpec.FilterForEventTypeName; // Since only for non-joins we get the existing stream's lock and try to reuse it's views var filterSubselectSameStream = EPStatementStartMethodHelperUtil.DetermineSubquerySameStream(statementSpec, filterStreamSpec); // create activator ViewableActivator activatorDeactivator; if (optionalViewableActivatorFactory != null) { activatorDeactivator = optionalViewableActivatorFactory.CreateActivatorSimple(filterStreamSpec); if (activatorDeactivator == null) { throw new IllegalStateException( "Viewable activate is null for " + filterStreamSpec.FilterSpec.FilterForEventType.Name); } } else { if (!hasContext) { activatorDeactivator = services.ViewableActivatorFactory.CreateStreamReuseView( services, statementContext, statementSpec, filterStreamSpec, isJoin, evaluatorContextStmt, filterSubselectSameStream, i, isCanIterateUnbound); } else { InstrumentationAgent instrumentationAgentFilter = null; if (InstrumentationHelper.ENABLED) { var eventTypeName = filterStreamSpec.FilterSpec.FilterForEventType.Name; var streamNumber = i; instrumentationAgentFilter = new ProxyInstrumentationAgent() { ProcIndicateQ = () => { InstrumentationHelper.Get() .QFilterActivationStream(eventTypeName, streamNumber); }, ProcIndicateA = () => { InstrumentationHelper.Get().AFilterActivationStream(); } }; } activatorDeactivator = services.ViewableActivatorFactory.CreateFilterProxy( services, filterStreamSpec.FilterSpec, statementSpec.Annotations, false, instrumentationAgentFilter, isCanIterateUnbound, i); } } eventStreamParentViewableActivators[i] = activatorDeactivator; var resultEventType = filterStreamSpec.FilterSpec.ResultEventType; unmaterializedViewChain[i] = services.ViewService.CreateFactories( i, resultEventType, streamSpec.ViewSpecs, streamSpec.Options, statementContext, false, -1); } else if (streamSpec is PatternStreamSpecCompiled) { // Create view factories and parent view based on a pattern expression var patternStreamSpec = (PatternStreamSpecCompiled)streamSpec; var usedByChildViews = streamSpec.ViewSpecs.Length > 0 || (statementSpec.InsertIntoDesc != null); var patternTypeName = statementContext.StatementId + "_pattern_" + i; var eventType = services.EventAdapterService.CreateSemiAnonymousMapType( patternTypeName, patternStreamSpec.TaggedEventTypes, patternStreamSpec.ArrayEventTypes, usedByChildViews); unmaterializedViewChain[i] = services.ViewService.CreateFactories( i, eventType, streamSpec.ViewSpecs, streamSpec.Options, statementContext, false, -1); var rootFactoryNode = services.PatternNodeFactory.MakeRootNode(patternStreamSpec.EvalFactoryNode); var patternContext = statementContext.PatternContextFactory.CreateContext( statementContext, i, rootFactoryNode, patternStreamSpec.MatchedEventMapMeta, true); // create activator var patternActivator = services.ViewableActivatorFactory.CreatePattern( patternContext, rootFactoryNode, eventType, EPStatementStartMethodHelperUtil.IsConsumingFilters(patternStreamSpec.EvalFactoryNode), patternStreamSpec.IsSuppressSameEventMatches, patternStreamSpec.IsDiscardPartialsOnMatch, isCanIterateUnbound); eventStreamParentViewableActivators[i] = patternActivator; } else if (streamSpec is DBStatementStreamSpec) { // Create view factories and parent view based on a database SQL statement ValidateNoViews(streamSpec, "Historical data"); var sqlStreamSpec = (DBStatementStreamSpec)streamSpec; var typeConversionHook = (SQLColumnTypeConversion) TypeHelper.GetAnnotationHook( statementSpec.Annotations, HookType.SQLCOL, typeof(SQLColumnTypeConversion), statementContext.EngineImportService); var outputRowConversionHook = (SQLOutputRowConversion) TypeHelper.GetAnnotationHook( statementSpec.Annotations, HookType.SQLROW, typeof(SQLOutputRowConversion), statementContext.EngineImportService); var epStatementAgentInstanceHandle = defaultAgentInstanceContext.EpStatementAgentInstanceHandle; var historicalEventViewable = DatabasePollingViewableFactory.CreateDBStatementView( statementContext.StatementId, i, sqlStreamSpec, services.DatabaseRefService, services.EventAdapterService, epStatementAgentInstanceHandle, statementContext.Annotations, typeConversionHook, outputRowConversionHook, statementContext.ConfigSnapshot.EngineDefaults.Logging.IsEnableADO, services.DataCacheFactory, statementContext); historicalEventViewables[i] = historicalEventViewable; unmaterializedViewChain[i] = ViewFactoryChain.FromTypeNoViews(historicalEventViewable.EventType); eventStreamParentViewableActivators[i] = services.ViewableActivatorFactory.MakeHistorical(historicalEventViewable); stopCallbacks.Add(historicalEventViewable); } else if (streamSpec is MethodStreamSpec) { ValidateNoViews(streamSpec, "Method data"); var methodStreamSpec = (MethodStreamSpec)streamSpec; var epStatementAgentInstanceHandle = defaultAgentInstanceContext.EpStatementAgentInstanceHandle; var historicalEventViewable = MethodPollingViewableFactory.CreatePollMethodView( i, methodStreamSpec, services.EventAdapterService, epStatementAgentInstanceHandle, statementContext.EngineImportService, statementContext.SchedulingService, statementContext.ScheduleBucket, evaluatorContextStmt, statementContext.VariableService, statementContext.ContextName, services.DataCacheFactory, statementContext); historicalEventViewables[i] = historicalEventViewable; unmaterializedViewChain[i] = ViewFactoryChain.FromTypeNoViews(historicalEventViewable.EventType); eventStreamParentViewableActivators[i] = services.ViewableActivatorFactory.MakeHistorical(historicalEventViewable); stopCallbacks.Add(historicalEventViewable); } else if (streamSpec is TableQueryStreamSpec) { ValidateNoViews(streamSpec, "Table data"); var tableStreamSpec = (TableQueryStreamSpec)streamSpec; if (isJoin && tableStreamSpec.FilterExpressions.Count > 0) { throw new ExprValidationException( "Joins with tables do not allow table filter expressions, please add table filters to the where-clause instead"); } var metadata = services.TableService.GetTableMetadata(tableStreamSpec.TableName); ExprEvaluator[] tableFilterEvals = null; if (tableStreamSpec.FilterExpressions.Count > 0) { tableFilterEvals = ExprNodeUtility.GetEvaluators(tableStreamSpec.FilterExpressions); } EPLValidationUtil.ValidateContextName( true, metadata.TableName, metadata.ContextName, statementSpec.OptionalContextName, false); eventStreamParentViewableActivators[i] = services.ViewableActivatorFactory.CreateTable( metadata, tableFilterEvals); unmaterializedViewChain[i] = ViewFactoryChain.FromTypeNoViews(metadata.InternalEventType); eventTypeNames[i] = tableStreamSpec.TableName; joinAnalysisResult.SetTablesForStream(i, metadata); if (tableStreamSpec.Options.IsUnidirectional) { throw new ExprValidationException("Tables cannot be marked as unidirectional"); } if (tableStreamSpec.Options.IsRetainIntersection || tableStreamSpec.Options.IsRetainUnion) { throw new ExprValidationException("Tables cannot be marked with retain"); } if (isJoin) { destroyCallbacks.AddCallback( new EPStatementDestroyCallbackTableIdxRef( services.TableService, metadata, statementContext.StatementName)); } services.StatementVariableRefService.AddReferences( statementContext.StatementName, metadata.TableName); } else if (streamSpec is NamedWindowConsumerStreamSpec) { var namedSpec = (NamedWindowConsumerStreamSpec)streamSpec; var processor = services.NamedWindowMgmtService.GetProcessor(namedSpec.WindowName); var namedWindowType = processor.TailView.EventType; if (namedSpec.OptPropertyEvaluator != null) { namedWindowType = namedSpec.OptPropertyEvaluator.FragmentEventType; } eventStreamParentViewableActivators[i] = services.ViewableActivatorFactory.CreateNamedWindow(processor, namedSpec, statementContext); services.NamedWindowConsumerMgmtService.AddConsumer(statementContext, namedSpec); unmaterializedViewChain[i] = services.ViewService.CreateFactories( i, namedWindowType, namedSpec.ViewSpecs, namedSpec.Options, statementContext, false, -1); joinAnalysisResult.SetNamedWindow(i); eventTypeNames[i] = namedSpec.WindowName; isNamedWindow[i] = true; // Consumers to named windows cannot declare a data window view onto the named window to avoid duplicate remove streams EPStatementStartMethodHelperValidate.ValidateNoDataWindowOnNamedWindow( unmaterializedViewChain[i].FactoryChain); } else { throw new ExprValidationException("Unknown stream specification type: " + streamSpec); } } // handle match-recognize pattern if (statementSpec.MatchRecognizeSpec != null) { if (isJoin) { throw new ExprValidationException("Joins are not allowed when using match-recognize"); } if (joinAnalysisResult.TablesPerStream[0] != null) { throw new ExprValidationException("Tables cannot be used with match-recognize"); } var isUnbound = (unmaterializedViewChain[0].FactoryChain.IsEmpty()) && (!(statementSpec.StreamSpecs[0] is NamedWindowConsumerStreamSpec)); var factory = services.RegexHandlerFactory.MakeViewFactory( unmaterializedViewChain[0], statementSpec.MatchRecognizeSpec, defaultAgentInstanceContext, isUnbound, statementSpec.Annotations, services.ConfigSnapshot.EngineDefaults.MatchRecognize); unmaterializedViewChain[0].FactoryChain.Add(factory); EPStatementStartMethodHelperAssignExpr.AssignAggregations( factory.AggregationService, factory.AggregationExpressions); } // Obtain event types from view factory chains var streamEventTypes = new EventType[statementSpec.StreamSpecs.Length]; for (var i = 0; i < unmaterializedViewChain.Length; i++) { streamEventTypes[i] = unmaterializedViewChain[i].EventType; } // Add uniqueness information useful for joins joinAnalysisResult.AddUniquenessInfo(unmaterializedViewChain, statementSpec.Annotations); // Validate sub-select views var subSelectStrategyCollection = EPStatementStartMethodHelperSubselect.PlanSubSelect( services, statementContext, queryPlanLogging, subSelectStreamDesc, streamNames, streamEventTypes, eventTypeNames, statementSpec.DeclaredExpressions, contextPropertyRegistry); // Construct type information per stream var typeService = new StreamTypeServiceImpl( streamEventTypes, streamNames, EPStatementStartMethodHelperUtil.GetHasIStreamOnly(isNamedWindow, unmaterializedViewChain), services.EngineURI, false); var viewResourceDelegateUnverified = new ViewResourceDelegateUnverified(); // Validate views that require validation, specifically streams that don't have // sub-views such as DB SQL joins var historicalViewableDesc = new HistoricalViewableDesc(numStreams); for (var stream = 0; stream < historicalEventViewables.Length; stream++) { var historicalEventViewable = historicalEventViewables[stream]; if (historicalEventViewable == null) { continue; } historicalEventViewable.Validate( services.EngineImportService, typeService, statementContext.TimeProvider, statementContext.VariableService, statementContext.TableService, statementContext.ScriptingService, evaluatorContextStmt, services.ConfigSnapshot, services.SchedulingService, services.EngineURI, statementSpec.SqlParameters, statementContext.EventAdapterService, statementContext); historicalViewableDesc.SetHistorical(stream, historicalEventViewable.RequiredStreams); if (historicalEventViewable.RequiredStreams.Contains(stream)) { throw new ExprValidationException( "Parameters for historical stream " + stream + " indicate that the stream is subordinate to itself as stream parameters originate in the same stream"); } } // unidirectional is not supported with into-table if (joinAnalysisResult.IsUnidirectional && statementSpec.IntoTableSpec != null) { throw new ExprValidationException("Into-table does not allow unidirectional joins"); } // Construct a processor for results posted by views and joins, which takes care of aggregation if required. // May return null if we don't need to post-process results posted by views or joins. var resultSetProcessorPrototypeDesc = ResultSetProcessorFactoryFactory.GetProcessorPrototype( statementSpec, statementContext, typeService, viewResourceDelegateUnverified, joinAnalysisResult.UnidirectionalInd, true, contextPropertyRegistry, selectExprProcessorDeliveryCallback, services.ConfigSnapshot, services.ResultSetProcessorHelperFactory, false, false); // Validate where-clause filter tree, outer join clause and output limit expression EPStatementStartMethodHelperValidate.ValidateNodes( statementSpec, statementContext, typeService, viewResourceDelegateUnverified); // Handle 'prior' function nodes in terms of view requirements var viewResourceDelegateVerified = EPStatementStartMethodHelperViewResources.VerifyPreviousAndPriorRequirements( unmaterializedViewChain, viewResourceDelegateUnverified); // handle join JoinSetComposerPrototype joinSetComposerPrototype = null; if (numStreams > 1) { var selectsRemoveStream = statementSpec.SelectStreamSelectorEnum.IsSelectsRStream() || statementSpec.OutputLimitSpec != null; var hasAggregations = !resultSetProcessorPrototypeDesc.AggregationServiceFactoryDesc.Expressions.IsEmpty(); joinSetComposerPrototype = JoinSetComposerPrototypeFactory.MakeComposerPrototype( statementContext.StatementName, statementContext.StatementId, statementSpec.OuterJoinDescList, statementSpec.FilterRootNode, typeService.EventTypes, streamNames, joinAnalysisResult, queryPlanLogging, statementContext, historicalViewableDesc, defaultAgentInstanceContext, selectsRemoveStream, hasAggregations, services.TableService, false, services.EventTableIndexService.AllowInitIndex(recoveringResilient)); } // obtain factory for output limiting var outputViewFactory = OutputProcessViewFactoryFactory.Make( statementSpec, services.InternalEventRouter, statementContext, resultSetProcessorPrototypeDesc.ResultSetProcessorFactory.ResultEventType, optionalOutputProcessViewCallback, services.TableService, resultSetProcessorPrototypeDesc.ResultSetProcessorFactory.ResultSetProcessorType, services.ResultSetProcessorHelperFactory, services.StatementVariableRefService); // Factory for statement-context instances var factoryX = new StatementAgentInstanceFactorySelect( numStreams, eventStreamParentViewableActivators, statementContext, statementSpec, services, typeService, unmaterializedViewChain, resultSetProcessorPrototypeDesc, joinAnalysisResult, recoveringResilient, joinSetComposerPrototype, subSelectStrategyCollection, viewResourceDelegateVerified, outputViewFactory); var stopMethod = new EPStatementStopMethodImpl(statementContext, stopCallbacks); return(new EPStatementStartMethodSelectDesc( factoryX, subSelectStrategyCollection, viewResourceDelegateUnverified, resultSetProcessorPrototypeDesc, stopMethod, destroyCallbacks)); }
public static EventTypeForgeablesPair MakeJsonTypeCompileTimeNewType( EventTypeMetadata metadata, IDictionary <string, object> compiledTyping, Pair <EventType[], ISet <EventType> > superTypes, ConfigurationCommonEventTypeWithSupertype config, StatementRawInfo raw, StatementCompileTimeServices services) { if (metadata.ApplicationType != EventTypeApplicationType.JSON) { throw new IllegalStateException("Expected Json application type"); } // determine supertype var optionalSuperType = (JsonEventType) (superTypes == null ? null : (superTypes.First == null || superTypes.First.Length == 0 ? null : superTypes.First[0])); var numFieldsSuperType = optionalSuperType?.Detail.FieldDescriptors.Count ?? 0; // determine dynamic var jsonSchema = (JsonSchemaAttribute)AnnotationUtil.FindAnnotation(raw.Annotations, typeof(JsonSchemaAttribute)); var dynamic = DetermineDynamic(jsonSchema, optionalSuperType, raw); // determine json underlying type class var optionalUnderlyingProvided = DetermineUnderlyingProvided(jsonSchema, services); // determine properties IDictionary <string, object> properties; IDictionary <string, string> fieldNames; IDictionary <Type, JsonApplicationClassSerializationDesc> deepClasses; IDictionary <string, FieldInfo> fields; if (optionalUnderlyingProvided == null) { properties = ResolvePropertyTypes(compiledTyping, services.EventTypeCompileTimeResolver); properties = RemoveEventBeanTypes(properties); fieldNames = ComputeFieldNames(properties); deepClasses = JsonEventTypeUtilityReflective.ComputeClassesDeep(properties, metadata.Name, raw.Annotations, services); fields = EmptyDictionary <string, FieldInfo> .Instance; } else { if (dynamic) { throw new ExprValidationException("The dynamic flag is not supported when used with a provided JSON event class"); } if (optionalSuperType != null) { throw new ExprValidationException("Specifying a supertype is not supported with a provided JSON event class"); } if (!optionalUnderlyingProvided.IsPublic && !optionalUnderlyingProvided.IsNestedPublic) { throw new ExprValidationException("Provided JSON event class is not public"); } if (!optionalUnderlyingProvided.HasDefaultConstructor()) { throw new ExprValidationException("Provided JSON event class does not have a public default constructor or is a non-static inner class"); } deepClasses = JsonEventTypeUtilityReflective.ComputeClassesDeep(optionalUnderlyingProvided, metadata.Name, raw.Annotations, services); fields = new LinkedHashMap <string, FieldInfo>(); deepClasses.Get(optionalUnderlyingProvided).Fields.ForEach(field => fields.Put(field.Name, field)); properties = ResolvePropertiesFromFields(fields); fieldNames = ComputeFieldNamesFromProperties(properties); compiledTyping = ResolvePropertyTypes(compiledTyping, services.EventTypeCompileTimeResolver); ValidateFieldTypes(optionalUnderlyingProvided, fields, compiledTyping); // use the rich-type definition for properties that may come from events foreach (var compiledTypingEntry in compiledTyping) { if (compiledTypingEntry.Value is TypeBeanOrUnderlying || compiledTypingEntry.Value is TypeBeanOrUnderlying[]) { properties.Put(compiledTypingEntry.Key, compiledTypingEntry.Value); } } } var fieldDescriptors = ComputeFields(properties, fieldNames, optionalSuperType, fields); // Computes a forge for each property presented. var forgesByProperty = ComputeValueForges(properties, fields, deepClasses, raw.Annotations, services); // Determines a name for the internal class representation for this json event. var jsonClassNameSimple = DetermineJsonClassName(metadata, raw, optionalUnderlyingProvided); var forgeableDesc = new StmtClassForgeableJsonDesc(properties, fieldDescriptors, dynamic, numFieldsSuperType, optionalSuperType, forgesByProperty); var underlyingClassNameSimple = jsonClassNameSimple; var underlyingClassNameForReference = optionalUnderlyingProvided != null ? optionalUnderlyingProvided.Name : underlyingClassNameSimple; var underlyingClassNameFull = optionalUnderlyingProvided == null ? $"{services.Namespace}.{underlyingClassNameSimple}" : optionalUnderlyingProvided.FullName; var underlying = new ProxyStmtClassForgeableFactory() { ProcMake = ( namespaceScope, classPostfix) => new StmtClassForgeableJsonUnderlying( underlyingClassNameSimple, underlyingClassNameFull, namespaceScope, forgeableDesc) }; var delegateClassNameSimple = jsonClassNameSimple + "__Delegate"; var @delegate = new ProxyStmtClassForgeableFactory() { ProcMake = ( namespaceScope, classPostfix) => new StmtClassForgeableJsonDelegate( CodegenClassType.JSONDELEGATE, delegateClassNameSimple, namespaceScope, underlyingClassNameFull, forgeableDesc) }; var deserializerClassNameSimple = jsonClassNameSimple + "__Deserializer"; var deserializer = new ProxyStmtClassForgeableFactory() { ProcMake = ( namespaceScope, classPostfix) => new StmtClassForgeableJsonDeserializer( CodegenClassType.JSONDESERIALIZER, deserializerClassNameSimple, namespaceScope, underlyingClassNameFull, forgeableDesc) }; var serializerClassNameSimple = jsonClassNameSimple + "__Serializer"; var serializer = new ProxyStmtClassForgeableFactory() { ProcMake = ( namespaceScope, classPostfix) => new StmtClassForgeableJsonSerializer( CodegenClassType.JSONSERIALIZER, serializerClassNameSimple, optionalUnderlyingProvided != null, namespaceScope, underlyingClassNameFull, forgeableDesc) }; var serializerClassNameFull = $"{services.Namespace}.{serializerClassNameSimple}"; var deserializerClassNameFull = $"{services.Namespace}.{deserializerClassNameSimple}"; var delegateClassNameFull = $"{services.Namespace}.{delegateClassNameSimple}"; // include event type name as underlying-class may occur multiple times var serdeClassNameFull = $"{services.Namespace}.{jsonClassNameSimple}__{metadata.Name}__Serde"; var detail = new JsonEventTypeDetail( underlyingClassNameFull, optionalUnderlyingProvided, delegateClassNameFull, deserializerClassNameFull, serializerClassNameFull, serdeClassNameFull, fieldDescriptors, dynamic, numFieldsSuperType); var getterFactoryJson = new EventTypeNestableGetterFactoryJson(detail); var isStandIn = optionalUnderlyingProvided == null; var standIn = isStandIn ? services.CompilerServices.CompileStandInClass(CodegenClassType.JSONEVENT, underlyingClassNameSimple, services.Services) : optionalUnderlyingProvided; var eventType = new JsonEventType( metadata, properties, superTypes == null ? new EventType[0] : superTypes.First, superTypes == null ? EmptySet <EventType> .Instance : superTypes.Second, config?.StartTimestampPropertyName, config?.EndTimestampPropertyName, getterFactoryJson, services.BeanEventTypeFactoryPrivate, detail, standIn, isStandIn); var additionalForgeables = new List <StmtClassForgeableFactory>(); // generate serializer, deserializer, and delegate forgeables for application classes GenerateApplicationClassForgables( optionalUnderlyingProvided, deepClasses, additionalForgeables, raw.Annotations, services); if (optionalUnderlyingProvided == null) { additionalForgeables.Add(underlying); } additionalForgeables.Add(@delegate); additionalForgeables.Add(deserializer); additionalForgeables.Add(serializer); return(new EventTypeForgeablesPair(eventType, additionalForgeables)); }
public static StmtForgeMethodSelectResult Make( IContainer container, bool dataflowOperator, string @namespace, string classPostfix, StatementBaseInfo @base, StatementCompileTimeServices services) { IList<FilterSpecCompiled> filterSpecCompileds = new List<FilterSpecCompiled>(); IList<ScheduleHandleCallbackProvider> scheduleHandleCallbackProviders = new List<ScheduleHandleCallbackProvider>(); IList<NamedWindowConsumerStreamSpec> namedWindowConsumers = new List<NamedWindowConsumerStreamSpec>(); var statementSpec = @base.StatementSpec; var streamNames = StatementForgeMethodSelectUtil.DetermineStreamNames(statementSpec.StreamSpecs); var numStreams = streamNames.Length; if (numStreams == 0) { throw new ExprValidationException("The from-clause is required but has not been specified"); } // first we create streams for subselects, if there are any var subselectActivation = SubSelectHelperActivations.CreateSubSelectActivation( filterSpecCompileds, namedWindowConsumers, @base, services); // verify for joins that required views are present var joinAnalysisResult = StatementForgeMethodSelectUtil.VerifyJoinViews( statementSpec, services.NamedWindowCompileTimeResolver); var streamEventTypes = new EventType[statementSpec.StreamSpecs.Length]; var eventTypeNames = new string[numStreams]; var isNamedWindow = new bool[numStreams]; var viewableActivatorForges = new ViewableActivatorForge[numStreams]; var viewForges = new IList<ViewFactoryForge>[numStreams]; var historicalEventViewables = new HistoricalEventViewableForge[numStreams]; for (var stream = 0; stream < numStreams; stream++) { var streamSpec = statementSpec.StreamSpecs[stream]; var isCanIterateUnbound = streamSpec.ViewSpecs.Length == 0 && (services.Configuration.Compiler.ViewResources.IsIterableUnbound || AnnotationUtil.FindAnnotation( statementSpec.Annotations, typeof(IterableUnboundAttribute)) != null); var args = new ViewFactoryForgeArgs( stream, false, -1, streamSpec.Options, null, @base.StatementRawInfo, services); if (dataflowOperator) { var dfResult = HandleDataflowActivation(args, streamSpec); streamEventTypes[stream] = dfResult.StreamEventType; eventTypeNames[stream] = dfResult.EventTypeName; viewableActivatorForges[stream] = dfResult.ViewableActivatorForge; viewForges[stream] = dfResult.ViewForges; } else if (streamSpec is FilterStreamSpecCompiled) { var filterStreamSpec = (FilterStreamSpecCompiled) statementSpec.StreamSpecs[stream]; var filterSpecCompiled = filterStreamSpec.FilterSpecCompiled; streamEventTypes[stream] = filterSpecCompiled.ResultEventType; eventTypeNames[stream] = filterStreamSpec.FilterSpecCompiled.FilterForEventTypeName; viewableActivatorForges[stream] = new ViewableActivatorFilterForge( filterSpecCompiled, isCanIterateUnbound, stream, false, -1); viewForges[stream] = ViewFactoryForgeUtil.CreateForges( streamSpec.ViewSpecs, args, streamEventTypes[stream]); filterSpecCompileds.Add(filterSpecCompiled); } else if (streamSpec is PatternStreamSpecCompiled) { var patternStreamSpec = (PatternStreamSpecCompiled) streamSpec; var forges = patternStreamSpec.Root.CollectFactories(); foreach (var forgeNode in forges) { forgeNode.CollectSelfFilterAndSchedule(filterSpecCompileds, scheduleHandleCallbackProviders); } var patternType = ViewableActivatorPatternForge.MakeRegisterPatternType( @base, stream, patternStreamSpec, services); var patternContext = new PatternContext(0, patternStreamSpec.MatchedEventMapMeta, false, -1, false); viewableActivatorForges[stream] = new ViewableActivatorPatternForge( patternType, patternStreamSpec, patternContext, isCanIterateUnbound); streamEventTypes[stream] = patternType; viewForges[stream] = ViewFactoryForgeUtil.CreateForges(streamSpec.ViewSpecs, args, patternType); } else if (streamSpec is NamedWindowConsumerStreamSpec) { var namedSpec = (NamedWindowConsumerStreamSpec) streamSpec; var namedWindow = services.NamedWindowCompileTimeResolver.Resolve(namedSpec.NamedWindow.EventType.Name); var namedWindowType = namedWindow.EventType; if (namedSpec.OptPropertyEvaluator != null) { namedWindowType = namedSpec.OptPropertyEvaluator.FragmentEventType; } var typesFilterValidation = new StreamTypeServiceImpl( namedWindowType, namedSpec.OptionalStreamName, false); var filterSingle = ExprNodeUtilityMake.ConnectExpressionsByLogicalAndWhenNeeded(namedSpec.FilterExpressions); var filterQueryGraph = EPLValidationUtil.ValidateFilterGetQueryGraphSafe( filterSingle, typesFilterValidation, @base.StatementRawInfo, services); namedWindowConsumers.Add(namedSpec); viewableActivatorForges[stream] = new ViewableActivatorNamedWindowForge( namedSpec, namedWindow, filterSingle, filterQueryGraph, true, namedSpec.OptPropertyEvaluator); streamEventTypes[stream] = namedWindowType; viewForges[stream] = Collections.GetEmptyList<ViewFactoryForge>(); joinAnalysisResult.SetNamedWindowsPerStream(stream, namedWindow); eventTypeNames[stream] = namedSpec.NamedWindow.EventType.Name; isNamedWindow[stream] = true; // Consumers to named windows cannot declare a data window view onto the named window to avoid duplicate remove streams viewForges[stream] = ViewFactoryForgeUtil.CreateForges(streamSpec.ViewSpecs, args, namedWindowType); EPStatementStartMethodHelperValidate.ValidateNoDataWindowOnNamedWindow(viewForges[stream]); } else if (streamSpec is TableQueryStreamSpec) { ValidateNoViews(streamSpec, "Table data"); var tableStreamSpec = (TableQueryStreamSpec) streamSpec; if (numStreams > 1 && tableStreamSpec.FilterExpressions.Count > 0) { throw new ExprValidationException( "Joins with tables do not allow table filter expressions, please add table filters to the where-clause instead"); } var table = tableStreamSpec.Table; EPLValidationUtil.ValidateContextName( true, table.TableName, table.OptionalContextName, statementSpec.Raw.OptionalContextName, false); var filter = ExprNodeUtilityMake.ConnectExpressionsByLogicalAndWhenNeeded(tableStreamSpec.FilterExpressions); viewableActivatorForges[stream] = new ViewableActivatorTableForge(table, filter); viewForges[stream] = Collections.GetEmptyList<ViewFactoryForge>(); eventTypeNames[stream] = tableStreamSpec.Table.TableName; streamEventTypes[stream] = tableStreamSpec.Table.InternalEventType; joinAnalysisResult.SetTablesForStream(stream, table); if (tableStreamSpec.Options.IsUnidirectional) { throw new ExprValidationException("Tables cannot be marked as unidirectional"); } if (tableStreamSpec.Options.IsRetainIntersection || tableStreamSpec.Options.IsRetainUnion) { throw new ExprValidationException("Tables cannot be marked with retain"); } } else if (streamSpec is DBStatementStreamSpec) { ValidateNoViews(streamSpec, "Historical data"); var sqlStreamSpec = (DBStatementStreamSpec) streamSpec; var typeConversionHook = (SQLColumnTypeConversion) ImportUtil.GetAnnotationHook( statementSpec.Annotations, HookType.SQLCOL, typeof(SQLColumnTypeConversion), services.ImportServiceCompileTime); var outputRowConversionHook = (SQLOutputRowConversion) ImportUtil.GetAnnotationHook( statementSpec.Annotations, HookType.SQLROW, typeof(SQLOutputRowConversion), services.ImportServiceCompileTime); var viewable = HistoricalEventViewableDatabaseForgeFactory.CreateDBStatementView( stream, sqlStreamSpec, typeConversionHook, outputRowConversionHook, @base, services, statementSpec.Annotations); streamEventTypes[stream] = viewable.EventType; viewForges[stream] = Collections.GetEmptyList<ViewFactoryForge>(); viewableActivatorForges[stream] = new ViewableActivatorHistoricalForge(viewable); historicalEventViewables[stream] = viewable; } else if (streamSpec is MethodStreamSpec) { ValidateNoViews(streamSpec, "Method data"); var methodStreamSpec = (MethodStreamSpec) streamSpec; var viewable = HistoricalEventViewableMethodForgeFactory.CreateMethodStatementView( stream, methodStreamSpec, @base, services); historicalEventViewables[stream] = viewable; streamEventTypes[stream] = viewable.EventType; viewForges[stream] = Collections.GetEmptyList<ViewFactoryForge>(); viewableActivatorForges[stream] = new ViewableActivatorHistoricalForge(viewable); historicalEventViewables[stream] = viewable; } else { throw new IllegalStateException("Unrecognized stream " + streamSpec); } } // handle match-recognize pattern if (statementSpec.Raw.MatchRecognizeSpec != null) { if (numStreams > 1) { throw new ExprValidationException("Joins are not allowed when using match-recognize"); } if (joinAnalysisResult.TablesPerStream[0] != null) { throw new ExprValidationException("Tables cannot be used with match-recognize"); } var isUnbound = viewForges[0].IsEmpty() && !(statementSpec.StreamSpecs[0] is NamedWindowConsumerStreamSpec); var eventType = viewForges[0].IsEmpty() ? streamEventTypes[0] : viewForges[0][(viewForges[0].Count - 1)].EventType; var desc = RowRecogNFAViewPlanUtil.ValidateAndPlan(container, eventType, isUnbound, @base, services); var factoryForge = new RowRecogNFAViewFactoryForge(desc); scheduleHandleCallbackProviders.Add(factoryForge); viewForges[0].Add(factoryForge); } // Obtain event types from view factory chains for (var i = 0; i < viewForges.Length; i++) { streamEventTypes[i] = viewForges[i].IsEmpty() ? streamEventTypes[i] : viewForges[i][(viewForges[i].Count - 1)].EventType; } // add unique-information to join analysis joinAnalysisResult.AddUniquenessInfo(viewForges, statementSpec.Annotations); // plan sub-selects var subselectForges = SubSelectHelperForgePlanner.PlanSubSelect( @base, subselectActivation, streamNames, streamEventTypes, eventTypeNames, services); DetermineViewSchedules(subselectForges, scheduleHandleCallbackProviders); // determine view schedules var viewResourceDelegateExpr = new ViewResourceDelegateExpr(); ViewFactoryForgeUtil.DetermineViewSchedules(viewForges, scheduleHandleCallbackProviders); var hasIStreamOnly = StatementForgeMethodSelectUtil.GetHasIStreamOnly(isNamedWindow, viewForges); var optionalStreamsIfAny = OuterJoinAnalyzer.OptionalStreamsIfAny(statementSpec.Raw.OuterJoinDescList); StreamTypeService typeService = new StreamTypeServiceImpl( streamEventTypes, streamNames, hasIStreamOnly, false, optionalStreamsIfAny); // Validate views that require validation, specifically streams that don't have // sub-views such as DB SQL joins var historicalViewableDesc = new HistoricalViewableDesc(numStreams); for (var stream = 0; stream < historicalEventViewables.Length; stream++) { var historicalEventViewable = historicalEventViewables[stream]; if (historicalEventViewable == null) { continue; } scheduleHandleCallbackProviders.Add(historicalEventViewable); historicalEventViewable.Validate(typeService, @base, services); historicalViewableDesc.SetHistorical(stream, historicalEventViewable.RequiredStreams); if (historicalEventViewable.RequiredStreams.Contains(stream)) { throw new ExprValidationException( "Parameters for historical stream " + stream + " indicate that the stream is subordinate to itself as stream parameters originate in the same stream"); } } // Validate where-clause filter tree, outer join clause and output limit expression var whereClauseValidated = EPStatementStartMethodHelperValidate.ValidateNodes( statementSpec.Raw, typeService, viewResourceDelegateExpr, @base.StatementRawInfo, services); var whereClauseForge = whereClauseValidated == null ? null : whereClauseValidated.Forge; // Obtain result set processor var resultSetProcessorDesc = ResultSetProcessorFactoryFactory.GetProcessorPrototype( new ResultSetSpec(statementSpec), typeService, viewResourceDelegateExpr, joinAnalysisResult.UnidirectionalInd, true, @base.ContextPropertyRegistry, false, false, @base.StatementRawInfo, services); // Handle 'prior' function nodes in terms of view requirements var viewResourceDelegateDesc = ViewResourceVerifyHelper.VerifyPreviousAndPriorRequirements(viewForges, viewResourceDelegateExpr); var hasPrior = ViewResourceDelegateDesc.HasPrior(viewResourceDelegateDesc); if (hasPrior) { for (var stream = 0; stream < numStreams; stream++) { if (!viewResourceDelegateDesc[stream].PriorRequests.IsEmpty()) { viewForges[stream] .Add( new PriorEventViewForge(viewForges[stream].IsEmpty(), streamEventTypes[stream])); } } } var outputProcessViewFactoryForge = OutputProcessViewForgeFactory.Make( typeService.EventTypes, resultSetProcessorDesc.ResultEventType, resultSetProcessorDesc.ResultSetProcessorType, statementSpec, @base.StatementRawInfo, services); outputProcessViewFactoryForge.CollectSchedules(scheduleHandleCallbackProviders); JoinSetComposerPrototypeForge joinForge = null; if (numStreams > 1) { var hasAggregations = !resultSetProcessorDesc.AggregationServiceForgeDesc.Expressions.IsEmpty(); joinForge = JoinSetComposerPrototypeForgeFactory.MakeComposerPrototype( statementSpec, joinAnalysisResult, typeService, historicalViewableDesc, false, hasAggregations, @base.StatementRawInfo, services); HandleIndexDependencies(joinForge.OptionalQueryPlan, services); } // plan table access var tableAccessForges = ExprTableEvalHelperPlan.PlanTableAccess(@base.StatementSpec.TableAccessNodes); ValidateTableAccessUse(statementSpec.Raw.IntoTableSpec, statementSpec.Raw.TableExpressions); if (joinAnalysisResult.IsUnidirectional && statementSpec.Raw.IntoTableSpec != null) { throw new ExprValidationException("Into-table does not allow unidirectional joins"); } var orderByWithoutOutputLimit = statementSpec.Raw.OrderByList != null && !statementSpec.Raw.OrderByList.IsEmpty() && statementSpec.Raw.OutputLimitSpec == null; var statementAIFactoryProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(StatementAIFactoryProvider), classPostfix); var resultSetProcessorProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(ResultSetProcessorFactoryProvider), classPostfix); var outputProcessViewProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(OutputProcessViewFactoryProvider), classPostfix); var statementProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementProvider), classPostfix); var statementFieldsClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementFields), classPostfix); //var statementFieldsClassName = namespaceScope.FieldsClassNameOptional; var forge = new StatementAgentInstanceFactorySelectForge( typeService.StreamNames, viewableActivatorForges, resultSetProcessorProviderClassName, viewForges, viewResourceDelegateDesc, whereClauseForge, joinForge, outputProcessViewProviderClassName, subselectForges, tableAccessForges, orderByWithoutOutputLimit, joinAnalysisResult.IsUnidirectional); var namespaceScope = new CodegenNamespaceScope( @namespace, statementFieldsClassName, services.IsInstrumented); var forgables = new List<StmtClassForgable>(); forgables.Add( new StmtClassForgableRSPFactoryProvider( resultSetProcessorProviderClassName, resultSetProcessorDesc, namespaceScope, @base.StatementRawInfo)); forgables.Add( new StmtClassForgableOPVFactoryProvider( outputProcessViewProviderClassName, outputProcessViewFactoryForge, namespaceScope, numStreams, @base.StatementRawInfo)); forgables.Add( new StmtClassForgableAIFactoryProviderSelect( statementAIFactoryProviderClassName, namespaceScope, forge)); forgables.Add( new StmtClassForgableStmtFields( statementFieldsClassName, namespaceScope, numStreams)); if (!dataflowOperator) { var informationals = StatementInformationalsUtil.GetInformationals( @base, filterSpecCompileds, scheduleHandleCallbackProviders, namedWindowConsumers, true, resultSetProcessorDesc.SelectSubscriberDescriptor, namespaceScope, services); forgables.Add( new StmtClassForgableStmtProvider( statementAIFactoryProviderClassName, statementProviderClassName, informationals, namespaceScope)); } var forgableResult = new StmtForgeMethodResult( forgables, filterSpecCompileds, scheduleHandleCallbackProviders, namedWindowConsumers, FilterSpecCompiled.MakeExprNodeList( filterSpecCompileds, Collections.GetEmptyList<FilterSpecParamExprNodeForge>())); return new StmtForgeMethodSelectResult(forgableResult, resultSetProcessorDesc.ResultEventType, numStreams); }