/// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="container">The container.</param>
 /// <param name="engineImportService">engine imports</param>
 /// <param name="variableService">variable names</param>
 /// <param name="configuration">the configuration</param>
 /// <param name="schedulingService">The scheduling service.</param>
 /// <param name="engineURI">The engine URI.</param>
 /// <param name="patternNodeFactory">The pattern node factory.</param>
 /// <param name="namedWindowMgmtService">The named window service.</param>
 /// <param name="contextManagementService">The context management service.</param>
 /// <param name="exprDeclaredService">The expr declared service.</param>
 /// <param name="contextDescriptor">optional context description</param>
 /// <param name="tableService">The table service.</param>
 public StatementSpecMapContext(
     IContainer container,
     EngineImportService engineImportService,
     VariableService variableService,
     ConfigurationInformation configuration,
     SchedulingService schedulingService,
     string engineURI,
     PatternNodeFactory patternNodeFactory,
     NamedWindowMgmtService namedWindowMgmtService,
     ContextManagementService contextManagementService,
     ExprDeclaredService exprDeclaredService,
     ContextDescriptor contextDescriptor,
     TableService tableService)
 {
     Container                = container;
     PlugInAggregations       = new LazyAllocatedMap <ConfigurationPlugInAggregationMultiFunction, PlugInAggregationMultiFunctionFactory>();
     TableExpressions         = new HashSet <ExprTableAccessNode>();
     EngineImportService      = engineImportService;
     VariableService          = variableService;
     Configuration            = configuration;
     VariableNames            = new HashSet <string>();
     SchedulingService        = schedulingService;
     EngineURI                = engineURI;
     PatternNodeFactory       = patternNodeFactory;
     NamedWindowMgmtService   = namedWindowMgmtService;
     ContextManagementService = contextManagementService;
     ExprDeclaredService      = exprDeclaredService;
     ContextDescriptor        = contextDescriptor;
     TableService             = tableService;
 }
Beispiel #2
0
 public StatementContextEngineServices(
     IContainer container,
     String engineURI,
     EventAdapterService eventAdapterService,
     NamedWindowMgmtService namedWindowMgmtService,
     VariableService variableService,
     TableService tableService,
     EngineSettingsService engineSettingsService,
     ValueAddEventService valueAddEventService,
     ConfigurationInformation configSnapshot,
     MetricReportingServiceSPI metricReportingService,
     ViewService viewService,
     ExceptionHandlingService exceptionHandlingService,
     ExpressionResultCacheService expressionResultCacheService,
     StatementEventTypeRef statementEventTypeRef,
     TableExprEvaluatorContext tableExprEvaluatorContext,
     EngineLevelExtensionServicesContext engineLevelExtensionServicesContext,
     RegexHandlerFactory regexHandlerFactory,
     StatementLockFactory statementLockFactory,
     ContextManagementService contextManagementService,
     ViewServicePreviousFactory viewServicePreviousFactory,
     EventTableIndexService eventTableIndexService,
     PatternNodeFactory patternNodeFactory,
     FilterBooleanExpressionFactory filterBooleanExpressionFactory,
     TimeSourceService timeSourceService,
     EngineImportService engineImportService,
     AggregationFactoryFactory aggregationFactoryFactory,
     SchedulingService schedulingService,
     ExprDeclaredService exprDeclaredService)
 {
     Container                           = container;
     EngineURI                           = engineURI;
     EventAdapterService                 = eventAdapterService;
     NamedWindowMgmtService              = namedWindowMgmtService;
     VariableService                     = variableService;
     TableService                        = tableService;
     EngineSettingsService               = engineSettingsService;
     ValueAddEventService                = valueAddEventService;
     ConfigSnapshot                      = configSnapshot;
     MetricReportingService              = metricReportingService;
     ViewService                         = viewService;
     ExceptionHandlingService            = exceptionHandlingService;
     ExpressionResultCacheService        = expressionResultCacheService;
     StatementEventTypeRef               = statementEventTypeRef;
     TableExprEvaluatorContext           = tableExprEvaluatorContext;
     EngineLevelExtensionServicesContext = engineLevelExtensionServicesContext;
     RegexHandlerFactory                 = regexHandlerFactory;
     StatementLockFactory                = statementLockFactory;
     ContextManagementService            = contextManagementService;
     ViewServicePreviousFactory          = viewServicePreviousFactory;
     EventTableIndexService              = eventTableIndexService;
     PatternNodeFactory                  = patternNodeFactory;
     FilterBooleanExpressionFactory      = filterBooleanExpressionFactory;
     TimeSourceService                   = timeSourceService;
     EngineImportService                 = engineImportService;
     AggregationFactoryFactory           = aggregationFactoryFactory;
     SchedulingService                   = schedulingService;
     ExprDeclaredService                 = exprDeclaredService;
 }
        private EventTableIndexRepository GetIndexInstanceRepo(bool namedWindow)
        {
            if (namedWindow)
            {
                var instance = NamedWindowMgmtService.GetProcessor("MyInfra").ProcessorInstanceNoContext;
                return(instance.RootViewInstance.IndexRepository);
            }
            var metadata = TableService.GetTableMetadata("MyInfra");

            return(metadata.GetState(-1).IndexRepository);
        }
 private EventTableIndexMetadata GetIndexMetaRepo(bool namedWindow)
 {
     if (namedWindow)
     {
         var processor = NamedWindowMgmtService.GetProcessor("MyInfra");
         return(processor.EventTableIndexMetadataRepo);
     }
     else
     {
         var metadata = TableService.GetTableMetadata("MyInfra");
         return(metadata.EventTableIndexMetadataRepo);
     }
 }
 public NamedWindowTailView CreateTailView(
     EventType eventType,
     NamedWindowMgmtService namedWindowMgmtService,
     NamedWindowDispatchService namedWindowDispatchService,
     StatementResultService statementResultService,
     ValueAddEventProcessor revisionProcessor,
     bool prioritized,
     bool parentBatchWindow,
     string contextName,
     TimeSourceService timeSourceService,
     ConfigurationEngineDefaults.Threading threadingConfig)
 {
     return(new NamedWindowTailView(eventType, namedWindowMgmtService, namedWindowDispatchService, statementResultService, revisionProcessor, _isPrioritized, parentBatchWindow, timeSourceService, threadingConfig));
 }
        /// <summary>Ctor. </summary>
        /// <param name="variableService">variables</param>
        public StatementVariableRefImpl(VariableService variableService, TableService tableService, NamedWindowMgmtService namedWindowMgmtService)
        {
            _variableToStmt         = new Dictionary <String, ICollection <String> >().WithNullSupport();
            _stmtToVariable         = new Dictionary <String, ICollection <String> >().WithNullSupport();
            _mapLock                = ReaderWriterLockManager.CreateLock(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            _variableService        = variableService;
            _tableService           = tableService;
            _namedWindowMgmtService = namedWindowMgmtService;

            _configuredVariables = new HashSet <String>();
            foreach (var entry in variableService.VariableReadersNonCP)
            {
                _configuredVariables.Add(entry.Key);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="namedWindowName">Name of the named window.</param>
        /// <param name="namedWindowMgmtService">service for dispatching results</param>
        /// <param name="namedWindowDispatchService">The named window dispatch service.</param>
        /// <param name="contextName">Name of the context.</param>
        /// <param name="eventType">the type of event held by the named window</param>
        /// <param name="statementResultService">for coordinating on whether insert and remove stream events should be posted</param>
        /// <param name="revisionProcessor">for revision processing</param>
        /// <param name="eplExpression">epl expression</param>
        /// <param name="statementName">statement name</param>
        /// <param name="isPrioritized">if the engine is running with prioritized execution</param>
        /// <param name="isEnableSubqueryIndexShare">if set to <c>true</c> [is enable subquery index share].</param>
        /// <param name="enableQueryPlanLog">if set to <c>true</c> [enable query plan log].</param>
        /// <param name="metricReportingService">The metric reporting service.</param>
        /// <param name="isBatchingDataWindow">if set to <c>true</c> [is batching data window].</param>
        /// <param name="isVirtualDataWindow">if set to <c>true</c> [is virtual data window].</param>
        /// <param name="optionalUniqueKeyProps">The optional unique key props.</param>
        /// <param name="eventTypeAsName">Name of the event type as.</param>
        /// <param name="statementContextCreateWindow">The statement context create window.</param>
        public NamedWindowProcessor(string namedWindowName, NamedWindowMgmtService namedWindowMgmtService, NamedWindowDispatchService namedWindowDispatchService, string contextName, EventType eventType, StatementResultService statementResultService, ValueAddEventProcessor revisionProcessor, string eplExpression, string statementName, bool isPrioritized, bool isEnableSubqueryIndexShare, bool enableQueryPlanLog, MetricReportingService metricReportingService, bool isBatchingDataWindow, bool isVirtualDataWindow, ICollection <string> optionalUniqueKeyProps, string eventTypeAsName, StatementContext statementContextCreateWindow)
        {
            _namedWindowName              = namedWindowName;
            _contextName                  = contextName;
            _eventType                    = eventType;
            _eplExpression                = eplExpression;
            _statementName                = statementName;
            _isEnableSubqueryIndexShare   = isEnableSubqueryIndexShare;
            _isVirtualDataWindow          = isVirtualDataWindow;
            _optionalUniqueKeyProps       = optionalUniqueKeyProps;
            _eventTypeAsName              = eventTypeAsName;
            _statementContextCreateWindow = statementContextCreateWindow;

            _rootView = new NamedWindowRootView(revisionProcessor, enableQueryPlanLog, metricReportingService, eventType, isBatchingDataWindow, isEnableSubqueryIndexShare, optionalUniqueKeyProps);
            _tailView = namedWindowDispatchService.CreateTailView(eventType, namedWindowMgmtService, namedWindowDispatchService, statementResultService, revisionProcessor, isPrioritized, isBatchingDataWindow, contextName, statementContextCreateWindow.TimeSourceService, statementContextCreateWindow.ConfigSnapshot.EngineDefaults.ThreadingConfig);
        }
Beispiel #8
0
        private volatile IDictionary <EPStatementAgentInstanceHandle, IList <NamedWindowConsumerView> > _consumersNonContext;  // handles as copy-on-write

        public NamedWindowTailView(
            EventType eventType,
            NamedWindowMgmtService namedWindowMgmtService,
            NamedWindowDispatchService namedWindowDispatchService,
            StatementResultService statementResultService,
            ValueAddEventProcessor revisionProcessor,
            bool prioritized,
            bool parentBatchWindow,
            TimeSourceService timeSourceService,
            ConfigurationEngineDefaults.ThreadingConfig threadingConfig)
        {
            EventType = eventType;
            NamedWindowMgmtService     = namedWindowMgmtService;
            NamedWindowDispatchService = namedWindowDispatchService;
            StatementResultService     = statementResultService;
            RevisionProcessor          = revisionProcessor;
            IsPrioritized        = prioritized;
            IsParentBatchWindow  = parentBatchWindow;
            _consumersNonContext = NamedWindowUtil.CreateConsumerMap(IsPrioritized);
            ThreadingConfig      = threadingConfig;
            TimeSourceService    = timeSourceService;
        }
Beispiel #9
0
        protected internal static void ValidateStatementForContext(
            string contextName,
            ContextControllerStatementBase statement,
            StatementSpecCompiledAnalyzerResult streamAnalysis,
            ICollection <EventType> itemEventTypes,
            NamedWindowMgmtService namedWindowMgmtService)
        {
            var filters = streamAnalysis.Filters;

            var isCreateWindow = statement.StatementSpec.CreateWindowDesc != null;

            // if no create-window: at least one of the filters must match one of the filters specified by the context
            if (!isCreateWindow)
            {
                foreach (var filter in filters)
                {
                    foreach (var itemEventType in itemEventTypes)
                    {
                        var stmtFilterType = filter.FilterForEventType;
                        if (stmtFilterType == itemEventType)
                        {
                            return;
                        }
                        if (EventTypeUtility.IsTypeOrSubTypeOf(stmtFilterType, itemEventType))
                        {
                            return;
                        }

                        NamedWindowProcessor processor = namedWindowMgmtService.GetProcessor(stmtFilterType.Name);
                        if (processor != null && processor.ContextName != null &&
                            processor.ContextName.Equals(contextName))
                        {
                            return;
                        }
                    }
                }

                if (!filters.IsEmpty())
                {
                    throw new ExprValidationException(
                              GetTypeValidationMessage(contextName, filters[0].FilterForEventType.Name));
                }
                return;
            }

            // validate create-window with column definition: not allowed, requires typed
            if (statement.StatementSpec.CreateWindowDesc.Columns != null &&
                statement.StatementSpec.CreateWindowDesc.Columns.Count > 0)
            {
                throw new ExprValidationException(
                          "Segmented context '" + contextName +
                          "' requires that named windows are associated to an existing event type and that the event type is listed among the partitions defined by the create-context statement");
            }

            // validate create-window declared type
            var declaredAsName = statement.StatementSpec.CreateWindowDesc.AsEventTypeName;

            if (declaredAsName != null)
            {
                if (itemEventTypes.Any(itemEventType => itemEventType.Name == declaredAsName))
                {
                    return;
                }

                throw new ExprValidationException(GetTypeValidationMessage(contextName, declaredAsName));
            }
        }
Beispiel #10
0
 /// <summary>Dispose services. </summary>
 public void Dispose()
 {
     if (ScriptingService != null)
     {
         ScriptingService.Dispose();
     }
     if (ExprDeclaredService != null)
     {
         ExprDeclaredService.Dispose();
     }
     if (DataFlowService != null)
     {
         DataFlowService.Dispose();
     }
     if (VariableService != null)
     {
         VariableService.Dispose();
     }
     if (MetricsReportingService != null)
     {
         MetricsReportingService.Dispose();
     }
     if (ThreadingService != null)
     {
         ThreadingService.Dispose();
     }
     if (StatementLifecycleSvc != null)
     {
         StatementLifecycleSvc.Dispose();
     }
     if (FilterService != null)
     {
         FilterService.Dispose();
     }
     if (SchedulingService != null)
     {
         SchedulingService.Dispose();
     }
     if (SchedulingMgmtService != null)
     {
         SchedulingMgmtService.Dispose();
     }
     if (StreamService != null)
     {
         StreamService.Destroy();
     }
     if (NamedWindowMgmtService != null)
     {
         NamedWindowMgmtService.Dispose();
     }
     if (NamedWindowDispatchService != null)
     {
         NamedWindowDispatchService.Dispose();
     }
     if (EngineLevelExtensionServicesContext != null)
     {
         EngineLevelExtensionServicesContext.Dispose();
     }
     if (StatementIsolationService != null)
     {
         StatementIsolationService.Dispose();
     }
     if (DeploymentStateService != null)
     {
         DeploymentStateService.Dispose();
     }
 }
Beispiel #11
0
        // Supplied after construction to avoid circular dependency

        /// <summary>
        /// Constructor - sets up new set of services.
        /// </summary>
        /// <param name="engineURI">is the engine URI</param>
        /// <param name="schedulingService">service to get time and schedule callbacks</param>
        /// <param name="eventAdapterService">service to resolve event types</param>
        /// <param name="engineImportService">is engine imported static func packages and aggregation functions</param>
        /// <param name="engineSettingsService">provides engine settings</param>
        /// <param name="databaseConfigService">service to resolve a database name to database connection factory and configs</param>
        /// <param name="plugInViews">resolves view namespace and name to view factory class</param>
        /// <param name="statementLockFactory">creates statement-level locks</param>
        /// <param name="eventProcessingRWLock">is the engine lock for statement management</param>
        /// <param name="extensionServicesContext">marker interface allows adding additional services</param>
        /// <param name="engineEnvContext">is engine environment/directory information for use with adapters and external env</param>
        /// <param name="statementContextFactory">is the factory to use to create statement context objects</param>
        /// <param name="plugInPatternObjects">resolves plug-in pattern objects</param>
        /// <param name="timerService">is the timer service</param>
        /// <param name="filterService">the filter service</param>
        /// <param name="streamFactoryService">is hooking up filters to streams</param>
        /// <param name="namedWindowMgmtService">The named window MGMT service.</param>
        /// <param name="namedWindowDispatchService">The named window dispatch service.</param>
        /// <param name="variableService">provides access to variable values</param>
        /// <param name="tableService">The table service.</param>
        /// <param name="timeSourceService">time source provider class</param>
        /// <param name="valueAddEventService">handles Update events</param>
        /// <param name="metricsReportingService">for metric reporting</param>
        /// <param name="statementEventTypeRef">statement to event type reference holding</param>
        /// <param name="statementVariableRef">statement to variabke reference holding</param>
        /// <param name="configSnapshot">configuration snapshot</param>
        /// <param name="threadingServiceImpl">engine-level threading services</param>
        /// <param name="internalEventRouter">routing of events</param>
        /// <param name="statementIsolationService">maintains isolation information per statement</param>
        /// <param name="schedulingMgmtService">schedule management for statements</param>
        /// <param name="deploymentStateService">The deployment state service.</param>
        /// <param name="exceptionHandlingService">The exception handling service.</param>
        /// <param name="patternNodeFactory">The pattern node factory.</param>
        /// <param name="eventTypeIdGenerator">The event type id generator.</param>
        /// <param name="statementMetadataFactory">The statement metadata factory.</param>
        /// <param name="contextManagementService">The context management service.</param>
        /// <param name="patternSubexpressionPoolSvc">The pattern subexpression pool SVC.</param>
        /// <param name="matchRecognizeStatePoolEngineSvc">The match recognize state pool engine SVC.</param>
        /// <param name="dataFlowService">The data flow service.</param>
        /// <param name="exprDeclaredService">The expr declared service.</param>
        /// <param name="contextControllerFactoryFactorySvc">The context controller factory factory SVC.</param>
        /// <param name="contextManagerFactoryService">The context manager factory service.</param>
        /// <param name="epStatementFactory">The ep statement factory.</param>
        /// <param name="regexHandlerFactory">The regex handler factory.</param>
        /// <param name="viewableActivatorFactory">The viewable activator factory.</param>
        /// <param name="filterNonPropertyRegisteryService">The filter non property registery service.</param>
        /// <param name="resultSetProcessorHelperFactory">The result set processor helper factory.</param>
        /// <param name="viewServicePreviousFactory">The view service previous factory.</param>
        /// <param name="eventTableIndexService">The event table index service.</param>
        /// <param name="epRuntimeIsolatedFactory">The ep runtime isolated factory.</param>
        /// <param name="filterBooleanExpressionFactory">The filter boolean expression factory.</param>
        /// <param name="dataCacheFactory">The data cache factory.</param>
        /// <param name="multiMatchHandlerFactory">The multi match handler factory.</param>
        /// <param name="namedWindowConsumerMgmtService">The named window consumer MGMT service.</param>
        /// <param name="aggregationFactoryFactory"></param>
        /// <param name="scriptingService">The scripting service.</param>
        public EPServicesContext(
            string engineURI,
            SchedulingServiceSPI schedulingService,
            EventAdapterService eventAdapterService,
            EngineImportService engineImportService,
            EngineSettingsService engineSettingsService,
            DatabaseConfigService databaseConfigService,
            PluggableObjectCollection plugInViews,
            StatementLockFactory statementLockFactory,
            IReaderWriterLock eventProcessingRWLock,
            EngineLevelExtensionServicesContext extensionServicesContext,
            Directory engineEnvContext,
            StatementContextFactory statementContextFactory,
            PluggableObjectCollection plugInPatternObjects,
            TimerService timerService,
            FilterServiceSPI filterService,
            StreamFactoryService streamFactoryService,
            NamedWindowMgmtService namedWindowMgmtService,
            NamedWindowDispatchService namedWindowDispatchService,
            VariableService variableService,
            TableService tableService,
            TimeSourceService timeSourceService,
            ValueAddEventService valueAddEventService,
            MetricReportingServiceSPI metricsReportingService,
            StatementEventTypeRef statementEventTypeRef,
            StatementVariableRef statementVariableRef,
            ConfigurationInformation configSnapshot,
            ThreadingService threadingServiceImpl,
            InternalEventRouterImpl internalEventRouter,
            StatementIsolationService statementIsolationService,
            SchedulingMgmtService schedulingMgmtService,
            DeploymentStateService deploymentStateService,
            ExceptionHandlingService exceptionHandlingService,
            PatternNodeFactory patternNodeFactory,
            EventTypeIdGenerator eventTypeIdGenerator,
            StatementMetadataFactory statementMetadataFactory,
            ContextManagementService contextManagementService,
            PatternSubexpressionPoolEngineSvc patternSubexpressionPoolSvc,
            MatchRecognizeStatePoolEngineSvc matchRecognizeStatePoolEngineSvc,
            DataFlowService dataFlowService,
            ExprDeclaredService exprDeclaredService,
            ContextControllerFactoryFactorySvc contextControllerFactoryFactorySvc,
            ContextManagerFactoryService contextManagerFactoryService,
            EPStatementFactory epStatementFactory,
            RegexHandlerFactory regexHandlerFactory,
            ViewableActivatorFactory viewableActivatorFactory,
            FilterNonPropertyRegisteryService filterNonPropertyRegisteryService,
            ResultSetProcessorHelperFactory resultSetProcessorHelperFactory,
            ViewServicePreviousFactory viewServicePreviousFactory,
            EventTableIndexService eventTableIndexService,
            EPRuntimeIsolatedFactory epRuntimeIsolatedFactory,
            FilterBooleanExpressionFactory filterBooleanExpressionFactory,
            DataCacheFactory dataCacheFactory,
            MultiMatchHandlerFactory multiMatchHandlerFactory,
            NamedWindowConsumerMgmtService namedWindowConsumerMgmtService,
            AggregationFactoryFactory aggregationFactoryFactory,
            ScriptingService scriptingService)
        {
            EngineURI             = engineURI;
            SchedulingService     = schedulingService;
            EventAdapterService   = eventAdapterService;
            EngineImportService   = engineImportService;
            EngineSettingsService = engineSettingsService;
            DatabaseRefService    = databaseConfigService;
            FilterService         = filterService;
            TimerService          = timerService;
            DispatchService       = DispatchServiceProvider.NewService();
            ViewService           = ViewServiceProvider.NewService();
            StreamService         = streamFactoryService;
            PlugInViews           = plugInViews;
            StatementLockFactory  = statementLockFactory;
            EventProcessingRWLock = eventProcessingRWLock;
            EngineLevelExtensionServicesContext = extensionServicesContext;
            EngineEnvContext           = engineEnvContext;
            StatementContextFactory    = statementContextFactory;
            PlugInPatternObjects       = plugInPatternObjects;
            NamedWindowMgmtService     = namedWindowMgmtService;
            NamedWindowDispatchService = namedWindowDispatchService;
            VariableService            = variableService;
            TableService                     = tableService;
            TimeSource                       = timeSourceService;
            ValueAddEventService             = valueAddEventService;
            MetricsReportingService          = metricsReportingService;
            StatementEventTypeRefService     = statementEventTypeRef;
            ConfigSnapshot                   = configSnapshot;
            ThreadingService                 = threadingServiceImpl;
            InternalEventRouter              = internalEventRouter;
            StatementIsolationService        = statementIsolationService;
            SchedulingMgmtService            = schedulingMgmtService;
            StatementVariableRefService      = statementVariableRef;
            DeploymentStateService           = deploymentStateService;
            ExceptionHandlingService         = exceptionHandlingService;
            PatternNodeFactory               = patternNodeFactory;
            EventTypeIdGenerator             = eventTypeIdGenerator;
            StatementMetadataFactory         = statementMetadataFactory;
            ContextManagementService         = contextManagementService;
            PatternSubexpressionPoolSvc      = patternSubexpressionPoolSvc;
            MatchRecognizeStatePoolEngineSvc = matchRecognizeStatePoolEngineSvc;
            DataFlowService                  = dataFlowService;
            ExprDeclaredService              = exprDeclaredService;
            ExpressionResultCacheSharable    = new ExpressionResultCacheService(
                configSnapshot.EngineDefaults.ExecutionConfig.DeclaredExprValueCacheSize);
            ContextControllerFactoryFactorySvc = contextControllerFactoryFactorySvc;
            ContextManagerFactoryService       = contextManagerFactoryService;
            EpStatementFactory                = epStatementFactory;
            RegexHandlerFactory               = regexHandlerFactory;
            ViewableActivatorFactory          = viewableActivatorFactory;
            FilterNonPropertyRegisteryService = filterNonPropertyRegisteryService;
            ResultSetProcessorHelperFactory   = resultSetProcessorHelperFactory;
            ViewServicePreviousFactory        = viewServicePreviousFactory;
            EventTableIndexService            = eventTableIndexService;
            EpRuntimeIsolatedFactory          = epRuntimeIsolatedFactory;
            FilterBooleanExpressionFactory    = filterBooleanExpressionFactory;
            DataCacheFactory               = dataCacheFactory;
            MultiMatchHandlerFactory       = multiMatchHandlerFactory;
            NamedWindowConsumerMgmtService = namedWindowConsumerMgmtService;
            AggregationFactoryFactory      = aggregationFactoryFactory;
            ScriptingService               = scriptingService;
        }
Beispiel #12
0
        /// <summary>
        /// Returns the processor to use for a given select-clause.
        /// </summary>
        /// <param name="assignedTypeNumberStack">The assigned type number stack.</param>
        /// <param name="selectionList">the list of select clause elements/items, which are expected to have been validated</param>
        /// <param name="isUsingWildcard">true if the wildcard (*) occurs in the select clause</param>
        /// <param name="insertIntoDesc">contains column names for the optional insert-into clause (if supplied)</param>
        /// <param name="optionalInsertIntoEventType">Type of the optional insert into event.</param>
        /// <param name="forClauseSpec">For clause spec.</param>
        /// <param name="typeService">serves stream type information</param>
        /// <param name="eventAdapterService">for generating wrapper instances for events</param>
        /// <param name="statementResultService">handles listeners/subscriptions awareness to reduce output result generation</param>
        /// <param name="valueAddEventService">service that handles update events and variant events</param>
        /// <param name="selectExprEventTypeRegistry">registry for event type to statements</param>
        /// <param name="engineImportService"></param>
        /// <param name="exprEvaluatorContext">context for expression evalauation</param>
        /// <param name="variableService">The variable service.</param>
        /// <param name="scriptingService">The scripting service.</param>
        /// <param name="tableService">The table service.</param>
        /// <param name="timeProvider">The time provider.</param>
        /// <param name="engineURI">The engine URI.</param>
        /// <param name="statementId">The statement identifier.</param>
        /// <param name="statementName">Name of the statement.</param>
        /// <param name="annotations">The annotations.</param>
        /// <param name="contextDescriptor">The context descriptor.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="selectExprProcessorCallback">The select expr processor callback.</param>
        /// <param name="namedWindowMgmtService">The named window service.</param>
        /// <param name="intoTableClause">The into table clause.</param>
        /// <param name="groupByRollupInfo"></param>
        /// <param name="statementExtensionSvcContext"></param>
        /// <returns>
        /// select-clause expression processor
        /// </returns>
        /// <exception cref="ExprValidationException">Expected any of the  + Arrays.ToString(ForClauseKeyword.Values()).ToLowerCase() +  for-clause keywords after reserved keyword 'for'
        /// or
        /// The for-clause with the  + ForClauseKeyword.GROUPED_DELIVERY.Name +  keyword requires one or more grouping expressions
        /// or
        /// The for-clause with the  + ForClauseKeyword.DISCRETE_DELIVERY.Name +  keyword does not allow grouping expressions
        /// or
        /// The for-clause with delivery keywords may only occur once in a statement
        /// or
        /// Expected any of the  + Arrays.ToString(ForClauseKeyword.Values()).ToLowerCase() +  for-clause keywords after reserved keyword 'for'</exception>
        /// <throws>ExprValidationException to indicate the select expression cannot be validated</throws>
        public static SelectExprProcessor GetProcessor(
            ICollection <int> assignedTypeNumberStack,
            SelectClauseElementCompiled[] selectionList,
            bool isUsingWildcard,
            InsertIntoDesc insertIntoDesc,
            EventType optionalInsertIntoEventType,
            ForClauseSpec forClauseSpec,
            StreamTypeService typeService,
            EventAdapterService eventAdapterService,
            StatementResultService statementResultService,
            ValueAddEventService valueAddEventService,
            SelectExprEventTypeRegistry selectExprEventTypeRegistry,
            EngineImportService engineImportService,
            ExprEvaluatorContext exprEvaluatorContext,
            VariableService variableService,
            ScriptingService scriptingService,
            TableService tableService,
            TimeProvider timeProvider,
            string engineURI,
            int statementId,
            string statementName,
            Attribute[] annotations,
            ContextDescriptor contextDescriptor,
            ConfigurationInformation configuration,
            SelectExprProcessorDeliveryCallback selectExprProcessorCallback,
            NamedWindowMgmtService namedWindowMgmtService,
            IntoTableSpec intoTableClause,
            GroupByRollupInfo groupByRollupInfo,
            StatementExtensionSvcContext statementExtensionSvcContext)
        {
            if (selectExprProcessorCallback != null)
            {
                var bindProcessor = new BindProcessor(selectionList, typeService.EventTypes, typeService.StreamNames, tableService);
                IDictionary <string, object> properties = new LinkedHashMap <string, object>();
                for (var i = 0; i < bindProcessor.ColumnNamesAssigned.Length; i++)
                {
                    properties.Put(bindProcessor.ColumnNamesAssigned[i], bindProcessor.ExpressionTypes[i]);
                }
                var eventType = eventAdapterService.CreateAnonymousObjectArrayType("Output_" + statementName, properties);
                return(new SelectExprProcessorWDeliveryCallback(eventType, bindProcessor, selectExprProcessorCallback));
            }

            var synthetic = GetProcessorInternal(
                assignedTypeNumberStack, selectionList, isUsingWildcard, insertIntoDesc, optionalInsertIntoEventType,
                typeService, eventAdapterService, valueAddEventService, selectExprEventTypeRegistry,
                engineImportService, statementId, statementName, annotations, configuration, namedWindowMgmtService, tableService,
                groupByRollupInfo);

            // Handle table as an optional service
            if (statementResultService != null)
            {
                // Handle for-clause delivery contract checking
                ExprNode[] groupedDeliveryExpr = null;
                var        forDelivery         = false;
                if (forClauseSpec != null)
                {
                    foreach (var item in forClauseSpec.Clauses)
                    {
                        if (item.Keyword == null)
                        {
                            throw new ExprValidationException("Expected any of the " + EnumHelper.GetValues <ForClauseKeyword>().Render().ToLower() + " for-clause keywords after reserved keyword 'for'");
                        }
                        try
                        {
                            ForClauseKeyword keyword = EnumHelper.Parse <ForClauseKeyword>(item.Keyword);
                            if ((keyword == ForClauseKeyword.GROUPED_DELIVERY) && (item.Expressions.IsEmpty()))
                            {
                                throw new ExprValidationException(
                                          "The for-clause with the " + ForClauseKeyword.GROUPED_DELIVERY.GetName() +
                                          " keyword requires one or more grouping expressions");
                            }
                            if ((keyword == ForClauseKeyword.DISCRETE_DELIVERY) && (!item.Expressions.IsEmpty()))
                            {
                                throw new ExprValidationException(
                                          "The for-clause with the " + ForClauseKeyword.DISCRETE_DELIVERY.GetName() +
                                          " keyword does not allow grouping expressions");
                            }
                            if (forDelivery)
                            {
                                throw new ExprValidationException(
                                          "The for-clause with delivery keywords may only occur once in a statement");
                            }
                        }
                        catch (ExprValidationException)
                        {
                            throw;
                        }
                        catch (EPException)
                        {
                            throw;
                        }
                        catch (Exception ex)
                        {
                            throw new ExprValidationException("Expected any of the " + EnumHelper.GetValues <ForClauseKeyword>().Render().ToLower() + " for-clause keywords after reserved keyword 'for'", ex);
                        }

                        StreamTypeService type = new StreamTypeServiceImpl(synthetic.ResultEventType, null, false, engineURI);
                        groupedDeliveryExpr = new ExprNode[item.Expressions.Count];
                        var validationContext = new ExprValidationContext(type, engineImportService, statementExtensionSvcContext, null, timeProvider, variableService, tableService, exprEvaluatorContext, eventAdapterService, statementName, statementId, annotations, null, scriptingService, false, false, true, false, intoTableClause == null ? null : intoTableClause.Name, false);  // no context descriptor available
                        for (var i = 0; i < item.Expressions.Count; i++)
                        {
                            groupedDeliveryExpr[i] = ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.FORCLAUSE, item.Expressions[i], validationContext);
                        }
                        forDelivery = true;
                    }
                }

                var bindProcessor = new BindProcessor(selectionList, typeService.EventTypes, typeService.StreamNames, tableService);
                statementResultService.SetSelectClause(bindProcessor.ExpressionTypes, bindProcessor.ColumnNamesAssigned, forDelivery, ExprNodeUtility.GetEvaluators(groupedDeliveryExpr), exprEvaluatorContext);
                return(new SelectExprResultProcessor(statementResultService, synthetic, bindProcessor));
            }

            return(synthetic);
        }
Beispiel #13
0
        private static SelectExprProcessor GetProcessorInternal(
            ICollection <int> assignedTypeNumberStack,
            SelectClauseElementCompiled[] selectionList,
            bool isUsingWildcard,
            InsertIntoDesc insertIntoDesc,
            EventType optionalInsertIntoEventType,
            StreamTypeService typeService,
            EventAdapterService eventAdapterService,
            ValueAddEventService valueAddEventService,
            SelectExprEventTypeRegistry selectExprEventTypeRegistry,
            EngineImportService engineImportService,
            int statementId,
            string statementName,
            Attribute[] annotations,
            ConfigurationInformation configuration,
            NamedWindowMgmtService namedWindowMgmtService,
            TableService tableService,
            GroupByRollupInfo groupByRollupInfo)
        {
            // Wildcard not allowed when insert into specifies column order
            if (isUsingWildcard && insertIntoDesc != null && !insertIntoDesc.ColumnNames.IsEmpty())
            {
                throw new ExprValidationException("Wildcard not allowed when insert-into specifies column order");
            }

            // Determine wildcard processor (select *)
            if (IsWildcardsOnly(selectionList))
            {
                // For joins
                if (typeService.StreamNames.Length > 1)
                {
                    Log.Debug(".getProcessor Using SelectExprJoinWildcardProcessor");
                    return(SelectExprJoinWildcardProcessorFactory.Create(
                               assignedTypeNumberStack, statementId, statementName,
                               typeService.StreamNames, typeService.EventTypes,
                               eventAdapterService, insertIntoDesc, selectExprEventTypeRegistry, engineImportService,
                               annotations, configuration, tableService, typeService.EngineURIQualifier));
                }
                // Single-table selects with no insert-into
                // don't need extra processing
                else if (insertIntoDesc == null)
                {
                    Log.Debug(".getProcessor Using wildcard processor");
                    if (typeService.HasTableTypes)
                    {
                        var tableName = TableServiceUtil.GetTableNameFromEventType(typeService.EventTypes[0]);
                        return(new SelectExprWildcardTableProcessor(tableName, tableService));
                    }
                    return(new SelectExprWildcardProcessor(typeService.EventTypes[0]));
                }
            }

            // Verify the assigned or name used is unique
            if (insertIntoDesc == null)
            {
                VerifyNameUniqueness(selectionList);
            }

            // Construct processor
            var buckets = GetSelectExpressionBuckets(selectionList);

            var factory = new SelectExprProcessorHelper(
                assignedTypeNumberStack, buckets.Expressions, buckets.SelectedStreams, insertIntoDesc,
                optionalInsertIntoEventType, isUsingWildcard, typeService, eventAdapterService, valueAddEventService,
                selectExprEventTypeRegistry, engineImportService, statementId, statementName, annotations, configuration,
                namedWindowMgmtService, tableService, groupByRollupInfo);
            SelectExprProcessor processor = factory.Evaluator;

            // add reference to the type obtained
            var type = (EventTypeSPI)processor.ResultEventType;

            if (!typeService.IsOnDemandStreams && type.Metadata.TypeClass != TypeClass.ANONYMOUS)
            {
                selectExprEventTypeRegistry.Add(processor.ResultEventType);
            }
            return(processor);
        }
        private static StreamJoinAnalysisResult VerifyJoinViews(StatementSpecCompiled statementSpec, NamedWindowMgmtService namedWindowMgmtService, AgentInstanceContext defaultAgentInstanceContext)
        {
            var streamSpecs    = statementSpec.StreamSpecs;
            var analysisResult = new StreamJoinAnalysisResult(streamSpecs.Length);

            if (streamSpecs.Length < 2)
            {
                return(analysisResult);
            }

            // Determine if any stream has a unidirectional keyword

            // inspect unidirectional indicator and named window flags
            var unidirectionalStreamNumber = -1;

            for (var i = 0; i < statementSpec.StreamSpecs.Length; i++)
            {
                var streamSpec = statementSpec.StreamSpecs[i];
                if (streamSpec.Options.IsUnidirectional)
                {
                    analysisResult.SetUnidirectionalInd(i);
                    if (unidirectionalStreamNumber != -1)
                    {
                        throw new ExprValidationException("The unidirectional keyword can only apply to one stream in a join");
                    }
                    unidirectionalStreamNumber = i;
                }
                if (streamSpec.ViewSpecs.Length > 0)
                {
                    analysisResult.SetHasChildViews(i);
                }
                if (streamSpec is NamedWindowConsumerStreamSpec)
                {
                    var nwSpec = (NamedWindowConsumerStreamSpec)streamSpec;
                    if (nwSpec.OptPropertyEvaluator != null && !streamSpec.Options.IsUnidirectional)
                    {
                        throw new ExprValidationException("Failed to validate named window use in join, contained-event is only allowed for named windows when marked as unidirectional");
                    }
                    analysisResult.SetNamedWindow(i);
                    var        processor     = namedWindowMgmtService.GetProcessor(nwSpec.WindowName);
                    string[][] uniqueIndexes = processor.UniqueIndexes;
                    analysisResult.UniqueKeys[i] = uniqueIndexes;
                    if (processor.IsVirtualDataWindow)
                    {
                        analysisResult.ViewExternal[i] = agentInstanceContext => processor.GetProcessorInstance(agentInstanceContext).RootViewInstance.VirtualDataWindow;
                    }
                }
            }
            if ((unidirectionalStreamNumber != -1) && (analysisResult.HasChildViews[unidirectionalStreamNumber]))
            {
                throw new ExprValidationException("The unidirectional keyword requires that no views are declared onto the stream");
            }
            analysisResult.UnidirectionalStreamNumber = unidirectionalStreamNumber;

            // count streams that provide data, excluding streams that poll data (DB and method)
            var countProviderNonpolling = 0;

            for (var i = 0; i < statementSpec.StreamSpecs.Length; i++)
            {
                var streamSpec = statementSpec.StreamSpecs[i];
                if ((streamSpec is MethodStreamSpec) ||
                    (streamSpec is DBStatementStreamSpec) ||
                    (streamSpec is TableQueryStreamSpec))
                {
                    continue;
                }
                countProviderNonpolling++;
            }

            // if there is only one stream providing data, the analysis is done
            if (countProviderNonpolling == 1)
            {
                return(analysisResult);
            }
            // there are multiple driving streams, verify the presence of a view for insert/remove stream

            // validation of join views works differently for unidirectional as there can be self-joins that don't require a view
            // see if this is a self-join in which all streams are filters and filter specification is the same.
            FilterSpecCompiled unidirectionalFilterSpec = null;
            FilterSpecCompiled lastFilterSpec           = null;
            var pureSelfJoin = true;

            foreach (var streamSpec in statementSpec.StreamSpecs)
            {
                if (!(streamSpec is FilterStreamSpecCompiled))
                {
                    pureSelfJoin = false;
                    continue;
                }

                var filterSpec = ((FilterStreamSpecCompiled)streamSpec).FilterSpec;
                if ((lastFilterSpec != null) && (!lastFilterSpec.EqualsTypeAndFilter(filterSpec)))
                {
                    pureSelfJoin = false;
                }
                if (streamSpec.ViewSpecs.Length > 0)
                {
                    pureSelfJoin = false;
                }
                lastFilterSpec = filterSpec;

                if (streamSpec.Options.IsUnidirectional)
                {
                    unidirectionalFilterSpec = filterSpec;
                }
            }

            // self-join without views and not unidirectional
            if ((pureSelfJoin) && (unidirectionalFilterSpec == null))
            {
                analysisResult.IsPureSelfJoin = true;
                return(analysisResult);
            }

            // weed out filter and pattern streams that don't have a view in a join
            for (var i = 0; i < statementSpec.StreamSpecs.Length; i++)
            {
                var streamSpec = statementSpec.StreamSpecs[i];
                if (streamSpec.ViewSpecs.Length > 0)
                {
                    continue;
                }

                var name = streamSpec.OptionalStreamName;
                if ((name == null) && (streamSpec is FilterStreamSpecCompiled))
                {
                    name = ((FilterStreamSpecCompiled)streamSpec).FilterSpec.FilterForEventTypeName;
                }
                if ((name == null) && (streamSpec is PatternStreamSpecCompiled))
                {
                    name = "pattern event stream";
                }

                if (streamSpec.Options.IsUnidirectional)
                {
                    continue;
                }
                // allow a self-join without a child view, in that the filter spec is the same as the unidirection's stream filter
                if ((unidirectionalFilterSpec != null) &&
                    (streamSpec is FilterStreamSpecCompiled) &&
                    (((FilterStreamSpecCompiled)streamSpec).FilterSpec.EqualsTypeAndFilter(unidirectionalFilterSpec)))
                {
                    analysisResult.SetUnidirectionalNonDriving(i);
                    continue;
                }
                if ((streamSpec is FilterStreamSpecCompiled) ||
                    (streamSpec is PatternStreamSpecCompiled))
                {
                    throw new ExprValidationException("Joins require that at least one view is specified for each stream, no view was specified for " + name);
                }
            }

            return(analysisResult);
        }
        /// <summary>
        /// Makes the property evaluator.
        /// </summary>
        /// <param name="spec">is the property specification</param>
        /// <param name="sourceEventType">the event type</param>
        /// <param name="optionalSourceStreamName">the source stream name</param>
        /// <param name="eventAdapterService">for event instances</param>
        /// <param name="engineImportService">The engine import service.</param>
        /// <param name="timeProvider">provides time</param>
        /// <param name="variableService">for resolving variables</param>
        /// <param name="scriptingService">The scripting service.</param>
        /// <param name="tableService">The table service.</param>
        /// <param name="engineURI">engine URI</param>
        /// <param name="statementId">The statement identifier.</param>
        /// <param name="statementName">Name of the statement.</param>
        /// <param name="annotations">The annotations.</param>
        /// <param name="assignedTypeNumberStack">The assigned type number stack.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="namedWindowMgmtService">The named window service.</param>
        /// <param name="statementExtensionSvcContext">The statement extension SVC context.</param>
        /// <returns>
        /// propert evaluator
        /// </returns>
        /// <exception cref="ExprValidationException">Missing @type(name) declaration providing the event type name of the return type for expression ' +
        /// ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(atom.SplitterExpression) + '
        /// or
        /// Event type by name ' + atom.OptionalResultEventType + ' could not be found
        /// or
        /// Event type ' + streamEventType.Name + ' underlying type  + streamEventType.UnderlyingType.Name +
        /// cannot be assigned a value of type  + returnType.GetTypeNameFullyQualPretty()
        /// or
        /// Return type of expression ' + ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(atom.SplitterExpression) + ' is ' + returnType.Name + ', expected an Iterable or array result
        /// or
        /// Property rename ' + rawStreamSpec.MaskTypeName + ' not found in path
        /// or
        /// Expression in a property-selection may not utilize  + isMinimal</exception>
        /// <exception cref="IllegalStateException">Unknown select clause item: + raw</exception>
        /// <throws>ExprValidationException if any expressions could not be verified</throws>
        public static PropertyEvaluator MakeEvaluator(
            PropertyEvalSpec spec,
            EventType sourceEventType,
            string optionalSourceStreamName,
            EventAdapterService eventAdapterService,
            EngineImportService engineImportService,
            TimeProvider timeProvider,
            VariableService variableService,
            ScriptingService scriptingService,
            TableService tableService,
            string engineURI,
            int statementId,
            string statementName,
            Attribute[] annotations,
            ICollection <int> assignedTypeNumberStack,
            ConfigurationInformation configuration,
            NamedWindowMgmtService namedWindowMgmtService,
            StatementExtensionSvcContext statementExtensionSvcContext)
        {
            var length = spec.Atoms.Count;
            var containedEventEvals = new ContainedEventEval[length];
            var fragmentEventTypes  = new FragmentEventType[length];
            var currentEventType    = sourceEventType;
            var whereClauses        = new ExprEvaluator[length];

            var streamEventTypes    = new List <EventType>();
            var streamNames         = new List <string>();
            var streamNameAndNumber = new Dictionary <string, int>().WithNullSupport();
            var expressionTexts     = new List <string>();
            var validateContext     = new ExprEvaluatorContextTimeOnly(timeProvider);

            streamEventTypes.Add(sourceEventType);
            streamNames.Add(optionalSourceStreamName);
            streamNameAndNumber.Put(optionalSourceStreamName, 0);
            expressionTexts.Add(sourceEventType.Name);

            IList <SelectClauseElementCompiled> cumulativeSelectClause = new List <SelectClauseElementCompiled>();

            for (var i = 0; i < length; i++)
            {
                var atom = spec.Atoms[i];
                ContainedEventEval containedEventEval = null;
                string             expressionText     = null;
                EventType          streamEventType    = null;
                FragmentEventType  fragmentEventType  = null;

                // Resolve directly as fragment event type if possible
                if (atom.SplitterExpression is ExprIdentNode)
                {
                    var propertyName = ((ExprIdentNode)atom.SplitterExpression).FullUnresolvedName;
                    fragmentEventType = currentEventType.GetFragmentType(propertyName);
                    if (fragmentEventType != null)
                    {
                        var getter = currentEventType.GetGetter(propertyName);
                        if (getter != null)
                        {
                            containedEventEval = new ContainedEventEvalGetter(getter);
                            expressionText     = propertyName;
                            streamEventType    = fragmentEventType.FragmentType;
                        }
                    }
                }

                // evaluate splitter expression
                if (containedEventEval == null)
                {
                    ExprNodeUtility.ValidatePlainExpression(
                        ExprNodeOrigin.CONTAINEDEVENT,
                        ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(atom.SplitterExpression),
                        atom.SplitterExpression);

                    var availableTypes       = streamEventTypes.ToArray();
                    var availableStreamNames = streamNames.ToArray();
                    var isIStreamOnly        = new bool[streamNames.Count];
                    isIStreamOnly.Fill(true);
                    StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                        availableTypes, availableStreamNames, isIStreamOnly, engineURI, false);
                    var validationContext = new ExprValidationContext(
                        streamTypeService, engineImportService, statementExtensionSvcContext, null, timeProvider, variableService, tableService,
                        validateContext, eventAdapterService, statementName, statementId, annotations, null, scriptingService,
                        false, false, true, false, null, false);
                    var validatedExprNode = ExprNodeUtility.GetValidatedSubtree(
                        ExprNodeOrigin.CONTAINEDEVENT, atom.SplitterExpression, validationContext);
                    var evaluator = validatedExprNode.ExprEvaluator;

                    // determine result type
                    if (atom.OptionalResultEventType == null)
                    {
                        throw new ExprValidationException(
                                  "Missing @type(name) declaration providing the event type name of the return type for expression '" +
                                  ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(atom.SplitterExpression) + "'");
                    }
                    streamEventType = eventAdapterService.GetEventTypeByName(atom.OptionalResultEventType);
                    if (streamEventType == null)
                    {
                        throw new ExprValidationException(
                                  "Event type by name '" + atom.OptionalResultEventType + "' could not be found");
                    }

                    var returnType = evaluator.ReturnType;

                    // when the expression returns an array, allow array values to become the column of the single-column event type
                    if (returnType.IsArray &&
                        streamEventType.PropertyNames.Length == 1 &&
                        TypeHelper.IsSubclassOrImplementsInterface(
                            TypeHelper.GetBoxedType(returnType.GetElementType()),
                            TypeHelper.GetBoxedType(streamEventType.GetPropertyType(streamEventType.PropertyNames[0]))))
                    {
                        var writables = eventAdapterService.GetWriteableProperties(streamEventType, false);
                        if (!writables.IsEmpty())
                        {
                            try
                            {
                                EventBeanManufacturer manufacturer = EventAdapterServiceHelper.GetManufacturer(
                                    eventAdapterService, streamEventType,
                                    new WriteablePropertyDescriptor[] { writables.First() },
                                    engineImportService, false,
                                    eventAdapterService.EventAdapterAvroHandler);
                                containedEventEval = new ContainedEventEvalArrayToEvent(evaluator, manufacturer);
                            }
                            catch (EventBeanManufactureException e)
                            {
                                throw new ExprValidationException(
                                          "Event type '" + streamEventType.Name + "' cannot be populated: " + e.Message, e);
                            }
                        }
                        else
                        {
                            throw new ExprValidationException("Event type '" + streamEventType.Name + "' cannot be written to");
                        }
                    }
                    else if (returnType.IsArray() && returnType.GetElementType() == typeof(EventBean))
                    {
                        containedEventEval = new ContainedEventEvalEventBeanArray(evaluator);
                    }
                    else
                    {
                        EventBeanFactory eventBeanFactory = EventAdapterServiceHelper.GetFactoryForType(
                            streamEventType, eventAdapterService);
                        // check expression result type against eventtype expected underlying type
                        if (returnType.IsArray())
                        {
                            if (!TypeHelper.IsSubclassOrImplementsInterface(returnType.GetElementType(), streamEventType.UnderlyingType))
                            {
                                throw new ExprValidationException(
                                          "Event type '" + streamEventType.Name + "' underlying type " +
                                          streamEventType.UnderlyingType.FullName +
                                          " cannot be assigned a value of type " + TypeHelper.GetTypeNameFullyQualPretty(returnType));
                            }
                        }
                        else if (GenericExtensions.IsGenericEnumerable(returnType) || returnType.IsImplementsInterface <IEnumerable>())
                        {
                            // fine, assumed to return the right type
                        }
                        else
                        {
                            throw new ExprValidationException(
                                      "Return type of expression '" +
                                      ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(atom.SplitterExpression) + "' is '" +
                                      returnType.FullName + "', expected an Iterable or array result");
                        }
                        containedEventEval = new ContainedEventEvalExprNode(evaluator, eventBeanFactory);
                    }
                    expressionText    = ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(validatedExprNode);
                    fragmentEventType = new FragmentEventType(streamEventType, true, false);
                }

                // validate where clause, if any
                streamEventTypes.Add(streamEventType);
                streamNames.Add(atom.OptionalAsName);
                streamNameAndNumber.Put(atom.OptionalAsName, i + 1);
                expressionTexts.Add(expressionText);

                if (atom.OptionalWhereClause != null)
                {
                    var whereTypes       = streamEventTypes.ToArray();
                    var whereStreamNames = streamNames.ToArray();
                    var isIStreamOnly    = new bool[streamNames.Count];
                    isIStreamOnly.Fill(true);
                    StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                        whereTypes, whereStreamNames, isIStreamOnly, engineURI, false);
                    var validationContext = new ExprValidationContext(
                        streamTypeService, engineImportService, statementExtensionSvcContext, null, timeProvider, variableService, tableService,
                        validateContext, eventAdapterService, statementName, statementId, annotations, null, scriptingService,
                        false, false, true, false, null, false);
                    whereClauses[i] =
                        ExprNodeUtility.GetValidatedSubtree(
                            ExprNodeOrigin.CONTAINEDEVENT, atom.OptionalWhereClause, validationContext).ExprEvaluator;
                }

                // validate select clause
                if (atom.OptionalSelectClause != null)
                {
                    var whereTypes       = streamEventTypes.ToArray();
                    var whereStreamNames = streamNames.ToArray();
                    var isIStreamOnly    = new bool[streamNames.Count];
                    isIStreamOnly.Fill(true);
                    StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                        whereTypes, whereStreamNames, isIStreamOnly, engineURI, false);
                    var validationContext = new ExprValidationContext(
                        streamTypeService, engineImportService, statementExtensionSvcContext, null, timeProvider, variableService, tableService,
                        validateContext, eventAdapterService, statementName, statementId, annotations, null, scriptingService,
                        false, false, true, false, null, false);

                    foreach (var raw in atom.OptionalSelectClause.SelectExprList)
                    {
                        if (raw is SelectClauseStreamRawSpec)
                        {
                            var rawStreamSpec = (SelectClauseStreamRawSpec)raw;
                            if (!streamNames.Contains(rawStreamSpec.StreamName))
                            {
                                throw new ExprValidationException(
                                          "Property rename '" + rawStreamSpec.StreamName + "' not found in path");
                            }
                            var streamSpec = new SelectClauseStreamCompiledSpec(
                                rawStreamSpec.StreamName, rawStreamSpec.OptionalAsName);
                            int streamNumber = streamNameAndNumber.Get(rawStreamSpec.StreamName);
                            streamSpec.StreamNumber = streamNumber;
                            cumulativeSelectClause.Add(streamSpec);
                        }
                        else if (raw is SelectClauseExprRawSpec)
                        {
                            var exprSpec     = (SelectClauseExprRawSpec)raw;
                            var exprCompiled = ExprNodeUtility.GetValidatedSubtree(
                                ExprNodeOrigin.CONTAINEDEVENT, exprSpec.SelectExpression, validationContext);
                            var resultName = exprSpec.OptionalAsName;
                            if (resultName == null)
                            {
                                resultName = ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(exprCompiled);
                            }
                            cumulativeSelectClause.Add(
                                new SelectClauseExprCompiledSpec(
                                    exprCompiled, resultName, exprSpec.OptionalAsName, exprSpec.IsEvents));

                            var isMinimal = ExprNodeUtility.IsMinimalExpression(exprCompiled);
                            if (isMinimal != null)
                            {
                                throw new ExprValidationException(
                                          "Expression in a property-selection may not utilize " + isMinimal);
                            }
                        }
                        else if (raw is SelectClauseElementWildcard)
                        {
                            // wildcards are stream selects: we assign a stream name (any) and add a stream wildcard select
                            var streamNameAtom = atom.OptionalAsName;
                            if (streamNameAtom == null)
                            {
                                streamNameAtom = UuidGenerator.Generate();
                            }

                            var streamSpec   = new SelectClauseStreamCompiledSpec(streamNameAtom, atom.OptionalAsName);
                            var streamNumber = i + 1;
                            streamSpec.StreamNumber = streamNumber;
                            cumulativeSelectClause.Add(streamSpec);
                        }
                        else
                        {
                            throw new IllegalStateException("Unknown select clause item:" + raw);
                        }
                    }
                }

                currentEventType       = fragmentEventType.FragmentType;
                fragmentEventTypes[i]  = fragmentEventType;
                containedEventEvals[i] = containedEventEval;
            }

            if (cumulativeSelectClause.IsEmpty())
            {
                if (length == 1)
                {
                    return(new PropertyEvaluatorSimple(
                               containedEventEvals[0], fragmentEventTypes[0], whereClauses[0], expressionTexts[0]));
                }
                else
                {
                    return(new PropertyEvaluatorNested(containedEventEvals, fragmentEventTypes, whereClauses, expressionTexts));
                }
            }
            else
            {
                var accumulative = new PropertyEvaluatorAccumulative(
                    containedEventEvals, fragmentEventTypes, whereClauses, expressionTexts);

                var whereTypes       = streamEventTypes.ToArray();
                var whereStreamNames = streamNames.ToArray();
                var isIStreamOnly    = new bool[streamNames.Count];
                isIStreamOnly.Fill(true);
                StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                    whereTypes, whereStreamNames, isIStreamOnly, engineURI, false);

                var cumulativeSelectArr = cumulativeSelectClause.ToArray();
                var selectExpr          = SelectExprProcessorFactory.GetProcessor(
                    assignedTypeNumberStack, cumulativeSelectArr, false, null, null, null, streamTypeService,
                    eventAdapterService, null, null, null, engineImportService, validateContext, variableService,
                    scriptingService,
                    tableService, timeProvider, engineURI, statementId, statementName, annotations, null, configuration, null,
                    namedWindowMgmtService, null, null, statementExtensionSvcContext);
                return(new PropertyEvaluatorSelect(selectExpr, accumulative));
            }
        }
Beispiel #16
0
        public static FilterSpecCompiled BuildNoStmtCtx(
            IContainer container,
            IList <ExprNode> validatedFilterNodes,
            EventType eventType,
            string eventTypeName,
            PropertyEvalSpec optionalPropertyEvalSpec,
            IDictionary <string, Pair <EventType, string> > taggedEventTypes,
            IDictionary <string, Pair <EventType, string> > arrayEventTypes,
            StreamTypeService streamTypeService,
            string optionalStreamName,
            ICollection <int> assignedTypeNumberStack,
            ExprEvaluatorContext exprEvaluatorContext,
            int statementId,
            string statementName,
            Attribute[] annotations,
            ContextDescriptor contextDescriptor,
            EngineImportService engineImportService,
            EventAdapterService eventAdapterService,
            FilterBooleanExpressionFactory filterBooleanExpressionFactory,
            TimeProvider timeProvider,
            VariableService variableService,
            ScriptingService scriptingService,
            TableService tableService,
            ConfigurationInformation configurationInformation,
            NamedWindowMgmtService namedWindowMgmtService,
            StatementExtensionSvcContext statementExtensionSvcContext)
        {
            var args = new FilterSpecCompilerArgs(
                container,
                taggedEventTypes,
                arrayEventTypes,
                exprEvaluatorContext,
                statementName,
                statementId,
                streamTypeService,
                engineImportService,
                timeProvider,
                variableService,
                tableService,
                eventAdapterService,
                filterBooleanExpressionFactory,
                scriptingService,
                annotations,
                contextDescriptor,
                configurationInformation,
                statementExtensionSvcContext);
            var parameters = FilterSpecCompilerPlanner.PlanFilterParameters(validatedFilterNodes, args);

            PropertyEvaluator optionalPropertyEvaluator = null;

            if (optionalPropertyEvalSpec != null)
            {
                optionalPropertyEvaluator = PropertyEvaluatorFactory.MakeEvaluator(
                    container,
                    optionalPropertyEvalSpec,
                    eventType,
                    optionalStreamName,
                    eventAdapterService,
                    engineImportService,
                    timeProvider,
                    variableService,
                    scriptingService,
                    tableService,
                    streamTypeService.EngineURIQualifier,
                    statementId,
                    statementName,
                    annotations,
                    assignedTypeNumberStack,
                    configurationInformation,
                    namedWindowMgmtService,
                    statementExtensionSvcContext);
            }

            var spec = new FilterSpecCompiled(eventType, eventTypeName, parameters, optionalPropertyEvaluator);

            if (Log.IsDebugEnabled)
            {
                Log.Debug(".makeFilterSpec spec=" + spec);
            }

            return(spec);
        }