public override void AssignExpressions(StatementAgentInstanceFactoryResult result) { var selectResult = (StatementAgentInstanceFactorySelectResult)result; EPStatementStartMethodHelperAssignExpr.AssignAggregations(selectResult.OptionalAggegationService, _resultSetProcessorFactoryDesc.AggregationServiceFactoryDesc.Expressions); EPStatementStartMethodHelperAssignExpr.AssignSubqueryStrategies(_subSelectStrategyCollection, result.SubselectStrategies); EPStatementStartMethodHelperAssignExpr.AssignPriorStrategies(result.PriorNodeStrategies); EPStatementStartMethodHelperAssignExpr.AssignPreviousStrategies(result.PreviousNodeStrategies); var matchRecognizeNodes = _viewResourceDelegate.PerStream[0].MatchRecognizePreviousRequests; EPStatementStartMethodHelperAssignExpr.AssignMatchRecognizePreviousStrategies(matchRecognizeNodes, result.RegexExprPreviousEvalStrategy); }
protected override StatementAgentInstanceFactoryResult NewContextInternal(AgentInstanceContext agentInstanceContext, bool isRecoveringResilient) { StopCallback stopCallback = new ProxyStopCallback(() => _services.VariableService.DeallocateVariableState(_variableMetaData.VariableName, agentInstanceContext.AgentInstanceId)); _services.VariableService.AllocateVariableState( _variableMetaData.VariableName, agentInstanceContext.AgentInstanceId, _statementContext.StatementExtensionServicesContext, isRecoveringResilient); CreateVariableView createView = new CreateVariableView( _statementContext.StatementId, _services.EventAdapterService, _services.VariableService, _createDesc.VariableName, _statementContext.StatementResultService, agentInstanceContext.AgentInstanceId); _services.VariableService.RegisterCallback(_createDesc.VariableName, agentInstanceContext.AgentInstanceId, createView.Update); _statementContext.StatementStopService.StatementStopped += () => _services.VariableService.UnregisterCallback(_createDesc.VariableName, 0, createView.Update); // Create result set processor, use wildcard selection _statementSpec.SelectClauseSpec.SetSelectExprList(new SelectClauseElementWildcard()); _statementSpec.SelectStreamDirEnum = SelectClauseStreamSelectorEnum.RSTREAM_ISTREAM_BOTH; var typeService = new StreamTypeServiceImpl(new EventType[] { createView.EventType }, new string[] { "create_variable" }, new bool[] { true }, _services.EngineURI, false); OutputProcessViewBase outputViewBase; try { ResultSetProcessorFactoryDesc resultSetProcessorPrototype = ResultSetProcessorFactoryFactory.GetProcessorPrototype( _statementSpec, _statementContext, typeService, null, new bool[0], true, ContextPropertyRegistryImpl.EMPTY_REGISTRY, null, _services.ConfigSnapshot, _services.ResultSetProcessorHelperFactory, false, false); ResultSetProcessor resultSetProcessor = EPStatementStartMethodHelperAssignExpr.GetAssignResultSetProcessor(agentInstanceContext, resultSetProcessorPrototype, false, null, false); // Attach output view OutputProcessViewFactory outputViewFactory = OutputProcessViewFactoryFactory.Make( _statementSpec, _services.InternalEventRouter, agentInstanceContext.StatementContext, resultSetProcessor.ResultEventType, null, _services.TableService, resultSetProcessorPrototype.ResultSetProcessorFactory.ResultSetProcessorType, _services.ResultSetProcessorHelperFactory, _services.StatementVariableRefService); outputViewBase = outputViewFactory.MakeView(resultSetProcessor, agentInstanceContext); createView.AddView(outputViewBase); } catch (ExprValidationException ex) { throw new EPException("Unexpected exception in create-variable context allocation: " + ex.Message, ex); } return(new StatementAgentInstanceFactoryCreateVariableResult(outputViewBase, stopCallback, agentInstanceContext)); }
public override void UnassignExpressions() { EPStatementStartMethodHelperAssignExpr.UnassignAggregations(_resultSetProcessorFactoryDesc.AggregationServiceFactoryDesc.Expressions); EPStatementStartMethodHelperAssignExpr.UnassignSubqueryStrategies(_subSelectStrategyCollection.Subqueries.Keys); for (var streamNum = 0; streamNum < _viewResourceDelegate.PerStream.Length; streamNum++) { var viewResourceStream = _viewResourceDelegate.PerStream[streamNum]; var callbacksPerIndex = viewResourceStream.PriorRequests; foreach (var priorItem in callbacksPerIndex) { EPStatementStartMethodHelperAssignExpr.UnassignPriorStrategies(priorItem.Value); } EPStatementStartMethodHelperAssignExpr.UnassignPreviousStrategies(viewResourceStream.PreviousRequests); } var matchRecognizeNodes = _viewResourceDelegate.PerStream[0].MatchRecognizePreviousRequests; EPStatementStartMethodHelperAssignExpr.UnassignMatchRecognizePreviousStrategies(matchRecognizeNodes); }
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) })); }
protected override StatementAgentInstanceFactoryResult NewContextInternal(AgentInstanceContext agentInstanceContext, bool isRecoveringResilient) { var stopCallbacks = new List <StopCallback>(); String windowName = _statementSpec.CreateWindowDesc.WindowName; Viewable finalView; Viewable eventStreamParentViewable; StatementAgentInstancePostLoad postLoad; Viewable topView; NamedWindowProcessorInstance processorInstance; ViewableActivationResult viewableActivationResult; try { // Register interest viewableActivationResult = _activator.Activate(agentInstanceContext, false, isRecoveringResilient); stopCallbacks.Add(viewableActivationResult.StopCallback); eventStreamParentViewable = viewableActivationResult.Viewable; // Obtain processor for this named window var processor = _services.NamedWindowMgmtService.GetProcessor(windowName); if (processor == null) { throw new Exception("Failed to obtain named window processor for named window '" + windowName + "'"); } // Allocate processor instance processorInstance = processor.AddInstance(agentInstanceContext); var rootView = processorInstance.RootViewInstance; eventStreamParentViewable.AddView(rootView); // Materialize views var viewFactoryChainContext = new AgentInstanceViewFactoryChainContext(agentInstanceContext, true, null, null); var createResult = _services.ViewService.CreateViews(rootView, _unmaterializedViewChain.FactoryChain, viewFactoryChainContext, false); topView = createResult.TopViewable; finalView = createResult.FinalViewable; // add views to stop callback if applicable StatementAgentInstanceFactorySelect.AddViewStopCallback(stopCallbacks, createResult.NewViews); // If this is a virtual data window implementation, bind it to the context for easy lookup StopCallback envStopCallback = null; if (finalView is VirtualDWView) { var objectName = "/virtualdw/" + windowName; var virtualDWView = (VirtualDWView)finalView; _services.EngineEnvContext.Bind(objectName, virtualDWView.VirtualDataWindow); envStopCallback = new ProxyStopCallback(() => { virtualDWView.Dispose(); _services.EngineEnvContext.Unbind(objectName); }); } StopCallback environmentStopCallback = envStopCallback; // Only if we are context-allocated: destroy the instance var contextName = processor.ContextName; var agentInstanceId = agentInstanceContext.AgentInstanceId; var allInOneStopMethod = new ProxyStopCallback(() => { var windowNameX = _statementSpec.CreateWindowDesc.WindowName; var processorX = _services.NamedWindowMgmtService.GetProcessor(windowNameX); if (processorX == null) { Log.Warn("Named window processor by name '" + windowNameX + "' has not been found"); } else { NamedWindowProcessorInstance instance = processorX.GetProcessorInstanceAllowUnpartitioned(agentInstanceId); if (instance != null) { if (contextName != null) { instance.Dispose(); } else { instance.Stop(); } } } if (environmentStopCallback != null) { environmentStopCallback.Stop(); } }); stopCallbacks.Add(allInOneStopMethod); // Attach tail view NamedWindowTailViewInstance tailView = processorInstance.TailViewInstance; finalView.AddView(tailView); finalView = tailView; // obtain result set processor ResultSetProcessor resultSetProcessor = EPStatementStartMethodHelperAssignExpr.GetAssignResultSetProcessor(agentInstanceContext, _resultSetProcessorPrototype, false, null, false); // Attach output view View outputView = _outputProcessViewFactory.MakeView(resultSetProcessor, agentInstanceContext); finalView.AddView(outputView); finalView = outputView; // obtain post load postLoad = processorInstance.PostLoad; // Handle insert case if (_statementSpec.CreateWindowDesc.IsInsert && !_isRecoveringStatement) { String insertFromWindow = _statementSpec.CreateWindowDesc.InsertFromWindow; NamedWindowProcessor namedWindowProcessor = _services.NamedWindowMgmtService.GetProcessor(insertFromWindow); NamedWindowProcessorInstance sourceWindowInstances = namedWindowProcessor.GetProcessorInstance(agentInstanceContext); IList <EventBean> events = new List <EventBean>(); if (_statementSpec.CreateWindowDesc.InsertFilter != null) { var eventsPerStream = new EventBean[1]; var filter = _statementSpec.CreateWindowDesc.InsertFilter.ExprEvaluator; for (IEnumerator <EventBean> it = sourceWindowInstances.TailViewInstance.GetEnumerator(); it.MoveNext();) { var candidate = it.Current; eventsPerStream[0] = candidate; var result = filter.Evaluate(new EvaluateParams(eventsPerStream, true, agentInstanceContext)); if ((result == null) || (false.Equals(result))) { continue; } events.Add(candidate); } } else { for (IEnumerator <EventBean> it = sourceWindowInstances.TailViewInstance.GetEnumerator(); it.MoveNext();) { events.Add(it.Current); } } if (events.Count > 0) { EventType rootViewType = rootView.EventType; EventBean[] convertedEvents = _services.EventAdapterService.TypeCast(events, rootViewType); rootView.Update(convertedEvents, null); } } } catch (Exception) { StopCallback callback = StatementAgentInstanceUtil.GetStopCallback(stopCallbacks, agentInstanceContext); StatementAgentInstanceUtil.StopSafe(callback, _statementContext); throw; } var createWindowResult = new StatementAgentInstanceFactoryCreateWindowResult( finalView, null, agentInstanceContext, eventStreamParentViewable, postLoad, topView, processorInstance, viewableActivationResult); if (_statementContext.StatementExtensionServicesContext != null) { _statementContext.StatementExtensionServicesContext.ContributeStopCallback(createWindowResult, stopCallbacks); } Log.Debug(".start Statement start completed"); StopCallback stopCallback = StatementAgentInstanceUtil.GetStopCallback(stopCallbacks, agentInstanceContext); createWindowResult.StopCallback = stopCallback; return(createWindowResult); }
public override void UnassignExpressions() { EPStatementStartMethodHelperAssignExpr.AssignAggregations(null, _resultSetProcessorFactoryDesc.AggregationServiceFactoryDesc.Expressions); }
public override void AssignExpressions(StatementAgentInstanceFactoryResult result) { StatementAgentInstanceFactorySelectResult selectResult = (StatementAgentInstanceFactorySelectResult)result; EPStatementStartMethodHelperAssignExpr.AssignAggregations(selectResult.OptionalAggegationService, _resultSetProcessorFactoryDesc.AggregationServiceFactoryDesc.Expressions); }