/// <summary> /// Ctor. /// </summary> /// <param name="statementSpec">is a container for the definition of all statement constructs thatmay have been used in the statement, i.e. if defines the select clauses, insert into, outer joins etc. /// </param> /// <param name="services">is the service instances for dependency injection</param> /// <param name="statementContext">is statement-level information and statement services</param> /// <throws>com.espertech.esper.epl.expression.core.ExprValidationException if the preparation failed</throws> public EPPreparedExecuteIUDSingleStream( StatementSpecCompiled statementSpec, EPServicesContext services, StatementContext statementContext) { var queryPlanLogging = services.ConfigSnapshot.EngineDefaults.LoggingConfig.IsEnableQueryPlan; if (queryPlanLogging) { QueryPlanLog.Info("Query plans for Fire-and-forget query '" + statementContext.Expression + "'"); } HasTableAccess = statementSpec.IntoTableSpec != null || (statementSpec.TableNodes != null && statementSpec.TableNodes.Length > 0); if (statementSpec.InsertIntoDesc != null && services.TableService.GetTableMetadata(statementSpec.InsertIntoDesc.EventTypeName) != null) { HasTableAccess = true; } if (statementSpec.FireAndForgetSpec is FireAndForgetSpecUpdate || statementSpec.FireAndForgetSpec is FireAndForgetSpecDelete) { HasTableAccess |= statementSpec.StreamSpecs[0] is TableQueryStreamSpec; } StatementSpec = statementSpec; Services = services; StatementContext = statementContext; // validate general FAF criteria EPPreparedExecuteMethodHelper.ValidateFAFQuery(statementSpec); // obtain processor var streamSpec = statementSpec.StreamSpecs[0]; Processor = FireAndForgetProcessorFactory.ValidateResolveProcessor(streamSpec, services); // obtain name and type var processorName = Processor.NamedWindowOrTableName; var eventType = Processor.EventTypeResultSetProcessor; // determine alias var aliasName = processorName; if (streamSpec.OptionalStreamName != null) { aliasName = streamSpec.OptionalStreamName; } // compile filter to optimize access to named window var typeService = new StreamTypeServiceImpl(new EventType[] { eventType }, new string[] { aliasName }, new bool[] { true }, services.EngineURI, true); FilterSpecCompiled filter; if (statementSpec.FilterRootNode != null) { var tagged = new LinkedHashMap <string, Pair <EventType, string> >(); FilterSpecCompiled filterCompiled; try { filterCompiled = FilterSpecCompiler.MakeFilterSpec(eventType, aliasName, Collections.SingletonList(statementSpec.FilterRootNode), null, tagged, tagged, typeService, null, statementContext, Collections.SingletonList(0)); } catch (Exception ex) { Log.Warn("Unexpected exception analyzing filter paths: " + ex.Message, ex); filterCompiled = null; } filter = filterCompiled; } else { filter = null; } // validate expressions EPStatementStartMethodHelperValidate.ValidateNodes(statementSpec, statementContext, typeService, null); // get executor Executor = GetExecutor(filter, aliasName); }
/// <summary> /// Ctor. /// </summary> /// <param name="statementSpec">is a container for the definition of all statement constructs thatmay have been used in the statement, i.e. if defines the select clauses, insert into, outer joins etc. /// </param> /// <param name="services">is the service instances for dependency injection</param> /// <param name="statementContext">is statement-level information and statement services</param> /// <throws>ExprValidationException if the preparation failed</throws> public EPPreparedExecuteMethodQuery(StatementSpecCompiled statementSpec, EPServicesContext services, StatementContext statementContext) { var queryPlanLogging = services.ConfigSnapshot.EngineDefaults.LoggingConfig.IsEnableQueryPlan; if (queryPlanLogging) { QueryPlanLog.Info("Query plans for Fire-and-forget query '" + statementContext.Expression + "'"); } _hasTableAccess = (statementSpec.TableNodes != null && statementSpec.TableNodes.Length > 0); foreach (var streamSpec in statementSpec.StreamSpecs) { _hasTableAccess |= streamSpec is TableQueryStreamSpec; } _statementSpec = statementSpec; _services = services; EPPreparedExecuteMethodHelper.ValidateFAFQuery(statementSpec); var numStreams = statementSpec.StreamSpecs.Length; var typesPerStream = new EventType[numStreams]; var namesPerStream = new string[numStreams]; _processors = new FireAndForgetProcessor[numStreams]; _agentInstanceContext = new AgentInstanceContext(statementContext, null, -1, null, null, statementContext.DefaultAgentInstanceScriptContext); // resolve types and processors for (var i = 0; i < numStreams; i++) { var streamSpec = statementSpec.StreamSpecs[i]; _processors[i] = FireAndForgetProcessorFactory.ValidateResolveProcessor(streamSpec, services); string streamName = _processors[i].NamedWindowOrTableName; if (streamSpec.OptionalStreamName != null) { streamName = streamSpec.OptionalStreamName; } namesPerStream[i] = streamName; typesPerStream[i] = _processors[i].EventTypeResultSetProcessor; } // compile filter to optimize access to named window _filters = new FilterSpecCompiled[numStreams]; if (statementSpec.FilterRootNode != null) { var tagged = new LinkedHashMap <string, Pair <EventType, string> >(); for (var i = 0; i < numStreams; i++) { try { var types = new StreamTypeServiceImpl(typesPerStream, namesPerStream, new bool[numStreams], services.EngineURI, false); _filters[i] = FilterSpecCompiler.MakeFilterSpec(typesPerStream[i], namesPerStream[i], Collections.SingletonList(statementSpec.FilterRootNode), null, tagged, tagged, types, null, statementContext, Collections.SingletonList(i)); } catch (Exception ex) { Log.Warn("Unexpected exception analyzing filter paths: " + ex.Message, ex); } } } // obtain result set processor var isIStreamOnly = new bool[namesPerStream.Length]; CompatExtensions.Fill(isIStreamOnly, true); StreamTypeService typeService = new StreamTypeServiceImpl(typesPerStream, namesPerStream, isIStreamOnly, services.EngineURI, true); EPStatementStartMethodHelperValidate.ValidateNodes(statementSpec, statementContext, typeService, null); var resultSetProcessorPrototype = ResultSetProcessorFactoryFactory.GetProcessorPrototype(statementSpec, statementContext, typeService, null, new bool[0], true, ContextPropertyRegistryImpl.EMPTY_REGISTRY, null, _services.ConfigSnapshot); _resultSetProcessor = EPStatementStartMethodHelperAssignExpr.GetAssignResultSetProcessor(_agentInstanceContext, resultSetProcessorPrototype); if (statementSpec.SelectClauseSpec.IsDistinct) { if (_resultSetProcessor.ResultEventType is EventTypeSPI) { _eventBeanReader = ((EventTypeSPI)_resultSetProcessor.ResultEventType).GetReader(); } if (_eventBeanReader == null) { _eventBeanReader = new EventBeanReaderDefaultImpl(_resultSetProcessor.ResultEventType); } } // plan joins or simple queries if (numStreams > 1) { var streamJoinAnalysisResult = new StreamJoinAnalysisResult(numStreams); CompatExtensions.Fill(streamJoinAnalysisResult.NamedWindow, true); for (var i = 0; i < numStreams; i++) { var processorInstance = _processors[i].GetProcessorInstance(_agentInstanceContext); if (_processors[i].IsVirtualDataWindow) { streamJoinAnalysisResult.ViewExternal[i] = agentInstanceContext => processorInstance.VirtualDataWindow; } var uniqueIndexes = _processors[i].GetUniqueIndexes(processorInstance); streamJoinAnalysisResult.UniqueKeys[i] = uniqueIndexes; } var hasAggregations = !resultSetProcessorPrototype.AggregationServiceFactoryDesc.Expressions.IsEmpty(); _joinSetComposerPrototype = JoinSetComposerPrototypeFactory.MakeComposerPrototype( null, null, statementSpec.OuterJoinDescList, statementSpec.FilterRootNode, typesPerStream, namesPerStream, streamJoinAnalysisResult, queryPlanLogging, statementContext, new HistoricalViewableDesc(numStreams), _agentInstanceContext, false, hasAggregations, services.TableService, true); } // check context partition use if (statementSpec.OptionalContextName != null) { if (numStreams > 1) { throw new ExprValidationException("Joins in runtime queries for context partitions are not supported"); } } }
/// <summary> /// Ctor. /// </summary> /// <param name="statementSpec">is a container for the definition of all statement constructs thatmay have been used in the statement, i.e. if defines the select clauses, insert into, outer joins etc. /// </param> /// <param name="services">is the service instances for dependency injection</param> /// <param name="statementContext">is statement-level information and statement services</param> /// <throws>com.espertech.esper.epl.expression.core.ExprValidationException if the preparation failed</throws> public EPPreparedExecuteIUDSingleStream( StatementSpecCompiled statementSpec, EPServicesContext services, StatementContext statementContext) { var queryPlanLogging = services.ConfigSnapshot.EngineDefaults.Logging.IsEnableQueryPlan; if (queryPlanLogging) { QueryPlanLog.Info("Query plans for Fire-and-forget query '" + statementContext.Expression + "'"); } HasTableAccess = statementSpec.IntoTableSpec != null || (statementSpec.TableNodes != null && statementSpec.TableNodes.Length > 0); if (statementSpec.InsertIntoDesc != null && services.TableService.GetTableMetadata(statementSpec.InsertIntoDesc.EventTypeName) != null) { HasTableAccess = true; } if (statementSpec.FireAndForgetSpec is FireAndForgetSpecUpdate || statementSpec.FireAndForgetSpec is FireAndForgetSpecDelete) { HasTableAccess |= statementSpec.StreamSpecs[0] is TableQueryStreamSpec; } StatementSpec = statementSpec; Services = services; StatementContext = statementContext; // validate general FAF criteria EPPreparedExecuteMethodHelper.ValidateFAFQuery(statementSpec); // obtain processor var streamSpec = statementSpec.StreamSpecs[0]; Processor = FireAndForgetProcessorFactory.ValidateResolveProcessor(streamSpec, services); // obtain name and type var processorName = Processor.NamedWindowOrTableName; var eventType = Processor.EventTypeResultSetProcessor; // determine alias var aliasName = processorName; if (streamSpec.OptionalStreamName != null) { aliasName = streamSpec.OptionalStreamName; } // compile filter to optimize access to named window var typeService = new StreamTypeServiceImpl(new EventType[] { eventType }, new string[] { aliasName }, new bool[] { true }, services.EngineURI, true); var excludePlanHint = ExcludePlanHint.GetHint(typeService.StreamNames, statementContext); var queryGraph = new QueryGraph(1, excludePlanHint, false); if (statementSpec.FilterRootNode != null) { ExprNodeUtility.ValidateFilterWQueryGraphSafe( queryGraph, statementSpec.FilterRootNode, statementContext, typeService); } // validate expressions EPStatementStartMethodHelperValidate.ValidateNodes(statementSpec, statementContext, typeService, null); // get executor Executor = GetExecutor(queryGraph, aliasName); }