public SubSelectStrategyRealization Instantiate( EPServicesContext services, Viewable viewableRoot, AgentInstanceContext agentInstanceContext, IList <StopCallback> stopCallbackList, int subqueryNumber, bool isRecoveringResilient) { SubselectAggregationPreprocessorBase subselectAggregationPreprocessor = null; AggregationService aggregationService = null; if (_aggregationServiceFactory != null) { aggregationService = _aggregationServiceFactory.AggregationServiceFactory.MakeService( agentInstanceContext, agentInstanceContext.StatementContext.EngineImportService, true, subqueryNumber); if (_groupByKeys == 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, _groupByKeys); } else { subselectAggregationPreprocessor = new SubselectAggregationPreprocessorFilteredGrouped( aggregationService, _filterExprEval, _groupByKeys); } } } SubordTableLookupStrategy subqueryLookup; if (_optionalNamedWindowProcessor != null) { NamedWindowProcessorInstance instance = _optionalNamedWindowProcessor.GetProcessorInstance(agentInstanceContext); if (_queryPlan == null) { if (instance.RootViewInstance.IsQueryPlanLogging && NamedWindowRootView.QueryPlanLog.IsInfoEnabled) { NamedWindowRootView.QueryPlanLog.Info("shared, full table scan"); } subqueryLookup = new SubordFullTableScanLookupStrategyLocking( instance.RootViewInstance.DataWindowContents, agentInstanceContext.EpStatementAgentInstanceHandle.StatementAgentInstanceLock); } else { EventTable[] tables = null; if (!_optionalNamedWindowProcessor.IsVirtualDataWindow) { tables = SubordinateQueryPlannerUtil.RealizeTables( _queryPlan.IndexDescs, instance.RootViewInstance.EventType, instance.RootViewInstance.IndexRepository, instance.RootViewInstance.DataWindowContents, agentInstanceContext, isRecoveringResilient); } SubordTableLookupStrategy strategy = _queryPlan.LookupStrategyFactory.MakeStrategy( tables, instance.RootViewInstance.VirtualDataWindow); subqueryLookup = new SubordIndexedTableLookupStrategyLocking( strategy, instance.TailViewInstance.AgentInstanceContext.AgentInstanceLock); } } else { TableStateInstance state = _tableService.GetState( _optionalTableMetadata.TableName, agentInstanceContext.AgentInstanceId); ILockable iLock = agentInstanceContext.StatementContext.IsWritesToTables ? state.TableLevelRWLock.WriteLock : state.TableLevelRWLock.ReadLock; if (_queryPlan == null) { subqueryLookup = new SubordFullTableScanTableLookupStrategy(iLock, state.IterableTableScan); } else { EventTable[] indexes = new EventTable[_queryPlan.IndexDescs.Length]; for (int i = 0; i < indexes.Length; i++) { indexes[i] = state.IndexRepository.GetIndexByDesc(_queryPlan.IndexDescs[i].IndexMultiKey); } subqueryLookup = _queryPlan.LookupStrategyFactory.MakeStrategy(indexes, null); subqueryLookup = new SubordIndexedTableLookupTableStrategy(subqueryLookup, iLock); } } return(new SubSelectStrategyRealization( subqueryLookup, subselectAggregationPreprocessor, aggregationService, Collections.GetEmptyMap <ExprPriorNode, ExprPriorEvalStrategy>(), Collections.GetEmptyMap <ExprPreviousNode, ExprPreviousEvalStrategy>(), null, null)); }
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)); }