Example #1
0
 public static FilterSpecCompiledDesc Build(
     FilterSpecValidatedDesc validatedDesc,
     EventType eventType,
     string eventTypeName,
     PropertyEvalSpec optionalPropertyEvalSpec,
     IDictionary<string, Pair<EventType, string>> taggedEventTypes,
     IDictionary<string, Pair<EventType, string>> arrayEventTypes,
     ISet<string> allTagNamesOrdered,
     StreamTypeService streamTypeService,
     string optionalStreamName,
     StatementRawInfo statementRawInfo,
     StatementCompileTimeServices compileTimeServices)
 {
     var compiled = BuildNoStmtCtx(
         validatedDesc.Expressions,
         eventType,
         eventTypeName,
         optionalStreamName,
         optionalPropertyEvalSpec,
         taggedEventTypes,
         arrayEventTypes,
         allTagNamesOrdered,
         streamTypeService,
         statementRawInfo,
         compileTimeServices);
     return new FilterSpecCompiledDesc(compiled, validatedDesc.AdditionalForgeables);
 }
Example #2
0
        public static StreamSpecCompiledDesc CompileFilter(
            FilterStreamSpecRaw streamSpec,
            bool isInsertInto,
            bool isJoin,
            bool isContextDeclaration,
            bool isOnTrigger,
            string optionalStreamName,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            // Determine the event type
            var rawFilterSpec = streamSpec.RawFilterSpec;
            var eventTypeName = rawFilterSpec.EventTypeName;

            var table = services.TableCompileTimeResolver.Resolve(eventTypeName);
            if (table != null) {
                if (streamSpec.ViewSpecs != null && streamSpec.ViewSpecs.Length > 0) {
                    throw new ExprValidationException("Views are not supported with tables");
                }

                if (streamSpec.RawFilterSpec.OptionalPropertyEvalSpec != null) {
                    throw new ExprValidationException("Contained-event expressions are not supported with tables");
                }

                StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                    new[] {table.InternalEventType},
                    new[] {optionalStreamName},
                    new[] {true},
                    false,
                    false);
                FilterSpecValidatedDesc descX = FilterSpecCompiler.ValidateAllowSubquery(
                    ExprNodeOrigin.FILTER,
                    rawFilterSpec.FilterExpressions,
                    streamTypeService,
                    null,
                    null,
                    statementRawInfo,
                    services);
                TableQueryStreamSpec tableStreamSpec = new TableQueryStreamSpec(
                    streamSpec.OptionalStreamName,
                    streamSpec.ViewSpecs,
                    streamSpec.Options,
                    table,
                    descX.Expressions);
                return new StreamSpecCompiledDesc(
                    tableStreamSpec,
                    descX.AdditionalForgeables);
            }

            // Could be a named window
            var namedWindowInfo = services.NamedWindowCompileTimeResolver.Resolve(eventTypeName);
            if (namedWindowInfo != null) {
                StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                    new[] {namedWindowInfo.EventType},
                    new[] {optionalStreamName},
                    new[] {true},
                    false,
                    false);

                FilterSpecValidatedDesc validated = FilterSpecCompiler.ValidateAllowSubquery(
                    ExprNodeOrigin.FILTER,
                    rawFilterSpec.FilterExpressions,
                    streamTypeService,
                    null,
                    null,
                    statementRawInfo,
                    services);

                PropertyEvaluatorForge optionalPropertyEvaluator = null;
                if (rawFilterSpec.OptionalPropertyEvalSpec != null) {
                    optionalPropertyEvaluator = PropertyEvaluatorForgeFactory.MakeEvaluator(
                        rawFilterSpec.OptionalPropertyEvalSpec,
                        namedWindowInfo.EventType,
                        streamSpec.OptionalStreamName,
                        statementRawInfo,
                        services);
                }

                NamedWindowConsumerStreamSpec consumer = new NamedWindowConsumerStreamSpec(
                    namedWindowInfo,
                    streamSpec.OptionalStreamName,
                    streamSpec.ViewSpecs,
                    validated.Expressions,
                    streamSpec.Options,
                    optionalPropertyEvaluator);

                return new StreamSpecCompiledDesc(consumer, validated.AdditionalForgeables);
            }

            var eventType = ResolveTypeName(eventTypeName, services.EventTypeCompileTimeResolver);

            // Validate all nodes, make sure each returns a boolean and types are good;
            // Also decompose all AND super nodes into individual expressions
            StreamTypeService streamTypeServiceX = new StreamTypeServiceImpl(
                new[] {eventType},
                new[] {streamSpec.OptionalStreamName},
                new[] {true},
                false,
                false);

            FilterSpecCompiledDesc desc = FilterSpecCompiler.MakeFilterSpec(
                eventType, 
                eventTypeName,
                rawFilterSpec.FilterExpressions,
                rawFilterSpec.OptionalPropertyEvalSpec,
                null, null, null, // no tags
                streamTypeServiceX,
                streamSpec.OptionalStreamName,
                statementRawInfo,
                services);
            
            FilterStreamSpecCompiled compiled = new FilterStreamSpecCompiled(
                desc.FilterSpecCompiled,
                streamSpec.ViewSpecs,
                streamSpec.OptionalStreamName,
                streamSpec.Options);

            return new StreamSpecCompiledDesc(compiled, desc.AdditionalForgeables);
        }