public override EPStatementStartResult StartInternal( EPServicesContext services, StatementContext statementContext, bool isNewStatement, bool isRecoveringStatement, bool isRecoveringResilient) { var expressionName = services.ExprDeclaredService.AddExpressionOrScript(StatementSpec.CreateExpressionDesc); // define output event type var typeName = "EventType_Expression_" + expressionName; var resultType = services.EventAdapterService.CreateAnonymousMapType( typeName, Collections.GetEmptyMap <String, Object>(), true); var stopMethod = new ProxyEPStatementStopMethod( () => { // no action }); var destroyMethod = new ProxyEPStatementDestroyMethod( () => services.ExprDeclaredService.DestroyedExpression(StatementSpec.CreateExpressionDesc)); Viewable resultView = new ZeroDepthStreamNoIterate(resultType); statementContext.StatementAgentInstanceFactory = new StatementAgentInstanceFactoryNoAgentInstance(resultView); return(new EPStatementStartResult(resultView, stopMethod, destroyMethod)); }
public override EPStatementStartResult StartInternal(EPServicesContext services, StatementContext statementContext, bool isNewStatement, bool isRecoveringStatement, bool isRecoveringResilient) { var createGraphDesc = StatementSpec.CreateGraphDesc; var agentInstanceContext = GetDefaultAgentInstanceContext(statementContext); // define output event type var typeName = "EventType_Graph_" + createGraphDesc.GraphName; var resultType = services.EventAdapterService.CreateAnonymousMapType(typeName, Collections.GetEmptyMap <String, Object>(), true); services.DataFlowService.AddStartGraph(createGraphDesc, statementContext, services, agentInstanceContext, isNewStatement); var stopMethod = new ProxyEPStatementStopMethod(() => services.DataFlowService.StopGraph(createGraphDesc.GraphName)); var destroyMethod = new ProxyEPStatementDestroyMethod(() => services.DataFlowService.RemoveGraph(createGraphDesc.GraphName)); var resultView = new ZeroDepthStreamNoIterate(resultType); statementContext.StatementAgentInstanceFactory = new StatementAgentInstanceFactoryNoAgentInstance(resultView); return(new EPStatementStartResult(resultView, stopMethod, destroyMethod)); }
public override EPStatementStartResult StartInternal( EPServicesContext services, StatementContext statementContext, bool isNewStatement, bool isRecoveringStatement, bool isRecoveringResilient) { if (_statementSpec.OptionalContextName != null) { throw new ExprValidationException("A create-context statement cannot itself be associated to a context, please declare a nested context instead"); } var context = _statementSpec.ContextDesc; var agentInstanceContext = GetDefaultAgentInstanceContext(statementContext); // compile filter specs, if any ISet <string> eventTypesReferenced = new HashSet <string>(); ValidateContextDetail(services, statementContext, eventTypesReferenced, context.ContextDetail, agentInstanceContext); services.StatementEventTypeRefService.AddReferences(statementContext.StatementName, CollectionUtil.ToArray(eventTypesReferenced)); // define output event type var typeName = "EventType_Context_" + context.ContextName; var statementResultEventType = services.EventAdapterService.CreateAnonymousMapType(typeName, Collections.GetEmptyMap <string, object>(), true); // add context - does not activate that context services.ContextManagementService.AddContextSpec(services, agentInstanceContext, context, isRecoveringResilient, statementResultEventType); EPStatementStopMethod stopMethod = new ProxyEPStatementStopMethod(() => { // no action }); EPStatementDestroyMethod destroyMethod = new ProxyEPStatementDestroyMethod(() => services.ContextManagementService.DestroyedContext(context.ContextName)); return(new EPStatementStartResult(new ZeroDepthStreamNoIterate(statementResultEventType), stopMethod, destroyMethod)); }
public override EPStatementStartResult StartInternal( EPServicesContext services, StatementContext statementContext, bool isNewStatement, bool isRecoveringStatement, bool isRecoveringResilient) { // define stop var stopCallbacks = new List <StopCallback>(); // determine context var contextName = _statementSpec.OptionalContextName; // Create view factories and parent view based on a filter specification // Since only for non-joins we get the existing stream's lock and try to reuse it's views var filterStreamSpec = (FilterStreamSpecCompiled)_statementSpec.StreamSpecs[0]; InstrumentationAgent instrumentationAgentCreateWindowInsert = null; if (InstrumentationHelper.ENABLED) { var eventTypeName = filterStreamSpec.FilterSpec.FilterForEventType.Name; instrumentationAgentCreateWindowInsert = new ProxyInstrumentationAgent() { ProcIndicateQ = () => InstrumentationHelper.Get().QFilterActivationNamedWindowInsert(eventTypeName), ProcIndicateA = () => InstrumentationHelper.Get().AFilterActivationNamedWindowInsert(), }; } var activator = services.ViewableActivatorFactory.CreateFilterProxy(services, filterStreamSpec.FilterSpec, statementContext.Annotations, false, instrumentationAgentCreateWindowInsert, false, 0); // create data window view factories var unmaterializedViewChain = services.ViewService.CreateFactories(0, filterStreamSpec.FilterSpec.ResultEventType, filterStreamSpec.ViewSpecs, filterStreamSpec.Options, statementContext, false, -1); // verify data window VerifyDataWindowViewFactoryChain(unmaterializedViewChain.FactoryChain); // get processor for variant-streams and versioned typed var windowName = _statementSpec.CreateWindowDesc.WindowName; var optionalRevisionProcessor = statementContext.ValueAddEventService.GetValueAddProcessor(windowName); // add named window processor (one per named window for all agent instances) var isPrioritized = services.EngineSettingsService.EngineSettings.ExecutionConfig.IsPrioritized; var isEnableSubqueryIndexShare = HintEnum.ENABLE_WINDOW_SUBQUERY_INDEXSHARE.GetHint(_statementSpec.Annotations) != null; if (!isEnableSubqueryIndexShare && unmaterializedViewChain.FactoryChain[0] is VirtualDWViewFactory) { isEnableSubqueryIndexShare = true; // index share is always enabled for virtual data window (otherwise it wouldn't make sense) } var isBatchingDataWindow = DetermineBatchingDataWindow(unmaterializedViewChain.FactoryChain); var virtualDataWindowFactory = DetermineVirtualDataWindow(unmaterializedViewChain.FactoryChain); var optionalUniqueKeyProps = ViewServiceHelper.GetUniqueCandidateProperties(unmaterializedViewChain.FactoryChain, _statementSpec.Annotations); var processor = services.NamedWindowMgmtService.AddProcessor( windowName, contextName, filterStreamSpec.FilterSpec.ResultEventType, statementContext.StatementResultService, optionalRevisionProcessor, statementContext.Expression, statementContext.StatementName, isPrioritized, isEnableSubqueryIndexShare, isBatchingDataWindow, virtualDataWindowFactory != null, optionalUniqueKeyProps, _statementSpec.CreateWindowDesc.AsEventTypeName, statementContext, services.NamedWindowDispatchService); Viewable finalViewable; EPStatementStopMethod stopStatementMethod; EPStatementDestroyMethod destroyStatementMethod; try { // add stop callback stopCallbacks.Add(new ProxyStopCallback(() => { services.NamedWindowMgmtService.RemoveProcessor(windowName); if (virtualDataWindowFactory != null) { virtualDataWindowFactory.DestroyNamedWindow(); } })); // Add a wildcard to the select clause as subscribers received the window contents _statementSpec.SelectClauseSpec.SetSelectExprList(new SelectClauseElementWildcard()); _statementSpec.SelectStreamDirEnum = SelectClauseStreamSelectorEnum.RSTREAM_ISTREAM_BOTH; // obtain result set processor factory StreamTypeService typeService = new StreamTypeServiceImpl(new EventType[] { processor.NamedWindowType }, new string[] { windowName }, new bool[] { true }, services.EngineURI, false); var resultSetProcessorPrototype = ResultSetProcessorFactoryFactory.GetProcessorPrototype( _statementSpec, statementContext, typeService, null, new bool[0], true, null, null, services.ConfigSnapshot, services.ResultSetProcessorHelperFactory, false, false); // obtain factory for output limiting var outputViewFactory = OutputProcessViewFactoryFactory.Make( _statementSpec, services.InternalEventRouter, statementContext, resultSetProcessorPrototype.ResultSetProcessorFactory.ResultEventType, null, services.TableService, resultSetProcessorPrototype.ResultSetProcessorFactory.ResultSetProcessorType, services.ResultSetProcessorHelperFactory, services.StatementVariableRefService); // create context factory // Factory for statement-context instances var contextFactory = new StatementAgentInstanceFactoryCreateWindow(statementContext, _statementSpec, services, activator, unmaterializedViewChain, resultSetProcessorPrototype, outputViewFactory, isRecoveringStatement); statementContext.StatementAgentInstanceFactory = contextFactory; // With context - delegate instantiation to context EPStatementStopMethod stopMethod = new EPStatementStopMethodImpl(statementContext, stopCallbacks); if (_statementSpec.OptionalContextName != null) { var mergeView = new ContextMergeView(processor.NamedWindowType); finalViewable = mergeView; var statement = new ContextManagedStatementCreateWindowDesc(_statementSpec, statementContext, mergeView, contextFactory); services.ContextManagementService.AddStatement(contextName, statement, isRecoveringResilient); stopStatementMethod = new ProxyEPStatementStopMethod(() => { services.ContextManagementService.StoppedStatement(contextName, statementContext.StatementName, statementContext.StatementId, statementContext.Expression, statementContext.ExceptionHandlingService); stopMethod.Stop(); }); destroyStatementMethod = new ProxyEPStatementDestroyMethod(() => services.ContextManagementService.DestroyedStatement(contextName, statementContext.StatementName, statementContext.StatementId)); } // Without context - start here else { var agentInstanceContext = GetDefaultAgentInstanceContext(statementContext); StatementAgentInstanceFactoryCreateWindowResult resultOfStart; try { resultOfStart = (StatementAgentInstanceFactoryCreateWindowResult)contextFactory.NewContext(agentInstanceContext, isRecoveringResilient); } catch (Exception) { services.NamedWindowMgmtService.RemoveProcessor(windowName); throw; } finalViewable = resultOfStart.FinalView; var stopCallback = services.EpStatementFactory.MakeStopMethod(resultOfStart); stopStatementMethod = new ProxyEPStatementStopMethod(() => { stopCallback.Stop(); stopMethod.Stop(); }); destroyStatementMethod = null; if (statementContext.StatementExtensionServicesContext != null && statementContext.StatementExtensionServicesContext.StmtResources != null) { var holder = statementContext.StatementExtensionServicesContext.ExtractStatementResourceHolder(resultOfStart); statementContext.StatementExtensionServicesContext.StmtResources.Unpartitioned = holder; statementContext.StatementExtensionServicesContext.PostProcessStart(resultOfStart, isRecoveringResilient); } } } catch (ExprValidationException) { services.NamedWindowMgmtService.RemoveProcessor(windowName); throw; } catch (Exception) { services.NamedWindowMgmtService.RemoveProcessor(windowName); throw; } services.StatementVariableRefService.AddReferences(statementContext.StatementName, windowName); return(new EPStatementStartResult(finalViewable, stopStatementMethod, destroyStatementMethod)); }
public override EPStatementStartResult StartInternal(EPServicesContext services, StatementContext statementContext, bool isNewStatement, bool isRecoveringStatement, bool isRecoveringResilient) { var createDesc = _statementSpec.CreateTableDesc; // determine whether already declared VariableServiceUtil.CheckAlreadyDeclaredVariable(createDesc.TableName, services.VariableService); if (isNewStatement) { VariableServiceUtil.CheckAlreadyDeclaredTable(createDesc.TableName, services.TableService); } if (services.EventAdapterService.GetEventTypeByName(createDesc.TableName) != null) { throw new ExprValidationException("An event type or schema by name '" + createDesc.TableName + "' already exists"); } // Determine event type names var internalTypeName = "table_" + createDesc.TableName + "__internal"; var publicTypeName = "table_" + createDesc.TableName + "__public"; TableMetadata metadata; try { // determine key types var keyTypes = GetKeyTypes(createDesc.Columns, services.EngineImportService); // check column naming, interpret annotations var columnDescs = ValidateExpressions(createDesc.Columns, services, statementContext); // analyze and plan the state holders var plan = AnalyzePlanAggregations(createDesc.TableName, statementContext, columnDescs, services, internalTypeName, publicTypeName); var tableStateRowFactory = plan.StateRowFactory; // register new table var queryPlanLogging = services.ConfigSnapshot.EngineDefaults.Logging.IsEnableQueryPlan; metadata = services.TableService.AddTable(createDesc.TableName, statementContext.Expression, statementContext.StatementName, keyTypes, plan.TableColumns, tableStateRowFactory, plan.NumberMethodAggregations, statementContext, plan.InternalEventType, plan.PublicEventType, plan.EventToPublic, queryPlanLogging); } catch (ExprValidationException ex) { services.EventAdapterService.RemoveType(internalTypeName); services.EventAdapterService.RemoveType(publicTypeName); throw ex; } // allocate context factory var contextFactory = new StatementAgentInstanceFactoryCreateTable(metadata); statementContext.StatementAgentInstanceFactory = contextFactory; Viewable outputView; EPStatementStopMethod stopStatementMethod; EPStatementDestroyMethod destroyStatementMethod; if (_statementSpec.OptionalContextName != null) { var contextName = _statementSpec.OptionalContextName; var mergeView = new ContextMergeView(metadata.PublicEventType); outputView = mergeView; var statement = new ContextManagedStatementCreateAggregationVariableDesc(_statementSpec, statementContext, mergeView, contextFactory); services.ContextManagementService.AddStatement(_statementSpec.OptionalContextName, statement, isRecoveringResilient); stopStatementMethod = new ProxyEPStatementStopMethod(() => services.ContextManagementService.StoppedStatement( contextName, statementContext.StatementName, statementContext.StatementId, statementContext.Expression, statementContext.ExceptionHandlingService)); destroyStatementMethod = new ProxyEPStatementDestroyMethod(() => { services.ContextManagementService.DestroyedStatement(contextName, statementContext.StatementName, statementContext.StatementId); services.StatementVariableRefService.RemoveReferencesStatement(statementContext.StatementName); }); } else { var defaultAgentInstanceContext = GetDefaultAgentInstanceContext(statementContext); var result = contextFactory.NewContext(defaultAgentInstanceContext, false); if (statementContext.StatementExtensionServicesContext != null && statementContext.StatementExtensionServicesContext.StmtResources != null) { var holder = statementContext.StatementExtensionServicesContext.ExtractStatementResourceHolder(result); statementContext.StatementExtensionServicesContext.StmtResources.Unpartitioned = holder; } outputView = result.FinalView; stopStatementMethod = new ProxyEPStatementStopMethod(() => { }); destroyStatementMethod = new ProxyEPStatementDestroyMethod(() => services.StatementVariableRefService.RemoveReferencesStatement(statementContext.StatementName)); } services.StatementVariableRefService.AddReferences(statementContext.StatementName, createDesc.TableName); return(new EPStatementStartResult(outputView, stopStatementMethod, destroyStatementMethod)); }