public SubSelectStrategyRealization Instantiate( EPServicesContext services, Viewable viewableRoot, AgentInstanceContext agentInstanceContext, IList <StopCallback> stopCallbackList, int subqueryNumber, bool isRecoveringResilient) { IList <ViewFactory> viewFactoryChain = _subSelectHolder.ViewFactoryChain.FactoryChain; // add "prior" view factory var hasPrior = _viewResourceDelegate.PerStream[0].PriorRequests != null && !_viewResourceDelegate.PerStream[0].PriorRequests.IsEmpty(); if (hasPrior) { var priorEventViewFactory = EPStatementStartMethodHelperPrior.GetPriorEventViewFactory( agentInstanceContext.StatementContext, 1024 + _subqueryNumber, viewFactoryChain.IsEmpty(), true, subqueryNumber); viewFactoryChain = new List <ViewFactory>(viewFactoryChain); viewFactoryChain.Add(priorEventViewFactory); } // create factory chain context to hold callbacks specific to "prior" and "prev" var viewFactoryChainContext = AgentInstanceViewFactoryChainContext.Create( viewFactoryChain, agentInstanceContext, _viewResourceDelegate.PerStream[0]); // make view var createResult = services.ViewService.CreateViews( viewableRoot, viewFactoryChain, viewFactoryChainContext, false); var subselectView = createResult.FinalViewable; // make aggregation service AggregationService aggregationService = null; if (_aggregationServiceFactory != null) { aggregationService = _aggregationServiceFactory.AggregationServiceFactory.MakeService( agentInstanceContext, agentInstanceContext.StatementContext.EngineImportService, true, subqueryNumber); } // handle "prior" nodes and their strategies var priorNodeStrategies = EPStatementStartMethodHelperPrior.CompilePriorNodeStrategies( _viewResourceDelegate, new AgentInstanceViewFactoryChainContext[] { viewFactoryChainContext }); // handle "previous" nodes and their strategies var previousNodeStrategies = EPStatementStartMethodHelperPrevious.CompilePreviousNodeStrategies( _viewResourceDelegate, new AgentInstanceViewFactoryChainContext[] { viewFactoryChainContext }); // handle aggregated and non-correlated queries: there is no strategy or index if (_aggregationServiceFactory != null && !_correlatedSubquery) { View aggregatorView; if (_groupKeys == null) { if (_filterExprEval == null) { aggregatorView = new SubselectAggregatorViewUnfilteredUngrouped( aggregationService, _filterExprEval, agentInstanceContext, null); } else { aggregatorView = new SubselectAggregatorViewFilteredUngrouped( aggregationService, _filterExprEval, agentInstanceContext, null, _filterExprNode); } } else { if (_filterExprEval == null) { aggregatorView = new SubselectAggregatorViewUnfilteredGrouped( aggregationService, _filterExprEval, agentInstanceContext, _groupKeys); } else { aggregatorView = new SubselectAggregatorViewFilteredGrouped( aggregationService, _filterExprEval, agentInstanceContext, _groupKeys, _filterExprNode); } } subselectView.AddView(aggregatorView); if (services.EventTableIndexService.AllowInitIndex(isRecoveringResilient)) { Preload(services, null, aggregatorView, agentInstanceContext); } return(new SubSelectStrategyRealization( NULL_ROW_STRATEGY, null, aggregationService, priorNodeStrategies, previousNodeStrategies, subselectView, null)); } // create index/holder table EventTable[] index = _pair.First.MakeEventTables( new EventTableFactoryTableIdentAgentInstanceSubq(agentInstanceContext, _subqueryNumber)); stopCallbackList.Add(new SubqueryStopCallback(index)); // create strategy SubordTableLookupStrategy strategy = _pair.Second.MakeStrategy(index, null); SubselectAggregationPreprocessorBase subselectAggregationPreprocessor = null; // handle unaggregated or correlated queries or if (_aggregationServiceFactory != null) { if (_groupKeys == null) { if (_filterExprEval == null) { subselectAggregationPreprocessor = new SubselectAggregationPreprocessorUnfilteredUngrouped( aggregationService, _filterExprEval, null); } else { subselectAggregationPreprocessor = new SubselectAggregationPreprocessorFilteredUngrouped( aggregationService, _filterExprEval, null); } } else { if (_filterExprEval == null) { subselectAggregationPreprocessor = new SubselectAggregationPreprocessorUnfilteredGrouped( aggregationService, _filterExprEval, _groupKeys); } else { subselectAggregationPreprocessor = new SubselectAggregationPreprocessorFilteredGrouped( aggregationService, _filterExprEval, _groupKeys); } } } // preload when allowed StatementAgentInstancePostLoad postLoad; if (services.EventTableIndexService.AllowInitIndex(isRecoveringResilient)) { Preload(services, index, subselectView, agentInstanceContext); postLoad = new ProxyStatementAgentInstancePostLoad() { ProcExecutePostLoad = () => Preload(services, index, subselectView, agentInstanceContext), ProcAcceptIndexVisitor = visitor => { foreach (var table in index) { visitor.Visit(table); } }, }; } else { postLoad = new ProxyStatementAgentInstancePostLoad { ProcExecutePostLoad = () => { // no post-load }, ProcAcceptIndexVisitor = visitor => { foreach (var table in index) { visitor.Visit(table); } }, }; } var bufferView = new BufferView(_subSelectHolder.StreamNumber); bufferView.Observer = new SubselectBufferObserver(index); subselectView.AddView(bufferView); return(new SubSelectStrategyRealization( strategy, subselectAggregationPreprocessor, aggregationService, priorNodeStrategies, previousNodeStrategies, subselectView, postLoad)); }
public SubSelectStrategyRealization Instantiate(EPServicesContext services, Viewable viewableRoot, AgentInstanceContext agentInstanceContext, IList <StopCallback> stopCallbackList) { var viewFactoryChain = _subSelectHolder.ViewFactoryChain.FactoryChain; // add "prior" view factory var hasPrior = _viewResourceDelegate.PerStream[0].PriorRequests != null && !_viewResourceDelegate.PerStream[0].PriorRequests.IsEmpty(); if (hasPrior) { var priorEventViewFactory = EPStatementStartMethodHelperPrior.GetPriorEventViewFactory(agentInstanceContext.StatementContext, 1024 + _subqueryNumber, viewFactoryChain.Count + 1, viewFactoryChain.IsEmpty()); viewFactoryChain = new List <ViewFactory>(viewFactoryChain); viewFactoryChain.Add(priorEventViewFactory); } // create factory chain context to hold callbacks specific to "prior" and "prev" var viewFactoryChainContext = AgentInstanceViewFactoryChainContext.Create(viewFactoryChain, agentInstanceContext, _viewResourceDelegate.PerStream[0]); var createResult = services.ViewService.CreateViews(viewableRoot, viewFactoryChain, viewFactoryChainContext, false); var subselectView = createResult.FinalViewable; // create index/holder table var index = _pair.First.MakeEventTables(); stopCallbackList.Add(new SubqueryStopCallback(index).Stop); // create strategy var strategy = _pair.Second.MakeStrategy(index, null); SubselectAggregationPreprocessorBase subselectAggregationPreprocessor = null; // handle "prior" nodes and their strategies var priorNodeStrategies = EPStatementStartMethodHelperPrior.CompilePriorNodeStrategies(_viewResourceDelegate, new AgentInstanceViewFactoryChainContext[] { viewFactoryChainContext }); // handle "previous" nodes and their strategies var previousNodeStrategies = EPStatementStartMethodHelperPrevious.CompilePreviousNodeStrategies(_viewResourceDelegate, new AgentInstanceViewFactoryChainContext[] { viewFactoryChainContext }); AggregationService aggregationService = null; if (_aggregationServiceFactory != null) { aggregationService = _aggregationServiceFactory.AggregationServiceFactory.MakeService(agentInstanceContext, agentInstanceContext.StatementContext.MethodResolutionService); if (!_correlatedSubquery) { View aggregatorView; if (_groupKeys == null) { if (_filterExprEval == null) { aggregatorView = new SubselectAggregatorViewUnfilteredUngrouped(aggregationService, _filterExprEval, agentInstanceContext, null); } else { aggregatorView = new SubselectAggregatorViewFilteredUngrouped(aggregationService, _filterExprEval, agentInstanceContext, null, _filterExprNode); } } else { if (_filterExprEval == null) { aggregatorView = new SubselectAggregatorViewUnfilteredGrouped(aggregationService, _filterExprEval, agentInstanceContext, _groupKeys); } else { aggregatorView = new SubselectAggregatorViewFilteredGrouped(aggregationService, _filterExprEval, agentInstanceContext, _groupKeys, _filterExprNode); } } subselectView.AddView(aggregatorView); Preload(services, null, aggregatorView, agentInstanceContext); return(new SubSelectStrategyRealization(NULL_ROW_STRATEGY, null, aggregationService, priorNodeStrategies, previousNodeStrategies, subselectView, null)); } else { if (_groupKeys == null) { if (_filterExprEval == null) { subselectAggregationPreprocessor = new SubselectAggregationPreprocessorUnfilteredUngrouped(aggregationService, _filterExprEval, null); } else { subselectAggregationPreprocessor = new SubselectAggregationPreprocessorFilteredUngrouped(aggregationService, _filterExprEval, null); } } else { if (_filterExprEval == null) { subselectAggregationPreprocessor = new SubselectAggregationPreprocessorUnfilteredGrouped(aggregationService, _filterExprEval, _groupKeys); } else { subselectAggregationPreprocessor = new SubselectAggregationPreprocessorFilteredGrouped(aggregationService, _filterExprEval, _groupKeys); } } } } // preload Preload(services, index, subselectView, agentInstanceContext); StatementAgentInstancePostLoad postLoad = new ProxyStatementAgentInstancePostLoad { ProcExecutePostLoad = () => Preload(services, index, subselectView, agentInstanceContext), ProcAcceptIndexVisitor = visitor => { foreach (var table in index) { visitor.Visit(table); } } }; var bufferView = new BufferView(_subSelectHolder.StreamNumber); bufferView.Observer = new SubselectBufferObserver(index); subselectView.AddView(bufferView); return(new SubSelectStrategyRealization(strategy, subselectAggregationPreprocessor, aggregationService, priorNodeStrategies, previousNodeStrategies, subselectView, postLoad)); }