Ejemplo n.º 1
0
        public StreamSpecCompiled Compile(StatementContext context, ICollection <String> eventTypeReferences, bool isInsertInto, ICollection <int> assignedTypeNumberStack, bool isJoin, bool isContextDeclaration, bool isOnTrigger, String optionalStreamName)
        {
            StreamTypeService streamTypeService;

            // Determine the event type
            var eventName = _rawFilterSpec.EventTypeName;

            if (context.TableService != null && context.TableService.GetTableMetadata(eventName) != null)
            {
                if (this.ViewSpecs != null && this.ViewSpecs.Length > 0)
                {
                    throw new ExprValidationException("Views are not supported with tables");
                }
                if (this.RawFilterSpec.OptionalPropertyEvalSpec != null)
                {
                    throw new ExprValidationException("Contained-event expressions are not supported with tables");
                }
                var tableMetadata      = context.TableService.GetTableMetadata(eventName);
                var streamTypeServiceX = new StreamTypeServiceImpl(new EventType[] { tableMetadata.InternalEventType }, new String[] { optionalStreamName }, new bool[] { true }, context.EngineURI, false);
                var validatedNodes     = FilterSpecCompiler.ValidateAllowSubquery(ExprNodeOrigin.FILTER, _rawFilterSpec.FilterExpressions, streamTypeServiceX, context, null, null);
                return(new TableQueryStreamSpec(this.OptionalStreamName, this.ViewSpecs, this.Options, eventName, validatedNodes));
            }

            // Could be a named window
            if (context.NamedWindowMgmtService.IsNamedWindow(eventName))
            {
                var namedWindowType = context.NamedWindowMgmtService.GetProcessor(eventName).TailView.EventType;
                streamTypeService = new StreamTypeServiceImpl(new EventType[] { namedWindowType }, new String[] { optionalStreamName }, new bool[] { true }, context.EngineURI, false);

                var validatedNodes = FilterSpecCompiler.ValidateAllowSubquery(
                    ExprNodeOrigin.FILTER, _rawFilterSpec.FilterExpressions, streamTypeService, context, null, null);

                PropertyEvaluator optionalPropertyEvaluator = null;
                if (_rawFilterSpec.OptionalPropertyEvalSpec != null)
                {
                    optionalPropertyEvaluator =
                        PropertyEvaluatorFactory.MakeEvaluator(
                            _rawFilterSpec.OptionalPropertyEvalSpec, namedWindowType, OptionalStreamName,
                            context.EventAdapterService,
                            context.MethodResolutionService,
                            context.TimeProvider,
                            context.VariableService,
                            context.ScriptingService,
                            context.TableService,
                            context.EngineURI,
                            context.StatementId,
                            context.StatementName,
                            context.Annotations, assignedTypeNumberStack,
                            context.ConfigSnapshot,
                            context.NamedWindowMgmtService);
                }
                eventTypeReferences.Add(((EventTypeSPI)namedWindowType).Metadata.PrimaryName);
                return(new NamedWindowConsumerStreamSpec(eventName, OptionalStreamName, ViewSpecs, validatedNodes, Options, optionalPropertyEvaluator));
            }

            EventType eventType = null;

            if (context.ValueAddEventService.IsRevisionTypeName(eventName))
            {
                eventType = context.ValueAddEventService.GetValueAddUnderlyingType(eventName);
                eventTypeReferences.Add(((EventTypeSPI)eventType).Metadata.PrimaryName);
            }

            if (eventType == null)
            {
                eventType = ResolveType(context.EngineURI, eventName, context.EventAdapterService, context.PlugInTypeResolutionURIs);
                if (eventType is EventTypeSPI)
                {
                    eventTypeReferences.Add(((EventTypeSPI)eventType).Metadata.PrimaryName);
                }
            }

            // Validate all nodes, make sure each returns a bool and types are good;
            // Also decompose all AND super nodes into individual expressions
            streamTypeService = new StreamTypeServiceImpl(new EventType[] { eventType }, new String[] { base.OptionalStreamName }, new bool[] { true }, context.EngineURI, false);

            var spec = FilterSpecCompiler.MakeFilterSpec(eventType, eventName, _rawFilterSpec.FilterExpressions, _rawFilterSpec.OptionalPropertyEvalSpec,
                                                         null, null, // no tags
                                                         streamTypeService, OptionalStreamName, context, assignedTypeNumberStack);

            return(new FilterStreamSpecCompiled(spec, ViewSpecs, OptionalStreamName, Options));
        }