Пример #1
0
 private EventType GetAssignAnonymousType(
     StatementRawInfo statementRawInfo,
     StatementCompileTimeServices services)
 {
     IDictionary<string, object> rowType = RowType;
     var eventTypeName =
         services.EventTypeNameGeneratorStatement.GetAnonymousTypeSubselectMultirow(SubselectNumber);
     var metadata = new EventTypeMetadata(
         eventTypeName,
         statementRawInfo.ModuleName,
         EventTypeTypeClass.SUBQDERIVED,
         EventTypeApplicationType.MAP,
         NameAccessModifier.TRANSIENT,
         EventTypeBusModifier.NONBUS,
         false,
         EventTypeIdPair.Unassigned());
     var maptype = BaseNestableEventUtil.MakeMapTypeCompileTime(
         metadata,
         rowType,
         null,
         null,
         null,
         null,
         services.BeanEventTypeFactoryPrivate,
         services.EventTypeCompileTimeResolver);
     services.EventTypeCompileTimeRegistry.NewType(maptype);
     subselectMultirowType = maptype;
     return maptype;
 }
Пример #2
0
 public static EventType NewType(
     string name,
     LinkedHashMap<string, object> schemaMap,
     ViewForgeEnv env,
     int streamNum)
 {
     string outputEventTypeName =
         env.StatementCompileTimeServices.EventTypeNameGeneratorStatement.GetViewDerived(name, streamNum);
     EventTypeMetadata metadata = new EventTypeMetadata(
         outputEventTypeName,
         env.ModuleName,
         EventTypeTypeClass.VIEWDERIVED,
         EventTypeApplicationType.MAP,
         NameAccessModifier.TRANSIENT,
         EventTypeBusModifier.NONBUS,
         false,
         EventTypeIdPair.Unassigned());
     IDictionary<string, object> propertyTypes = EventTypeUtility.GetPropertyTypesNonPrimitive(schemaMap);
     EventType resultEventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
         metadata,
         propertyTypes,
         null,
         null,
         null,
         null,
         env.BeanEventTypeFactoryProtected,
         env.EventTypeCompileTimeResolver);
     env.EventTypeModuleCompileTimeRegistry.NewType(resultEventType);
     return resultEventType;
 }
Пример #3
0
        private static StreamTypeService GetStreamTypeService(
            IDictionary<string, Pair<EventType, string>> taggedEventTypes,
            IDictionary<string, Pair<EventType, string>> arrayEventTypes,
            EvalForgeNode forge,
            int streamNum,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            var filterTypes = new LinkedHashMap<string, Pair<EventType, string>>();
            filterTypes.PutAll(taggedEventTypes);

            // handle array tags (match-until clause)
            if (arrayEventTypes != null) {
                var eventTypeName =
                    services.EventTypeNameGeneratorStatement.GetAnonymousPatternName(streamNum, forge.FactoryNodeId);
                var metadata = new EventTypeMetadata(
                    eventTypeName,
                    statementRawInfo.ModuleName,
                    EventTypeTypeClass.PATTERNDERIVED,
                    EventTypeApplicationType.MAP,
                    NameAccessModifier.TRANSIENT,
                    EventTypeBusModifier.NONBUS,
                    false,
                    EventTypeIdPair.Unassigned());
                var mapProperties = GetMapProperties(
                    new Dictionary<string, Pair<EventType, string>>(),
                    arrayEventTypes);
                var mapEventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                    metadata,
                    mapProperties,
                    null,
                    null,
                    null,
                    null,
                    services.BeanEventTypeFactoryPrivate,
                    services.EventTypeCompileTimeResolver);
                services.EventTypeCompileTimeRegistry.NewType(mapEventType);

                EventType arrayTagCompositeEventType = mapEventType;
                foreach (var entry in arrayEventTypes) {
                    var tag = entry.Key;
                    if (!filterTypes.ContainsKey(tag)) {
                        var pair = new Pair<EventType, string>(arrayTagCompositeEventType, tag);
                        filterTypes.Put(tag, pair);
                    }
                }
            }

            return new StreamTypeServiceImpl(filterTypes, true, false);
        }
Пример #4
0
        public static MapEventType MakeRegisterPatternType(
            StatementBaseInfo @base,
            int stream,
            PatternStreamSpecCompiled patternStreamSpec,
            StatementCompileTimeServices services)
        {
            var patternEventTypeName = services.EventTypeNameGeneratorStatement.GetPatternTypeName(stream);
            var metadata = new EventTypeMetadata(
                patternEventTypeName,
                @base.ModuleName,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.MAP,
                NameAccessModifier.PRIVATE,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            IDictionary<string, object> propertyTypes = new LinkedHashMap<string, object>();
            foreach (var entry in patternStreamSpec.TaggedEventTypes) {
                propertyTypes.Put(entry.Key, entry.Value.First);
            }

            foreach (var entry in patternStreamSpec.ArrayEventTypes) {
                propertyTypes.Put(entry.Key, new[] {entry.Value.First});
            }

            var patternType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                metadata,
                propertyTypes,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(patternType);
            return patternType;
        }
Пример #5
0
        public static HistoricalEventViewableMethodForge CreateMethodStatementView(
            int stream,
            MethodStreamSpec methodStreamSpec,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var variableMetaData = services.VariableCompileTimeResolver.Resolve(methodStreamSpec.ClassName);
            MethodPollingExecStrategyEnum strategy;
            MethodInfo methodReflection = null;
            string eventTypeNameProvidedUDFOrScript = null;
            var contextName = @base.StatementSpec.Raw.OptionalContextName;
            var classpathImportService = services.ImportServiceCompileTime;

            // see if this is a script in the from-clause
            ExprNodeScript scriptExpression = null;
            if (methodStreamSpec.ClassName == null && methodStreamSpec.MethodName != null) {
                var script = services.ScriptCompileTimeResolver.Resolve(
                    methodStreamSpec.MethodName,
                    methodStreamSpec.Expressions.Count);
                if (script != null) {
                    scriptExpression = new ExprNodeScript(
                        services.Configuration.Compiler.Scripts.DefaultDialect,
                        script,
                        methodStreamSpec.Expressions);
                }
            }

            try {
                if (scriptExpression != null) {
                    eventTypeNameProvidedUDFOrScript = scriptExpression.EventTypeNameAnnotation;
                    strategy = MethodPollingExecStrategyEnum.TARGET_SCRIPT;
                    EPLValidationUtil.ValidateSimpleGetSubtree(
                        ExprNodeOrigin.METHODINVJOIN,
                        scriptExpression,
                        null,
                        false,
                        @base.StatementRawInfo,
                        services);
                }
                else if (variableMetaData != null) {
                    var variableName = variableMetaData.VariableName;
                    if (variableMetaData.OptionalContextName != null) {
                        if (contextName == null || !contextName.Equals(variableMetaData.OptionalContextName)) {
                            throw new ExprValidationException(
                                "Variable by name '" +
                                variableMetaData.VariableName +
                                "' has been declared for context '" +
                                variableMetaData.OptionalContextName +
                                "' and can only be used within the same context");
                        }

                        strategy = MethodPollingExecStrategyEnum.TARGET_VAR_CONTEXT;
                    }
                    else {
                        if (variableMetaData.IsConstant) {
                            strategy = MethodPollingExecStrategyEnum.TARGET_CONST;
                        }
                        else {
                            strategy = MethodPollingExecStrategyEnum.TARGET_VAR;
                        }
                    }

                    methodReflection = classpathImportService.ResolveNonStaticMethodOverloadChecked(
                        variableMetaData.Type,
                        methodStreamSpec.MethodName);
                }
                else if (methodStreamSpec.ClassName == null) { // must be either UDF or script
                    Pair<Type, ImportSingleRowDesc> udf;
                    try {
                        udf = classpathImportService.ResolveSingleRow(
                            methodStreamSpec.MethodName,
                            services.ClassProvidedExtension);
                    }
                    catch (ImportException ex) {
                        throw new ExprValidationException(
                            "Failed to find user-defined function '" + methodStreamSpec.MethodName + "': " + ex.Message,
                            ex);
                    }

                    methodReflection = classpathImportService.ResolveMethodOverloadChecked(
                        udf.First,
                        methodStreamSpec.MethodName);
                    eventTypeNameProvidedUDFOrScript = udf.Second.OptionalEventTypeName;
                    strategy = MethodPollingExecStrategyEnum.TARGET_CONST;
                }
                else {
                    methodReflection = classpathImportService.ResolveMethodOverloadChecked(
                        methodStreamSpec.ClassName,
                        methodStreamSpec.MethodName,
                        services.ClassProvidedExtension);
                    strategy = MethodPollingExecStrategyEnum.TARGET_CONST;
                }
            }
            catch (ExprValidationException) {
                throw;
            }
            catch (Exception e) {
                throw new ExprValidationException(e.Message, e);
            }

            Type methodProviderClass = null;
            Type beanClass;
            IDictionary<string, object> oaType = null;
            IDictionary<string, object> mapType = null;
            var isCollection = false;
            var isEnumerator = false;
            EventType eventType;
            EventType eventTypeWhenMethodReturnsEventBeans = null;
            var isStaticMethod = false;

            if (methodReflection != null) {
                methodProviderClass = methodReflection.DeclaringType;
                isStaticMethod = variableMetaData == null;

                // Determine object type returned by method
                beanClass = methodReflection.ReturnType;
                if (beanClass == typeof(void) || beanClass == typeof(void) || beanClass.IsBuiltinDataType()) {
                    throw new ExprValidationException(
                        "Invalid return type for static method '" +
                        methodReflection.Name +
                        "' of class '" +
                        methodStreamSpec.ClassName +
                        "', expecting a type");
                }

                if (methodReflection.ReturnType.IsArray &&
                    methodReflection.ReturnType.GetElementType() != typeof(EventBean)) {
                    beanClass = methodReflection.ReturnType.GetElementType();
                }

                isCollection = beanClass.IsGenericCollection() && !beanClass.IsGenericDictionary();
                Type collectionClass = null;
                if (isCollection) {
                    collectionClass = TypeHelper.GetGenericReturnType(methodReflection, true);
                    beanClass = collectionClass;
                }

                isEnumerator = beanClass.IsGenericEnumerator();
                Type enumerator = null;
                if (isEnumerator) {
                    enumerator = TypeHelper.GetGenericReturnType(methodReflection, true);
                    beanClass = enumerator;
                }

                // If the method returns a Map, look up the map type
                string mapTypeName = null;
                if (methodReflection.ReturnType.IsGenericDictionary() ||
                    methodReflection.ReturnType.IsArray &&
                    methodReflection.ReturnType.GetElementType().IsGenericDictionary() ||
                    isCollection && collectionClass.IsGenericDictionary() ||
                    isEnumerator && enumerator.IsGenericDictionary()) {
                    MethodMetadataDesc metadata;
                    if (variableMetaData != null) {
                        metadata = GetCheckMetadataVariable(
                            methodStreamSpec.MethodName,
                            variableMetaData,
                            classpathImportService,
                            typeof(IDictionary<string, object>));
                    }
                    else {
                        metadata = GetCheckMetadataNonVariable(
                            methodStreamSpec.MethodName,
                            methodStreamSpec.ClassName,
                            classpathImportService,
                            typeof(IDictionary<string, object>));
                    }

                    mapTypeName = metadata.TypeName;
                    mapType = (IDictionary<string, object>) metadata.TypeMetadata;
                }

                // If the method returns an Object[] or Object[][], look up the type information
                string oaTypeName = null;
                if (methodReflection.ReturnType == typeof(object[]) ||
                    methodReflection.ReturnType == typeof(object[][]) ||
                    isCollection && collectionClass == typeof(object[]) ||
                    isEnumerator && enumerator == typeof(object[])) {
                    MethodMetadataDesc metadata;
                    if (variableMetaData != null) {
                        metadata = GetCheckMetadataVariable(
                            methodStreamSpec.MethodName,
                            variableMetaData,
                            classpathImportService,
                            typeof(IDictionary<string, object>));
                    }
                    else {
                        metadata = GetCheckMetadataNonVariable(
                            methodStreamSpec.MethodName,
                            methodStreamSpec.ClassName,
                            classpathImportService,
                            typeof(IDictionary<string, object>));
                    }

                    oaTypeName = metadata.TypeName;
                    oaType = (IDictionary<string, object>) metadata.TypeMetadata;
                }

                // Determine event type from class and method name
                // If the method returns EventBean[], require the event type
                Func<EventTypeApplicationType, EventTypeMetadata> metadataFunction = apptype => {
                    var eventTypeName = services.EventTypeNameGeneratorStatement.GetAnonymousMethodHistorical(stream);
                    return new EventTypeMetadata(
                        eventTypeName,
                        @base.ModuleName,
                        EventTypeTypeClass.METHODPOLLDERIVED,
                        apptype,
                        NameAccessModifier.TRANSIENT,
                        EventTypeBusModifier.NONBUS,
                        false,
                        EventTypeIdPair.Unassigned());
                };
                if (methodReflection.ReturnType.IsArray &&
                    methodReflection.ReturnType.GetElementType() == typeof(EventBean) ||
                    isCollection && collectionClass == typeof(EventBean) ||
                    isEnumerator && enumerator == typeof(EventBean)) {
                    var typeName = methodStreamSpec.EventTypeName == null
                        ? eventTypeNameProvidedUDFOrScript
                        : methodStreamSpec.EventTypeName;
                    eventType = EventTypeUtility.RequireEventType(
                        "Method",
                        methodReflection.Name,
                        typeName,
                        services.EventTypeCompileTimeResolver);
                    eventTypeWhenMethodReturnsEventBeans = eventType;
                }
                else if (mapType != null) {
                    eventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                        metadataFunction.Invoke(EventTypeApplicationType.MAP),
                        mapType,
                        null,
                        null,
                        null,
                        null,
                        services.BeanEventTypeFactoryPrivate,
                        services.EventTypeCompileTimeResolver);
                    services.EventTypeCompileTimeRegistry.NewType(eventType);
                }
                else if (oaType != null) {
                    eventType = BaseNestableEventUtil.MakeOATypeCompileTime(
                        metadataFunction.Invoke(EventTypeApplicationType.OBJECTARR),
                        oaType,
                        null,
                        null,
                        null,
                        null,
                        services.BeanEventTypeFactoryPrivate,
                        services.EventTypeCompileTimeResolver);
                    services.EventTypeCompileTimeRegistry.NewType(eventType);
                }
                else {
                    var stem = services.BeanEventTypeStemService.GetCreateStem(beanClass, null);
                    eventType = new BeanEventType(
                        services.Container,
                        stem,
                        metadataFunction.Invoke(EventTypeApplicationType.CLASS),
                        services.BeanEventTypeFactoryPrivate,
                        null,
                        null,
                        null,
                        null);
                    services.EventTypeCompileTimeRegistry.NewType(eventType);
                }

                // the @type is only allowed in conjunction with EventBean return types
                if (methodStreamSpec.EventTypeName != null && eventTypeWhenMethodReturnsEventBeans == null) {
                    throw new ExprValidationException(EventTypeUtility.DisallowedAtTypeMessage());
                }
            }
            else {
                var eventTypeName = methodStreamSpec.EventTypeName == null
                    ? scriptExpression.EventTypeNameAnnotation
                    : methodStreamSpec.EventTypeName;
                eventType = EventTypeUtility.RequireEventType(
                    "Script",
                    scriptExpression.Script.Name,
                    eventTypeName,
                    services.EventTypeCompileTimeResolver);
            }

            // metadata
            var meta = new MethodPollingViewableMeta(
                methodProviderClass,
                isStaticMethod,
                mapType,
                oaType,
                strategy,
                isCollection,
                isEnumerator,
                variableMetaData,
                eventTypeWhenMethodReturnsEventBeans,
                scriptExpression);
            return new HistoricalEventViewableMethodForge(stream, eventType, methodStreamSpec, meta);
        }
Пример #6
0
        private static void RecursiveCompile(
            EvalForgeNode evalNode,
            ISet<string> eventTypeReferences,
            bool isInsertInto,
            MatchEventSpec tags,
            Stack<EvalForgeNode> parentNodeStack,
            ISet<string> allTagNamesOrdered,
            int streamNum,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            parentNodeStack.Push(evalNode);
            foreach (var child in evalNode.ChildNodes) {
                RecursiveCompile(
                    child,
                    eventTypeReferences,
                    isInsertInto,
                    tags,
                    parentNodeStack,
                    allTagNamesOrdered,
                    streamNum,
                    statementRawInfo,
                    services);
            }

            parentNodeStack.Pop();

            IDictionary<string, Pair<EventType, string>> newTaggedEventTypes = null;
            IDictionary<string, Pair<EventType, string>> newArrayEventTypes = null;

            if (evalNode is EvalFilterForgeNode) {
                var filterNode = (EvalFilterForgeNode) evalNode;
                var eventName = filterNode.RawFilterSpec.EventTypeName;
                if (services.TableCompileTimeResolver.Resolve(eventName) != null) {
                    throw new ExprValidationException("Tables cannot be used in pattern filter atoms");
                }

                var resolvedEventType = ResolveTypeName(eventName, services.EventTypeCompileTimeResolver);
                var finalEventType = resolvedEventType;
                var optionalTag = filterNode.EventAsName;
                var isPropertyEvaluation = false;
                var isParentMatchUntil = IsParentMatchUntil(evalNode, parentNodeStack);

                // obtain property event type, if final event type is properties
                if (filterNode.RawFilterSpec.OptionalPropertyEvalSpec != null) {
                    var optionalPropertyEvaluator = PropertyEvaluatorForgeFactory.MakeEvaluator(
                        filterNode.RawFilterSpec.OptionalPropertyEvalSpec,
                        resolvedEventType,
                        filterNode.EventAsName,
                        statementRawInfo,
                        services);
                    finalEventType = optionalPropertyEvaluator.FragmentEventType;
                    isPropertyEvaluation = true;
                }

                // If a tag was supplied for the type, the tags must stay with this type, i.e. a=BeanA -> b=BeanA -> a=BeanB is a no
                if (optionalTag != null) {
                    var pair = tags.TaggedEventTypes.Get(optionalTag);
                    EventType existingType = null;
                    if (pair != null) {
                        existingType = pair.First;
                    }

                    if (existingType == null) {
                        pair = tags.ArrayEventTypes.Get(optionalTag);
                        if (pair != null) {
                            throw new ExprValidationException(
                                "Tag '" +
                                optionalTag +
                                "' for event '" +
                                eventName +
                                "' used in the repeat-until operator cannot also appear in other filter expressions");
                        }
                    }

                    if (existingType != null && existingType != finalEventType) {
                        throw new ExprValidationException(
                            "Tag '" +
                            optionalTag +
                            "' for event '" +
                            eventName +
                            "' has already been declared for events of type " +
                            existingType.UnderlyingType.Name);
                    }

                    pair = new Pair<EventType, string>(finalEventType, eventName);

                    // add tagged type
                    if (isPropertyEvaluation || isParentMatchUntil) {
                        newArrayEventTypes = new LinkedHashMap<string, Pair<EventType, string>>();
                        newArrayEventTypes.Put(optionalTag, pair);
                    }
                    else {
                        newTaggedEventTypes = new LinkedHashMap<string, Pair<EventType, string>>();
                        newTaggedEventTypes.Put(optionalTag, pair);
                    }
                }

                // For this filter, filter types are all known tags at this time,
                // and additionally stream 0 (self) is our event type.
                // Stream type service allows resolution by property name event if that name appears in other tags.
                // by defaulting to stream zero.
                // Stream zero is always the current event type, all others follow the order of the map (stream 1 to N).
                var selfStreamName = optionalTag;
                if (selfStreamName == null) {
                    selfStreamName = "s_" + UuidGenerator.Generate();
                }

                var filterTypes = new LinkedHashMap<string, Pair<EventType, string>>();
                var typePair = new Pair<EventType, string>(finalEventType, eventName);
                filterTypes.Put(selfStreamName, typePair);
                filterTypes.PutAll(tags.TaggedEventTypes);

                // for the filter, specify all tags used
                var filterTaggedEventTypes = new LinkedHashMap<string, Pair<EventType, string>>(tags.TaggedEventTypes);
                filterTaggedEventTypes.Remove(optionalTag);

                // handle array tags (match-until clause)
                IDictionary<string, Pair<EventType, string>> arrayCompositeEventTypes = null;
                if (tags.ArrayEventTypes != null && !tags.ArrayEventTypes.IsEmpty()) {
                    arrayCompositeEventTypes = new LinkedHashMap<string, Pair<EventType, string>>();

                    foreach (var entry in tags.ArrayEventTypes) {
                        var specificArrayType = new LinkedHashMap<string, Pair<EventType, string>>();
                        specificArrayType.Put(entry.Key, entry.Value);

                        var eventTypeName = services.EventTypeNameGeneratorStatement.GetAnonymousPatternNameWTag(
                            streamNum,
                            evalNode.FactoryNodeId,
                            entry.Key);
                        var mapProps = GetMapProperties(
                            Collections.GetEmptyMap<string, Pair<EventType, string>>(),
                            specificArrayType);
                        var metadata = new EventTypeMetadata(
                            eventTypeName,
                            statementRawInfo.ModuleName,
                            EventTypeTypeClass.PATTERNDERIVED,
                            EventTypeApplicationType.MAP,
                            NameAccessModifier.TRANSIENT,
                            EventTypeBusModifier.NONBUS,
                            false,
                            EventTypeIdPair.Unassigned());
                        var mapEventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                            metadata,
                            mapProps,
                            null,
                            null,
                            null,
                            null,
                            services.BeanEventTypeFactoryPrivate,
                            services.EventTypeCompileTimeResolver);
                        services.EventTypeCompileTimeRegistry.NewType(mapEventType);

                        var tag = entry.Key;
                        if (!filterTypes.ContainsKey(tag)) {
                            var pair = new Pair<EventType, string>(mapEventType, tag);
                            filterTypes.Put(tag, pair);
                            arrayCompositeEventTypes.Put(tag, pair);
                        }
                    }
                }

                StreamTypeService streamTypeService = new StreamTypeServiceImpl(filterTypes, true, false);
                var exprNodes = filterNode.RawFilterSpec.FilterExpressions;

                var spec = FilterSpecCompiler.MakeFilterSpec(
                    resolvedEventType,
                    eventName,
                    exprNodes,
                    filterNode.RawFilterSpec.OptionalPropertyEvalSpec,
                    filterTaggedEventTypes,
                    arrayCompositeEventTypes,
                    streamTypeService,
                    null,
                    statementRawInfo,
                    services);
                filterNode.FilterSpec = spec;
            }
            else if (evalNode is EvalObserverForgeNode) {
                var observerNode = (EvalObserverForgeNode) evalNode;
                try {
                    var observerForge =
                        services.PatternResolutionService.Create(observerNode.PatternObserverSpec);

                    var streamTypeService = GetStreamTypeService(
                        tags.TaggedEventTypes,
                        tags.ArrayEventTypes,
                        observerNode,
                        streamNum,
                        statementRawInfo,
                        services);
                    var validationContext = new ExprValidationContextBuilder(
                        streamTypeService,
                        statementRawInfo,
                        services).Build();
                    var validated = ValidateExpressions(
                        ExprNodeOrigin.PATTERNOBSERVER,
                        observerNode.PatternObserverSpec.ObjectParameters,
                        validationContext);

                    var convertor = new MatchedEventConvertorForge(
                        tags.TaggedEventTypes,
                        tags.ArrayEventTypes,
                        allTagNamesOrdered);

                    observerNode.ObserverFactory = observerForge;
                    observerForge.SetObserverParameters(validated, convertor, validationContext);
                }
                catch (ObserverParameterException e) {
                    throw new ExprValidationException(
                        "Invalid parameter for pattern observer '" +
                        observerNode.ToPrecedenceFreeEPL() +
                        "': " +
                        e.Message,
                        e);
                }
                catch (PatternObjectException e) {
                    throw new ExprValidationException(
                        "Failed to resolve pattern observer '" + observerNode.ToPrecedenceFreeEPL() + "': " + e.Message,
                        e);
                }
            }
            else if (evalNode is EvalGuardForgeNode) {
                var guardNode = (EvalGuardForgeNode) evalNode;
                try {
                    var guardForge = services.PatternResolutionService.Create(guardNode.PatternGuardSpec);

                    var streamTypeService = GetStreamTypeService(
                        tags.TaggedEventTypes,
                        tags.ArrayEventTypes,
                        guardNode,
                        streamNum,
                        statementRawInfo,
                        services);
                    var validationContext = new ExprValidationContextBuilder(
                        streamTypeService,
                        statementRawInfo,
                        services).Build();
                    var validated = ValidateExpressions(
                        ExprNodeOrigin.PATTERNGUARD,
                        guardNode.PatternGuardSpec.ObjectParameters,
                        validationContext);

                    var convertor = new MatchedEventConvertorForge(
                        tags.TaggedEventTypes,
                        tags.ArrayEventTypes,
                        allTagNamesOrdered);

                    guardNode.GuardForge = guardForge;
                    guardForge.SetGuardParameters(validated, convertor, services);
                }
                catch (GuardParameterException e) {
                    throw new ExprValidationException(
                        "Invalid parameter for pattern guard '" + guardNode.ToPrecedenceFreeEPL() + "': " + e.Message,
                        e);
                }
                catch (PatternObjectException e) {
                    throw new ExprValidationException(
                        "Failed to resolve pattern guard '" + guardNode.ToPrecedenceFreeEPL() + "': " + e.Message,
                        e);
                }
            }
            else if (evalNode is EvalEveryDistinctForgeNode) {
                var distinctNode = (EvalEveryDistinctForgeNode) evalNode;
                var matchEventFromChildNodes = AnalyzeMatchEvent(distinctNode);
                var streamTypeService = GetStreamTypeService(
                    matchEventFromChildNodes.TaggedEventTypes,
                    matchEventFromChildNodes.ArrayEventTypes,
                    distinctNode,
                    streamNum,
                    statementRawInfo,
                    services);
                var validationContext =
                    new ExprValidationContextBuilder(streamTypeService, statementRawInfo, services).Build();
                IList<ExprNode> validated;
                try {
                    validated = ValidateExpressions(
                        ExprNodeOrigin.PATTERNEVERYDISTINCT,
                        distinctNode.Expressions,
                        validationContext);
                }
                catch (ExprValidationPropertyException ex) {
                    throw new ExprValidationPropertyException(
                        ex.Message +
                        ", every-distinct requires that all properties resolve from sub-expressions to the every-distinct",
                        ex.InnerException);
                }

                var convertor = new MatchedEventConvertorForge(
                    matchEventFromChildNodes.TaggedEventTypes,
                    matchEventFromChildNodes.ArrayEventTypes,
                    allTagNamesOrdered);

                distinctNode.Convertor = convertor;

                // Determine whether some expressions are constants or time period
                IList<ExprNode> distinctExpressions = new List<ExprNode>();
                TimePeriodComputeForge timePeriodComputeForge = null;
                ExprNode expiryTimeExp = null;
                var count = -1;
                var last = validated.Count - 1;
                foreach (var expr in validated) {
                    count++;
                    if (count == last && expr is ExprTimePeriod) {
                        expiryTimeExp = expr;
                        var timePeriodExpr = (ExprTimePeriod) expiryTimeExp;
                        timePeriodComputeForge = timePeriodExpr.TimePeriodComputeForge;
                    }
                    else if (expr.Forge.ForgeConstantType.IsCompileTimeConstant) {
                        if (count == last) {
                            var value = expr.Forge.ExprEvaluator.Evaluate(null, true, null);
                            if (!value.IsNumber()) {
                                throw new ExprValidationException(
                                    "Invalid parameter for every-distinct, expected number of seconds constant (constant not considered for distinct)");
                            }

                            var secondsExpire = expr.Forge.ExprEvaluator.Evaluate(null, true, null);
                            var timeExpire = secondsExpire == null
                                ? (long?) null
                                : (long?) services.ImportServiceCompileTime.TimeAbacus.DeltaForSecondsNumber(
                                    secondsExpire);
                            if (timeExpire != null && timeExpire > 0) {
                                timePeriodComputeForge = new TimePeriodComputeConstGivenDeltaForge(timeExpire.Value);
                                expiryTimeExp = expr;
                            }
                            else {
                                Log.Warn(
                                    "Invalid seconds-expire " +
                                    timeExpire +
                                    " for " +
                                    ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(expr));
                            }
                        }
                        else {
                            Log.Warn(
                                "Every-distinct node utilizes an expression returning a constant value, please check expression '" +
                                ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(expr) +
                                "', not adding expression to distinct-value expression list");
                        }
                    }
                    else {
                        distinctExpressions.Add(expr);
                    }
                }

                if (distinctExpressions.IsEmpty()) {
                    throw new ExprValidationException(
                        "Every-distinct node requires one or more distinct-value expressions that each return non-constant result values");
                }

                distinctNode.SetDistinctExpressions(distinctExpressions, timePeriodComputeForge, expiryTimeExp);
            }
            else if (evalNode is EvalMatchUntilForgeNode) {
                var matchUntilNode = (EvalMatchUntilForgeNode) evalNode;

                // compile bounds expressions, if any
                var untilMatchEventSpec = new MatchEventSpec(tags.TaggedEventTypes, tags.ArrayEventTypes);
                var streamTypeService = GetStreamTypeService(
                    untilMatchEventSpec.TaggedEventTypes,
                    untilMatchEventSpec.ArrayEventTypes,
                    matchUntilNode,
                    streamNum,
                    statementRawInfo,
                    services);
                var validationContext =
                    new ExprValidationContextBuilder(streamTypeService, statementRawInfo, services).Build();

                var lower = ValidateBounds(matchUntilNode.LowerBounds, validationContext);
                matchUntilNode.LowerBounds = lower;

                var upper = ValidateBounds(matchUntilNode.UpperBounds, validationContext);
                matchUntilNode.UpperBounds = upper;

                var single = ValidateBounds(matchUntilNode.SingleBound, validationContext);
                matchUntilNode.SingleBound = single;

                bool tightlyBound;
                if (matchUntilNode.SingleBound != null) {
                    ValidateMatchUntil(matchUntilNode.SingleBound, matchUntilNode.SingleBound, false);
                    tightlyBound = true;
                }
                else {
                    var allowZeroLowerBounds = matchUntilNode.LowerBounds != null && matchUntilNode.UpperBounds != null;
                    tightlyBound = ValidateMatchUntil(
                        matchUntilNode.LowerBounds,
                        matchUntilNode.UpperBounds,
                        allowZeroLowerBounds);
                }

                if (matchUntilNode.SingleBound == null && !tightlyBound && matchUntilNode.ChildNodes.Count < 2) {
                    throw new ExprValidationException("Variable bounds repeat operator requires an until-expression");
                }

                var convertor = new MatchedEventConvertorForge(
                    untilMatchEventSpec.TaggedEventTypes,
                    untilMatchEventSpec.ArrayEventTypes,
                    allTagNamesOrdered);

                matchUntilNode.Convertor = convertor;

                // compile new tag lists
                ISet<string> arrayTags = null;
                var matchUntilAnalysisResult = EvalNodeUtil.RecursiveAnalyzeChildNodes(matchUntilNode.ChildNodes[0]);
                foreach (var filterNode in matchUntilAnalysisResult.FilterNodes) {
                    var optionalTag = filterNode.EventAsName;
                    if (optionalTag != null) {
                        if (arrayTags == null) {
                            arrayTags = new HashSet<string>();
                        }

                        arrayTags.Add(optionalTag);
                    }
                }

                if (arrayTags != null) {
                    foreach (var arrayTag in arrayTags) {
                        if (!tags.ArrayEventTypes.ContainsKey(arrayTag)) {
                            tags.ArrayEventTypes.Put(arrayTag, tags.TaggedEventTypes.Get(arrayTag));
                            tags.TaggedEventTypes.Remove(arrayTag);
                        }
                    }
                }

                matchUntilNode.TagsArrayedSet = GetIndexesForTags(allTagNamesOrdered, arrayTags);
            }
            else if (evalNode is EvalFollowedByForgeNode) {
                var followedByNode = (EvalFollowedByForgeNode) evalNode;
                StreamTypeService streamTypeService = new StreamTypeServiceImpl(false);
                var validationContext =
                    new ExprValidationContextBuilder(streamTypeService, statementRawInfo, services).Build();

                if (followedByNode.OptionalMaxExpressions != null) {
                    IList<ExprNode> validated = new List<ExprNode>();
                    foreach (var maxExpr in followedByNode.OptionalMaxExpressions) {
                        if (maxExpr == null) {
                            validated.Add(null);
                        }
                        else {
                            var visitor = new ExprNodeSummaryVisitor();
                            maxExpr.Accept(visitor);
                            if (!visitor.IsPlain) {
                                var errorMessage = "Invalid maximum expression in followed-by, " +
                                                   visitor.Message +
                                                   " are not allowed within the expression";
                                Log.Error(errorMessage);
                                throw new ExprValidationException(errorMessage);
                            }

                            var validatedExpr = ExprNodeUtilityValidate.GetValidatedSubtree(
                                ExprNodeOrigin.FOLLOWEDBYMAX,
                                maxExpr,
                                validationContext);
                            validated.Add(validatedExpr);
                            var returnType = validatedExpr.Forge.EvaluationType;
                            if (returnType == null || !returnType.IsNumeric()) {
                                var message =
                                    "Invalid maximum expression in followed-by, the expression must return an integer value";
                                throw new ExprValidationException(message);
                            }
                        }
                    }

                    followedByNode.OptionalMaxExpressions = validated;
                }
            }

            if (newTaggedEventTypes != null) {
                tags.TaggedEventTypes.PutAll(newTaggedEventTypes);
            }

            if (newArrayEventTypes != null) {
                tags.ArrayEventTypes.PutAll(newArrayEventTypes);
            }
        }
Пример #7
0
        public static RowRecogPlan ValidateAndPlan(
            IContainer container,
            EventType parentEventType,
            bool unbound,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var statementRawInfo = @base.StatementRawInfo;
            var matchRecognizeSpec = @base.StatementSpec.Raw.MatchRecognizeSpec;
            var annotations = statementRawInfo.Annotations;
            var iterateOnly = HintEnum.ITERATE_ONLY.GetHint(annotations) != null;
            var additionalForgeables = new List<StmtClassForgeableFactory>();

            // Expanded pattern already there
            RowRecogExprNode expandedPatternNode = matchRecognizeSpec.Pattern;

            // Determine single-row and multiple-row variables
            var variablesSingle = new LinkedHashSet<string>();
            var variablesMultiple = new LinkedHashSet<string>();
            RowRecogHelper.RecursiveInspectVariables(expandedPatternNode, false, variablesSingle, variablesMultiple);

            // each variable gets associated with a stream number (multiple-row variables as well to hold the current event for the expression).
            var streamNum = 0;
            var variableStreams = new LinkedHashMap<string, Pair<int, bool>>();
            foreach (var variableSingle in variablesSingle) {
                variableStreams.Put(variableSingle, new Pair<int, bool>(streamNum, false));
                streamNum++;
            }

            foreach (var variableMultiple in variablesMultiple) {
                variableStreams.Put(variableMultiple, new Pair<int, bool>(streamNum, true));
                streamNum++;
            }

            // mapping of stream to variable
            var streamVariables = new OrderedListDictionary<int, string>();
            foreach (var entry in variableStreams) {
                streamVariables.Put(entry.Value.First, entry.Key);
            }

            // determine visibility rules
            var visibility = RowRecogHelper.DetermineVisibility(expandedPatternNode);

            // assemble all single-row variables for expression validation
            var allStreamNames = new string[variableStreams.Count];
            var allTypes = new EventType[variableStreams.Count];

            streamNum = 0;
            foreach (var variableSingle in variablesSingle) {
                allStreamNames[streamNum] = variableSingle;
                allTypes[streamNum] = parentEventType;
                streamNum++;
            }

            foreach (var variableMultiple in variablesMultiple) {
                allStreamNames[streamNum] = variableMultiple;
                allTypes[streamNum] = parentEventType;
                streamNum++;
            }

            // determine type service for use with DEFINE
            // validate each DEFINE clause expression
            ISet<string> definedVariables = new HashSet<string>();
            IList<ExprAggregateNode> aggregateNodes = new List<ExprAggregateNode>();
            var isExprRequiresMultimatchState = new bool[variableStreams.Count];
            var previousNodes = new OrderedListDictionary<int, IList<ExprPreviousMatchRecognizeNode>>();

            for (var defineIndex = 0; defineIndex < matchRecognizeSpec.Defines.Count; defineIndex++) {
                MatchRecognizeDefineItem defineItem = matchRecognizeSpec.Defines[defineIndex];
                if (definedVariables.Contains(defineItem.Identifier)) {
                    throw new ExprValidationException(
                        "Variable '" + defineItem.Identifier + "' has already been defined");
                }

                definedVariables.Add(defineItem.Identifier);

                // stream-type visibilities handled here
                var typeServiceDefines = BuildDefineStreamTypeServiceDefine(
                    defineIndex,
                    variableStreams,
                    defineItem,
                    visibility,
                    parentEventType,
                    statementRawInfo,
                    services);

                var exprNodeResult = HandlePreviousFunctions(defineItem.Expression, previousNodes);
                var validationContext = new ExprValidationContextBuilder(typeServiceDefines, statementRawInfo, services)
                    .WithAllowBindingConsumption(true)
                    .WithDisablePropertyExpressionEventCollCache(true)
                    .Build();

                ExprNode validated;
                try {
                    // validate
                    validated = ExprNodeUtilityValidate.GetValidatedSubtree(
                        ExprNodeOrigin.MATCHRECOGDEFINE,
                        exprNodeResult,
                        validationContext);

                    // check aggregates
                    defineItem.Expression = validated;
                    ExprAggregateNodeUtil.GetAggregatesBottomUp(validated, aggregateNodes);
                    if (!aggregateNodes.IsEmpty()) {
                        throw new ExprValidationException("An aggregate function may not appear in a DEFINE clause");
                    }
                }
                catch (ExprValidationException ex) {
                    throw new ExprValidationException(
                        "Failed to validate condition expression for variable '" +
                        defineItem.Identifier +
                        "': " +
                        ex.Message,
                        ex);
                }

                // determine access to event properties from multi-matches
                var visitor = new ExprNodeStreamRequiredVisitor();
                validated.Accept(visitor);
                var streamsRequired = visitor.StreamsRequired;
                foreach (var streamRequired in streamsRequired) {
                    if (streamRequired >= variableStreams.Count) {
                        var streamNumIdent = variableStreams.Get(defineItem.Identifier).First;
                        isExprRequiresMultimatchState[streamNumIdent] = true;
                        break;
                    }
                }
            }

            var defineAsksMultimatches = CollectionUtil.IsAnySet(isExprRequiresMultimatchState);

            // determine type service for use with MEASURE
            IDictionary<string, object> measureTypeDef = new LinkedHashMap<string, object>();
            foreach (var variableSingle in variablesSingle) {
                measureTypeDef.Put(variableSingle, parentEventType);
            }

            foreach (var variableMultiple in variablesMultiple) {
                measureTypeDef.Put(variableMultiple, new[] {parentEventType});
            }

            var compositeTypeName = services.EventTypeNameGeneratorStatement.AnonymousRowrecogCompositeName;
            var compositeTypeMetadata = new EventTypeMetadata(
                compositeTypeName,
                @base.ModuleName,
                EventTypeTypeClass.MATCHRECOGDERIVED,
                EventTypeApplicationType.OBJECTARR,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var compositeEventType = BaseNestableEventUtil.MakeOATypeCompileTime(
                compositeTypeMetadata,
                measureTypeDef,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(compositeEventType);
            StreamTypeService compositeTypeServiceMeasure =
                new StreamTypeServiceImpl(compositeEventType, "MATCH_RECOGNIZE", true);

            // find MEASURE clause aggregations
            var measureReferencesMultivar = false;
            IList<ExprAggregateNode> measureAggregateExprNodes = new List<ExprAggregateNode>();
            foreach (var measureItem in matchRecognizeSpec.Measures) {
                ExprAggregateNodeUtil.GetAggregatesBottomUp(measureItem.Expr, measureAggregateExprNodes);
            }

            AggregationServiceForgeDesc[] aggregationServices = null;
            if (!measureAggregateExprNodes.IsEmpty()) {
                aggregationServices = PlanAggregations(
                    measureAggregateExprNodes,
                    compositeTypeServiceMeasure,
                    allStreamNames,
                    allTypes,
                    streamVariables,
                    variablesMultiple,
                    @base,
                    services);
                foreach (AggregationServiceForgeDesc svc in aggregationServices) {
                    if (svc != null) {
                        additionalForgeables.AddAll(svc.AdditionalForgeables);
                    }
                }
            }

            // validate each MEASURE clause expression
            IDictionary<string, object> rowTypeDef = new LinkedHashMap<string, object>();
            var streamRefVisitor = new ExprNodeStreamUseCollectVisitor();
            foreach (var measureItem in matchRecognizeSpec.Measures) {
                if (measureItem.Name == null) {
                    throw new ExprValidationException(
                        "The measures clause requires that each expression utilizes the AS keyword to assign a column name");
                }

                var validated = ValidateMeasureClause(
                    measureItem.Expr,
                    compositeTypeServiceMeasure,
                    variablesMultiple,
                    variablesSingle,
                    statementRawInfo,
                    services);
                measureItem.Expr = validated;
                rowTypeDef.Put(measureItem.Name, validated.Forge.EvaluationType);
                validated.Accept(streamRefVisitor);
            }

            // Determine if any of the multi-var streams are referenced in the measures (non-aggregated only)
            foreach (var @ref in streamRefVisitor.Referenced) {
                var rootPropName = @ref.RootPropertyNameIfAny;
                if (rootPropName != null) {
                    if (variablesMultiple.Contains(rootPropName)) {
                        measureReferencesMultivar = true;
                        break;
                    }
                }

                var streamRequired = @ref.StreamReferencedIfAny;
                if (streamRequired != null) {
                    var streamVariable = streamVariables.Get(streamRequired.Value);
                    if (streamVariable != null) {
                        var def = variableStreams.Get(streamVariable);
                        if (def != null && def.Second) {
                            measureReferencesMultivar = true;
                            break;
                        }
                    }
                }
            }

            var collectMultimatches = measureReferencesMultivar || defineAsksMultimatches;

            // create rowevent type
            var rowTypeName = services.EventTypeNameGeneratorStatement.AnonymousRowrecogRowName;
            var rowTypeMetadata = new EventTypeMetadata(
                rowTypeName,
                @base.ModuleName,
                EventTypeTypeClass.MATCHRECOGDERIVED,
                EventTypeApplicationType.MAP,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var rowEventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                rowTypeMetadata,
                rowTypeDef,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(rowEventType);

            // validate partition-by expressions, if any
            ExprNode[] partitionBy;
            MultiKeyClassRef partitionMultiKey;
            if (!matchRecognizeSpec.PartitionByExpressions.IsEmpty()) {
                StreamTypeService typeServicePartition = new StreamTypeServiceImpl(
                    parentEventType,
                    "MATCH_RECOGNIZE_PARTITION",
                    true);
                IList<ExprNode> validated = new List<ExprNode>();
                var validationContext =
                    new ExprValidationContextBuilder(typeServicePartition, statementRawInfo, services)
                        .WithAllowBindingConsumption(true)
                        .Build();
                foreach (var partitionExpr in matchRecognizeSpec.PartitionByExpressions) {
                    validated.Add(
                        ExprNodeUtilityValidate.GetValidatedSubtree(
                            ExprNodeOrigin.MATCHRECOGPARTITION,
                            partitionExpr,
                            validationContext));
                }

                matchRecognizeSpec.PartitionByExpressions = validated;
                partitionBy = ExprNodeUtilityQuery.ToArray(validated);
                MultiKeyPlan multiKeyPlan = MultiKeyPlanner.PlanMultiKey(partitionBy, false, @base.StatementRawInfo, services.SerdeResolver);
                partitionMultiKey = multiKeyPlan.ClassRef;
                additionalForgeables.AddAll(multiKeyPlan.MultiKeyForgeables);
            }
            else {
                partitionBy = null;
                partitionMultiKey = null;
            }

            // validate interval if present
            if (matchRecognizeSpec.Interval != null) {
                var validationContext =
                    new ExprValidationContextBuilder(new StreamTypeServiceImpl(false), statementRawInfo, services)
                        .WithAllowBindingConsumption(true)
                        .Build();
                var validated = (ExprTimePeriod) ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.MATCHRECOGINTERVAL,
                    matchRecognizeSpec.Interval.TimePeriodExpr,
                    validationContext);
                matchRecognizeSpec.Interval.TimePeriodExpr = validated;
            }

            // compile variable definition expressions
            IDictionary<string, ExprNode> variableDefinitions = new Dictionary<string, ExprNode>();
            foreach (var defineItem in matchRecognizeSpec.Defines) {
                variableDefinitions.Put(defineItem.Identifier, defineItem.Expression);
            }

            // create evaluators
            var columnNames = new string[matchRecognizeSpec.Measures.Count];
            var columnForges = new ExprNode[matchRecognizeSpec.Measures.Count];
            var count = 0;
            foreach (var measureItem in matchRecognizeSpec.Measures) {
                columnNames[count] = measureItem.Name;
                columnForges[count] = measureItem.Expr;
                count++;
            }

            // build states
            var strand = RowRecogHelper.BuildStartStates(
                expandedPatternNode,
                variableDefinitions,
                variableStreams,
                isExprRequiresMultimatchState);
            var startStates = strand.StartStates.ToArray();
            RowRecogNFAStateForge[] allStates = strand.AllStates.ToArray();

            if (Log.IsInfoEnabled) {
                Log.Info("NFA tree:\n" + RowRecogNFAViewUtil.Print(startStates));
            }

            // determine names of multimatching variables
            string[] multimatchVariablesArray;
            int[] multimatchStreamNumToVariable;
            int[] multimatchVariableToStreamNum;
            if (variablesSingle.Count == variableStreams.Count) {
                multimatchVariablesArray = new string[0];
                multimatchStreamNumToVariable = new int[0];
                multimatchVariableToStreamNum = new int[0];
            }
            else {
                multimatchVariablesArray = new string[variableStreams.Count - variablesSingle.Count];
                multimatchVariableToStreamNum = new int[multimatchVariablesArray.Length];
                multimatchStreamNumToVariable = new int[variableStreams.Count];
                CompatExtensions.Fill(multimatchStreamNumToVariable, -1);
                count = 0;
                foreach (var entry in variableStreams) {
                    if (entry.Value.Second) {
                        var index = count;
                        multimatchVariablesArray[index] = entry.Key;
                        multimatchVariableToStreamNum[index] = entry.Value.First;
                        multimatchStreamNumToVariable[entry.Value.First] = index;
                        count++;
                    }
                }
            }

            var numEventsEventsPerStreamDefine =
                defineAsksMultimatches ? variableStreams.Count + 1 : variableStreams.Count;

            // determine interval-or-terminated
            var orTerminated = matchRecognizeSpec.Interval != null && matchRecognizeSpec.Interval.IsOrTerminated;
            TimePeriodComputeForge intervalCompute = null;
            if (matchRecognizeSpec.Interval != null) {
                intervalCompute = matchRecognizeSpec.Interval.TimePeriodExpr.TimePeriodComputeForge;
            }

            EventType multimatchEventType = null;
            if (defineAsksMultimatches) {
                multimatchEventType = GetDefineMultimatchEventType(variableStreams, parentEventType, @base, services);
            }

            // determine previous-access indexes and assign "prev" node indexes
            // Since an expression such as "prior(2, price), prior(8, price)" translates into {2, 8} the relative index is {0, 1}.
            // Map the expression-supplied index to a relative index
            int[] previousRandomAccessIndexes = null;
            if (!previousNodes.IsEmpty()) {
                previousRandomAccessIndexes = new int[previousNodes.Count];
                var countPrev = 0;
                foreach (var entry in previousNodes) {
                    previousRandomAccessIndexes[countPrev] = entry.Key;
                    foreach (var callback in entry.Value) {
                        callback.AssignedIndex = countPrev;
                    }

                    countPrev++;
                }
            }

            RowRecogDescForge forge = new RowRecogDescForge(
                parentEventType,
                rowEventType,
                compositeEventType,
                multimatchEventType,
                multimatchStreamNumToVariable,
                multimatchVariableToStreamNum,
                partitionBy,
                partitionMultiKey,
                variableStreams,
                matchRecognizeSpec.Interval != null,
                iterateOnly,
                unbound,
                orTerminated,
                collectMultimatches,
                defineAsksMultimatches,
                numEventsEventsPerStreamDefine,
                multimatchVariablesArray,
                startStates,
                allStates,
                matchRecognizeSpec.IsAllMatches,
                matchRecognizeSpec.Skip.Skip,
                columnForges,
                columnNames,
                intervalCompute,
                previousRandomAccessIndexes,
                aggregationServices);
            
            return new RowRecogPlan(forge, additionalForgeables);
        }
Пример #8
0
        public StmtForgeMethodResult Make(
            string @namespace,
            string classPostfix,
            StatementCompileTimeServices services)
        {
            var statementSpec = @base.StatementSpec;
            if (statementSpec.Raw.OptionalContextName != null) {
                throw new ExprValidationException(
                    "A create-context statement cannot itself be associated to a context, please declare a nested context instead");
            }

            IList<FilterSpecCompiled> filterSpecCompileds = new List<FilterSpecCompiled>();
            IList<ScheduleHandleCallbackProvider> scheduleHandleCallbackProviders =
                new List<ScheduleHandleCallbackProvider>();
            IList<FilterSpecParamExprNodeForge> filterBooleanExpressions = new List<FilterSpecParamExprNodeForge>();

            var context = statementSpec.Raw.CreateContextDesc;
            if (services.ContextCompileTimeResolver.GetContextInfo(context.ContextName) != null) {
                throw new ExprValidationException("Context by name '" + context.ContextName + "' already exists");
            }

            // compile filter specs, if any
            var validationEnv = new CreateContextValidationEnv(
                context.ContextName,
                @base.StatementRawInfo,
                services,
                filterSpecCompileds,
                scheduleHandleCallbackProviders,
                filterBooleanExpressions);
            var additionalForgeables = ValidateContextDetail(
                context.ContextDetail,
                0,
                validationEnv);

            // get controller factory forges
            var controllerFactoryForges = GetForges(
                context.ContextName,
                context.ContextDetail);

            // build context properties type information
            var contextProps = MakeContextProperties(
                controllerFactoryForges,
                @base.StatementRawInfo,
                services);

            // allocate type for context properties
            var contextEventTypeName =
                services.EventTypeNameGeneratorStatement.GetContextPropertyTypeName(context.ContextName);
            var metadata = new EventTypeMetadata(
                contextEventTypeName,
                @base.ModuleName,
                EventTypeTypeClass.CONTEXTPROPDERIVED,
                EventTypeApplicationType.MAP,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var contextPropertiesType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                metadata,
                contextProps,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(contextPropertiesType);

            // register context
            var visibilityContext =
                services.ModuleVisibilityRules.GetAccessModifierContext(@base, context.ContextName);
            var validationInfo =
                new ContextControllerPortableInfo[controllerFactoryForges.Length];
            for (var i = 0; i < validationInfo.Length; i++) {
                validationInfo[i] = controllerFactoryForges[i].ValidationInfo;
            }

            var detail = new ContextMetaData(
                context.ContextName,
                @base.ModuleName,
                visibilityContext,
                contextPropertiesType,
                validationInfo);
            services.ContextCompileTimeRegistry.NewContext(detail);

            // define output event type
            var statementEventTypeName =
                services.EventTypeNameGeneratorStatement.GetContextStatementTypeName(context.ContextName);
            var statementTypeMetadata = new EventTypeMetadata(
                statementEventTypeName,
                @base.ModuleName,
                EventTypeTypeClass.STATEMENTOUT,
                EventTypeApplicationType.MAP,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            EventType statementEventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                statementTypeMetadata,
                EmptyDictionary<string, object>.Instance,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(statementEventType);

            var statementFieldsClassName = CodeGenerationIDGenerator
                .GenerateClassNameSimple(typeof(StatementFields), classPostfix);
            var namespaceScope = new CodegenNamespaceScope(
                @namespace,
                statementFieldsClassName,
                services.IsInstrumented);

            var forgeables = new List<StmtClassForgeable>();
            foreach (var additional in additionalForgeables) {
                forgeables.Add(additional.Make(namespaceScope, classPostfix));
            }

            var statementProviderClassName =
                CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementProvider), classPostfix);
            var statementAIFactoryProviderClassName =
                CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementAIFactoryProvider), classPostfix);

            var forge =
                new StatementAgentInstanceFactoryCreateContextForge(context.ContextName, statementEventType);
            forgeables.Add(
                new StmtClassForgeableAIFactoryProviderCreateContext(
                    statementAIFactoryProviderClassName,
                    namespaceScope,
                    context.ContextName,
                    controllerFactoryForges,
                    contextPropertiesType,
                    forge));

            var selectSubscriberDescriptor = new SelectSubscriberDescriptor();
            var informationals = StatementInformationalsUtil.GetInformationals(
                @base,
                filterSpecCompileds,
                scheduleHandleCallbackProviders,
                EmptyList<NamedWindowConsumerStreamSpec>.Instance,
                false,
                selectSubscriberDescriptor,
                namespaceScope,
                services);
            informationals.Properties.Put(StatementProperty.CREATEOBJECTNAME, context.ContextName);
            forgeables.Add(
                new StmtClassForgeableStmtProvider(
                    statementAIFactoryProviderClassName,
                    statementProviderClassName,
                    informationals,
                    namespaceScope));
            forgeables.Add(
                new StmtClassForgeableStmtFields(
                    statementFieldsClassName,
                    namespaceScope,
                    0));

            return new StmtForgeMethodResult(
                forgeables,
                filterSpecCompileds,
                scheduleHandleCallbackProviders,
                EmptyList<NamedWindowConsumerStreamSpec>.Instance,
                FilterSpecCompiled.MakeExprNodeList(filterSpecCompileds, filterBooleanExpressions));
        }
Пример #9
0
        private static void ValidateMergeDesc(
            OnTriggerMergeDesc mergeDesc,
            EventType namedWindowType,
            string namedWindowName,
            EventType triggerStreamType,
            string triggerStreamName,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            var exprNodeErrorMessage = "Aggregation functions may not be used within an merge-clause";

            var dummyTypeNoPropertiesMeta = new EventTypeMetadata(
                "merge_named_window_insert",
                statementRawInfo.ModuleName,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.MAP,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            EventType dummyTypeNoProperties = BaseNestableEventUtil.MakeMapTypeCompileTime(
                dummyTypeNoPropertiesMeta,
                Collections.GetEmptyMap<string, object>(),
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            StreamTypeService insertOnlyTypeSvc = new StreamTypeServiceImpl(
                new[] {dummyTypeNoProperties, triggerStreamType},
                new[] {UuidGenerator.Generate(), triggerStreamName},
                new[] {true, true},
                true,
                false);
            var twoStreamTypeSvc = new StreamTypeServiceImpl(
                new[] {namedWindowType, triggerStreamType},
                new[] {namedWindowName, triggerStreamName},
                new[] {true, true},
                true,
                false);

            foreach (var matchedItem in mergeDesc.Items) {
                // we may provide an additional stream "initial" for the prior value, unless already defined
                StreamTypeServiceImpl assignmentStreamTypeSvc;
                if (namedWindowName.Equals(INITIAL_VALUE_STREAM_NAME) ||
                    triggerStreamName.Equals(INITIAL_VALUE_STREAM_NAME)) {
                    assignmentStreamTypeSvc = twoStreamTypeSvc;
                }
                else {
                    assignmentStreamTypeSvc = new StreamTypeServiceImpl(
                        new[] {namedWindowType, triggerStreamType, namedWindowType},
                        new[] {namedWindowName, triggerStreamName, INITIAL_VALUE_STREAM_NAME},
                        new[] {true, true, true},
                        false,
                        false);
                    assignmentStreamTypeSvc.IsStreamZeroUnambigous = true;
                }

                if (matchedItem.OptionalMatchCond != null) {
                    var matchValidStreams = matchedItem.IsMatchedUnmatched ? twoStreamTypeSvc : insertOnlyTypeSvc;
                    matchedItem.OptionalMatchCond = EPStatementStartMethodHelperValidate.ValidateExprNoAgg(
                        ExprNodeOrigin.MERGEMATCHCOND,
                        matchedItem.OptionalMatchCond,
                        matchValidStreams,
                        exprNodeErrorMessage,
                        true,
                        statementRawInfo,
                        services);
                    if (!matchedItem.IsMatchedUnmatched) {
                        EPStatementStartMethodHelperValidate.ValidateSubqueryExcludeOuterStream(
                            matchedItem.OptionalMatchCond);
                    }
                }

                foreach (var item in matchedItem.Actions) {
                    if (item is OnTriggerMergeActionDelete) {
                        var delete = (OnTriggerMergeActionDelete) item;
                        if (delete.OptionalWhereClause != null) {
                            delete.OptionalWhereClause = EPStatementStartMethodHelperValidate.ValidateExprNoAgg(
                                ExprNodeOrigin.MERGEMATCHWHERE,
                                delete.OptionalWhereClause,
                                twoStreamTypeSvc,
                                exprNodeErrorMessage,
                                true,
                                statementRawInfo,
                                services);
                        }
                    }
                    else if (item is OnTriggerMergeActionUpdate) {
                        var update = (OnTriggerMergeActionUpdate) item;
                        if (update.OptionalWhereClause != null) {
                            update.OptionalWhereClause = EPStatementStartMethodHelperValidate.ValidateExprNoAgg(
                                ExprNodeOrigin.MERGEMATCHWHERE,
                                update.OptionalWhereClause,
                                twoStreamTypeSvc,
                                exprNodeErrorMessage,
                                true,
                                statementRawInfo,
                                services);
                        }

                        foreach (var assignment in update.Assignments) {
                            assignment.Expression = EPStatementStartMethodHelperValidate.ValidateExprNoAgg(
                                ExprNodeOrigin.UPDATEASSIGN,
                                assignment.Expression,
                                assignmentStreamTypeSvc,
                                exprNodeErrorMessage,
                                true,
                                statementRawInfo,
                                services);
                        }
                    }
                    else if (item is OnTriggerMergeActionInsert) {
                        var insert = (OnTriggerMergeActionInsert) item;

                        var insertTypeSvc = GetInsertStreamService(
                            insert.OptionalStreamName,
                            namedWindowName,
                            insertOnlyTypeSvc,
                            twoStreamTypeSvc);

                        if (insert.OptionalWhereClause != null) {
                            insert.OptionalWhereClause = EPStatementStartMethodHelperValidate.ValidateExprNoAgg(
                                ExprNodeOrigin.MERGEMATCHWHERE,
                                insert.OptionalWhereClause,
                                insertTypeSvc,
                                exprNodeErrorMessage,
                                true,
                                statementRawInfo,
                                services);
                        }

                        var compiledSelect = ValidateInsertSelect(
                            insert.SelectClause,
                            insertTypeSvc,
                            insert.Columns,
                            statementRawInfo,
                            services);
                        insert.SelectClauseCompiled = compiledSelect;
                    }
                    else {
                        throw new ArgumentException("Unrecognized merge item '" + item.GetType().Name + "'");
                    }
                }
            }

            if (mergeDesc.OptionalInsertNoMatch != null) {
                var insertTypeSvc = GetInsertStreamService(
                    mergeDesc.OptionalInsertNoMatch.OptionalStreamName,
                    namedWindowName,
                    insertOnlyTypeSvc,
                    twoStreamTypeSvc);
                var compiledSelect = ValidateInsertSelect(
                    mergeDesc.OptionalInsertNoMatch.SelectClause,
                    insertTypeSvc,
                    mergeDesc.OptionalInsertNoMatch.Columns,
                    statementRawInfo,
                    services);
                mergeDesc.OptionalInsertNoMatch.SelectClauseCompiled = compiledSelect;
            }
        }
Пример #10
0
        public static OnTriggerSetPlan HandleSetVariable(
            string className,
            CodegenNamespaceScope namespaceScope,
            string classPostfix,
            OnTriggerActivatorDesc activatorResult,
            string optionalStreamName,
            IDictionary<ExprSubselectNode, SubSelectActivationPlan> subselectActivation,
            OnTriggerSetDesc desc,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            StreamTypeService typeService = new StreamTypeServiceImpl(
                new[] {activatorResult.ActivatorResultEventType},
                new[] {optionalStreamName},
                new[] {true},
                false,
                false);
            var validationContext = new ExprValidationContextBuilder(typeService, @base.StatementRawInfo, services)
                .WithAllowBindingConsumption(true)
                .Build();

            // handle subselects
            var subselectForges = SubSelectHelperForgePlanner.PlanSubSelect(
                @base,
                subselectActivation,
                new[] {optionalStreamName},
                new[] {activatorResult.ActivatorResultEventType},
                new[] {activatorResult.TriggerEventTypeName},
                services);

            // validate assignments
            foreach (var assignment in desc.Assignments) {
                var validated = ExprNodeUtilityValidate.GetValidatedAssignment(assignment, validationContext);
                assignment.Expression = validated;
            }

            // create read-write logic
            var variableReadWritePackageForge = new VariableReadWritePackageForge(desc.Assignments, services);

            // plan table access
            var tableAccessForges = ExprTableEvalHelperPlan.PlanTableAccess(@base.StatementSpec.TableAccessNodes);

            // create output event type
            var eventTypeName = services.EventTypeNameGeneratorStatement.AnonymousTypeName;
            var eventTypeMetadata = new EventTypeMetadata(
                eventTypeName,
                @base.ModuleName,
                EventTypeTypeClass.STATEMENTOUT,
                EventTypeApplicationType.MAP,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var eventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                eventTypeMetadata,
                variableReadWritePackageForge.VariableTypes,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(eventType);

            // Handle output format
            var defaultSelectAllSpec = new StatementSpecCompiled();
            defaultSelectAllSpec.SelectClauseCompiled.WithSelectExprList(new SelectClauseElementWildcard());
            defaultSelectAllSpec.Raw.SelectStreamDirEnum = SelectClauseStreamSelectorEnum.RSTREAM_ISTREAM_BOTH;
            StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                new EventType[] {eventType},
                new[] {"trigger_stream"},
                new[] {true},
                false,
                false);
            var resultSetProcessor = ResultSetProcessorFactoryFactory.GetProcessorPrototype(
                new ResultSetSpec(defaultSelectAllSpec),
                streamTypeService,
                null,
                new bool[1],
                false,
                @base.ContextPropertyRegistry,
                false,
                false,
                @base.StatementRawInfo,
                services);
            var classNameRSP = CodeGenerationIDGenerator.GenerateClassNameSimple(
                typeof(ResultSetProcessorFactoryProvider),
                classPostfix);

            var forge = new StatementAgentInstanceFactoryOnTriggerSetForge(
                activatorResult.Activator,
                eventType,
                subselectForges,
                tableAccessForges,
                variableReadWritePackageForge,
                classNameRSP);
            IList<StmtClassForgable> forgables = new List<StmtClassForgable>();
            forgables.Add(
                new StmtClassForgableRSPFactoryProvider(
                    classNameRSP,
                    resultSetProcessor,
                    namespaceScope,
                    @base.StatementRawInfo));

            var onTrigger = new StmtClassForgableAIFactoryProviderOnTrigger(className, namespaceScope, forge);
            return new OnTriggerSetPlan(onTrigger, forgables, resultSetProcessor.SelectSubscriberDescriptor);
        }
Пример #11
0
        private InfraOnMergeActionInsForge SetupInsert(
            string infraName,
            EventType infraType,
            OnTriggerMergeActionInsert desc,
            EventType triggeringEventType,
            string triggeringStreamName,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services,
            bool isTable)
        {
            // Compile insert-into info
            var streamName = desc.OptionalStreamName != null ? desc.OptionalStreamName : infraName;
            InsertIntoDesc insertIntoDesc = InsertIntoDesc.FromColumns(streamName, desc.Columns);

            // rewrite any wildcards to use "stream.wildcard"
            if (triggeringStreamName == null) {
                triggeringStreamName = UuidGenerator.Generate();
            }

            var selectNoWildcard = CompileSelectNoWildcard(triggeringStreamName, desc.SelectClauseCompiled);

            // Set up event types for select-clause evaluation: The first type does not contain anything as its the named-window or table row which is not present for insert
            var eventTypeMetadata = new EventTypeMetadata(
                "merge_infra_insert",
                statementRawInfo.ModuleName,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.MAP,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            EventType dummyTypeNoProperties = BaseNestableEventUtil.MakeMapTypeCompileTime(
                eventTypeMetadata,
                Collections.GetEmptyMap<string, object>(),
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            var eventTypes = new EventType[] {dummyTypeNoProperties, triggeringEventType};
            var streamNames = new string[] {UuidGenerator.Generate(), triggeringStreamName};
            StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                eventTypes,
                streamNames,
                new bool[eventTypes.Length],
                false,
                false);

            // Get select expr processor
            var selectClause = selectNoWildcard.ToArray();
            var args = new SelectProcessorArgs(
                selectClause,
                null,
                false,
                null,
                null,
                streamTypeService,
                null,
                false,
                statementRawInfo.Annotations,
                statementRawInfo,
                services);
            if (isTable && streamName.Equals(infraName)) {
                args.OptionalInsertIntoEventType = infraType;
            }

            SelectExprProcessorForge insertHelperForge =
                SelectExprProcessorFactory.GetProcessor(args, insertIntoDesc, false).Forge;
            ExprNode filterEval = desc.OptionalWhereClause;

            var route = !streamName.Equals(infraName);
            bool audit = AuditEnum.INSERT.GetAudit(statementRawInfo.Annotations) != null;

            TableMetaData insertIntoTable = services.TableCompileTimeResolver.Resolve(insertIntoDesc.EventTypeName);
            return new InfraOnMergeActionInsForge(filterEval, insertHelperForge, insertIntoTable, audit, route);
        }
        public static SelectExprProcessorForgeWForgables Create(
            SelectProcessorArgs args,
            InsertIntoDesc insertIntoDesc,
            Func<String, String> eventTypeNamePostfix) 
        {
            var streamNames = args.TypeService.StreamNames;
            var streamTypes = args.TypeService.EventTypes;
            var moduleName = args.ModuleName;
            var additionalForgeables = new List<StmtClassForgeableFactory>();
            
            if (streamNames.Length < 2 || streamTypes.Length < 2 || streamNames.Length != streamTypes.Length) {
                throw new ArgumentException(
                    "Stream names and types parameter length is invalid, expected use of this class is for join statements");
            }

            // Create EventType of result join events
            var selectProperties = new LinkedHashMap<string, object>();
            var streamTypesWTables = new EventType[streamTypes.Length];
            var hasTables = false;
            for (var i = 0; i < streamTypes.Length; i++) {
                streamTypesWTables[i] = streamTypes[i];
                var table = args.TableCompileTimeResolver.ResolveTableFromEventType(streamTypesWTables[i]);
                if (table != null) {
                    hasTables = true;
                    streamTypesWTables[i] = table.PublicEventType;
                }

                selectProperties.Put(streamNames[i], streamTypesWTables[i]);
            }

            // If we have a name for this type, add it
            var representation = EventRepresentationUtil.GetRepresentation(
                args.Annotations,
                args.Configuration,
                AssignedType.NONE);
            EventType resultEventType;

            SelectExprProcessorForge processor = null;
            if (insertIntoDesc != null) {
                var existingType = args.EventTypeCompileTimeResolver.GetTypeByName(insertIntoDesc.EventTypeName);
                if (existingType != null) {
                    processor = SelectExprInsertEventBeanFactory.GetInsertUnderlyingJoinWildcard(
                        existingType,
                        streamNames,
                        streamTypesWTables,
                        args.ImportService,
                        args.StatementName,
                        args.EventTypeAvroHandler);
                }
            }

            if (processor == null) {
                if (insertIntoDesc != null) {
                    var eventTypeName = eventTypeNamePostfix.Invoke(insertIntoDesc.EventTypeName);
                    var visibility =
                        args.CompileTimeServices.ModuleVisibilityRules.GetAccessModifierEventType(
                            args.StatementRawInfo,
                            eventTypeName);
                    var metadata = new Func<EventTypeApplicationType, EventTypeMetadata>(
                        apptype => new EventTypeMetadata(
                            eventTypeName,
                            moduleName,
                            EventTypeTypeClass.STREAM,
                            apptype,
                            visibility,
                            EventTypeBusModifier.NONBUS,
                            false,
                            EventTypeIdPair.Unassigned()));
                    if (representation == EventUnderlyingType.MAP) {
                        IDictionary<string, object> propertyTypes =
                            EventTypeUtility.GetPropertyTypesNonPrimitive(selectProperties);
                        resultEventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                            metadata.Invoke(EventTypeApplicationType.MAP),
                            propertyTypes,
                            null,
                            null,
                            null,
                            null,
                            args.BeanEventTypeFactoryPrivate,
                            args.EventTypeCompileTimeResolver);
                    }
                    else if (representation == EventUnderlyingType.OBJECTARRAY) {
                        IDictionary<string, object> propertyTypes =
                            EventTypeUtility.GetPropertyTypesNonPrimitive(selectProperties);
                        resultEventType = BaseNestableEventUtil.MakeOATypeCompileTime(
                            metadata.Invoke(EventTypeApplicationType.OBJECTARR),
                            propertyTypes,
                            null,
                            null,
                            null,
                            null,
                            args.BeanEventTypeFactoryPrivate,
                            args.EventTypeCompileTimeResolver);
                    }
                    else if (representation == EventUnderlyingType.AVRO) {
                        resultEventType = args.EventTypeAvroHandler.NewEventTypeFromNormalized(
                            metadata.Invoke(EventTypeApplicationType.AVRO),
                            args.EventTypeCompileTimeResolver,
                            EventBeanTypedEventFactoryCompileTime.INSTANCE,
                            selectProperties,
                            args.Annotations,
                            null,
                            null,
                            null,
                            args.StatementName);
                    } else if (representation == EventUnderlyingType.JSON) {
                        EventTypeForgeablesPair pair = JsonEventTypeUtility.MakeJsonTypeCompileTimeNewType(
                            metadata.Invoke(EventTypeApplicationType.JSON),
                            selectProperties,
                            null,
                            null,
                            args.StatementRawInfo,
                            args.CompileTimeServices);
                        resultEventType = pair.EventType;
                        additionalForgeables.AddAll(pair.AdditionalForgeables);
                    }
                    else {
                        throw new IllegalStateException("Unrecognized code " + representation);
                    }

                    args.EventTypeCompileTimeRegistry.NewType(resultEventType);
                }
                else {
                    var eventTypeName = eventTypeNamePostfix.Invoke(
                        args.CompileTimeServices.EventTypeNameGeneratorStatement.AnonymousTypeName);
                    IDictionary<string, object> propertyTypes =
                        EventTypeUtility.GetPropertyTypesNonPrimitive(selectProperties);
                    var metadata = new Func<EventTypeApplicationType, EventTypeMetadata>(
                        type => new EventTypeMetadata(
                            eventTypeName,
                            moduleName,
                            EventTypeTypeClass.STATEMENTOUT,
                            type,
                            NameAccessModifier.TRANSIENT,
                            EventTypeBusModifier.NONBUS,
                            false,
                            EventTypeIdPair.Unassigned()));
                    if (representation == EventUnderlyingType.MAP) {
                        resultEventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                            metadata.Invoke(EventTypeApplicationType.MAP),
                            propertyTypes,
                            null,
                            null,
                            null,
                            null,
                            args.BeanEventTypeFactoryPrivate,
                            args.EventTypeCompileTimeResolver);
                    }
                    else if (representation == EventUnderlyingType.OBJECTARRAY) {
                        resultEventType = BaseNestableEventUtil.MakeOATypeCompileTime(
                            metadata.Invoke(EventTypeApplicationType.OBJECTARR),
                            propertyTypes,
                            null,
                            null,
                            null,
                            null,
                            args.BeanEventTypeFactoryPrivate,
                            args.EventTypeCompileTimeResolver);
                    }
                    else if (representation == EventUnderlyingType.AVRO) {
                        resultEventType = args.EventTypeAvroHandler.NewEventTypeFromNormalized(
                            metadata.Invoke(EventTypeApplicationType.AVRO),
                            args.EventTypeCompileTimeResolver,
                            args.BeanEventTypeFactoryPrivate.EventBeanTypedEventFactory,
                            selectProperties,
                            args.Annotations,
                            null,
                            null,
                            null,
                            args.StatementName);
                    } else if (representation == EventUnderlyingType.JSON) {
                        EventTypeForgeablesPair pair = JsonEventTypeUtility.MakeJsonTypeCompileTimeNewType(
                            metadata.Invoke(EventTypeApplicationType.JSON),
                            propertyTypes,
                            null,
                            null,
                            args.StatementRawInfo,
                            args.CompileTimeServices);
                        resultEventType = pair.EventType;
                        additionalForgeables.AddAll(pair.AdditionalForgeables);
                    }
                    else {
                        throw new IllegalStateException("Unrecognized enum " + representation);
                    }

                    args.EventTypeCompileTimeRegistry.NewType(resultEventType);
                }

                // NOTE: Processors herein maintain their own result-event-type as they become inner types,
                //       for example "insert into VariantStream select * from A, B"
                if (resultEventType is ObjectArrayEventType) {
                    processor = new SelectEvalJoinWildcardProcessorObjectArray(streamNames, resultEventType);
                }
                else if (resultEventType is MapEventType) {
                    processor = new SelectEvalJoinWildcardProcessorMap(streamNames, resultEventType);
                }
                else if (resultEventType is AvroSchemaEventType) {
                    processor = args.EventTypeAvroHandler.OutputFactory.MakeJoinWildcard(streamNames, resultEventType);
                } else if (resultEventType is JsonEventType) {
                    processor = new SelectEvalJoinWildcardProcessorJson(streamNames, (JsonEventType) resultEventType);
                }
            }

            if (!hasTables) {
                return new SelectExprProcessorForgeWForgables(processor, additionalForgeables);
            }
            processor = new SelectEvalJoinWildcardProcessorTableRows(streamTypes, processor, args.TableCompileTimeResolver);
            return new SelectExprProcessorForgeWForgables(processor, additionalForgeables);
        }
Пример #13
0
        // The create window command:
        //      create window windowName[.window_view_list] as [select properties from] type
        //
        // This section expected s single FilterStreamSpecCompiled representing the selected type.
        // It creates a new event type representing the window type and a sets the type selected on the filter stream spec.
        protected internal static CreateWindowCompileResult HandleCreateWindow(
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var createWindowDesc = @base.StatementSpec.Raw.CreateWindowDesc;
            var columns = createWindowDesc.Columns;
            var typeName = createWindowDesc.WindowName;
            EventType targetType;

            // determine that the window name is not already in use as an event type name
            var existingType = services.EventTypeCompileTimeResolver.GetTypeByName(typeName);
            if (existingType != null && existingType.Metadata.TypeClass != EventTypeTypeClass.NAMED_WINDOW) {
                throw new ExprValidationException(
                    "Error starting statement: An event type or schema by name '" + typeName + "' already exists");
            }

            // Determine select-from
            var optionalSelectFrom = GetOptionalSelectFrom(createWindowDesc, services);

            // Create Map or Wrapper event type from the select clause of the window.
            // If no columns selected, simply create a wrapper type
            // Build a list of properties
            var newSelectClauseSpecRaw = new SelectClauseSpecRaw();
            LinkedHashMap<string, object> properties;
            var hasProperties = false;
            if (columns != null && !columns.IsEmpty()) {
                properties = EventTypeUtility.BuildType(
                    columns,
                    null,
                    services.ImportServiceCompileTime,
                    services.EventTypeCompileTimeResolver);
                hasProperties = true;
            }
            else {
                if (optionalSelectFrom == null) {
                    throw new IllegalStateException("Missing from-type information for create-window");
                }

                // Validate the select expressions which consists of properties only
                var select = CompileLimitedSelect(optionalSelectFrom, @base, services);

                properties = new LinkedHashMap<string, object>();
                foreach (var selectElement in select) {
                    if (selectElement.FragmentType != null) {
                        properties.Put(selectElement.AssignedName, selectElement.FragmentType);
                    }
                    else {
                        properties.Put(selectElement.AssignedName, selectElement.SelectExpressionType);
                    }

                    // Add any properties to the new select clause for use by consumers to the statement itself
                    newSelectClauseSpecRaw.Add(
                        new SelectClauseExprRawSpec(new ExprIdentNodeImpl(selectElement.AssignedName), null, false));
                    hasProperties = true;
                }
            }

            // Create Map or Wrapper event type from the select clause of the window.
            // If no columns selected, simply create a wrapper type
            var isOnlyWildcard = @base.StatementSpec.Raw.SelectClauseSpec.IsOnlyWildcard;
            var isWildcard = @base.StatementSpec.Raw.SelectClauseSpec.IsUsingWildcard;
            var namedWindowVisibility = services.ModuleVisibilityRules.GetAccessModifierNamedWindow(@base, typeName);
            var additionalForgeables = new List<StmtClassForgeableFactory>();
            
            try {
                if (isWildcard && !isOnlyWildcard) {
                    var metadata = new EventTypeMetadata(
                        typeName,
                        @base.ModuleName,
                        EventTypeTypeClass.NAMED_WINDOW,
                        EventTypeApplicationType.WRAPPER,
                        namedWindowVisibility,
                        EventTypeBusModifier.NONBUS,
                        false,
                        EventTypeIdPair.Unassigned());
                    targetType = WrapperEventTypeUtil.MakeWrapper(
                        metadata,
                        optionalSelectFrom.EventType,
                        properties,
                        null,
                        services.BeanEventTypeFactoryPrivate,
                        services.EventTypeCompileTimeResolver);
                }
                else {
                    // Some columns selected, use the types of the columns
                    Func<EventTypeApplicationType, EventTypeMetadata> metadata = type => new EventTypeMetadata(
                        typeName,
                        @base.ModuleName,
                        EventTypeTypeClass.NAMED_WINDOW,
                        type,
                        namedWindowVisibility,
                        EventTypeBusModifier.NONBUS,
                        false,
                        EventTypeIdPair.Unassigned());

                    if (hasProperties && !isOnlyWildcard) {
                        var compiledProperties = EventTypeUtility.CompileMapTypeProperties(
                            properties,
                            services.EventTypeCompileTimeResolver);
                        var representation = EventRepresentationUtil.GetRepresentation(
                            @base.StatementSpec.Annotations,
                            services.Configuration,
                            AssignedType.NONE);

                        if (representation == EventUnderlyingType.MAP) {
                            targetType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                                metadata.Invoke(EventTypeApplicationType.MAP),
                                compiledProperties,
                                null,
                                null,
                                null,
                                null,
                                services.BeanEventTypeFactoryPrivate,
                                services.EventTypeCompileTimeResolver);
                        }
                        else if (representation == EventUnderlyingType.OBJECTARRAY) {
                            targetType = BaseNestableEventUtil.MakeOATypeCompileTime(
                                metadata.Invoke(EventTypeApplicationType.OBJECTARR),
                                compiledProperties,
                                null,
                                null,
                                null,
                                null,
                                services.BeanEventTypeFactoryPrivate,
                                services.EventTypeCompileTimeResolver);
                        }
                        else if (representation == EventUnderlyingType.AVRO) {
                            targetType = services.EventTypeAvroHandler.NewEventTypeFromNormalized(
                                metadata.Invoke(EventTypeApplicationType.AVRO),
                                services.EventTypeCompileTimeResolver,
                                services.BeanEventTypeFactoryPrivate.EventBeanTypedEventFactory,
                                compiledProperties,
                                @base.StatementRawInfo.Annotations,
                                null,
                                null,
                                null,
                                @base.StatementName);
                        } else if (representation == EventUnderlyingType.JSON) {
                            EventTypeForgeablesPair pair = JsonEventTypeUtility.MakeJsonTypeCompileTimeNewType(
                                metadata.Invoke(EventTypeApplicationType.JSON),
                                compiledProperties,
                                null,
                                null,
                                @base.StatementRawInfo,
                                services);
                            targetType = pair.EventType;
                            additionalForgeables.AddRange(pair.AdditionalForgeables);
                        }
                        else {
                            throw new IllegalStateException("Unrecognized representation " + representation);
                        }
                    }
                    else {
                        if (optionalSelectFrom == null) {
                            throw new IllegalStateException("Missing from-type information for create-window");
                        }

                        var selectFromType = optionalSelectFrom.EventType;

                        // No columns selected, no wildcard, use the type as is or as a wrapped type
                        if (selectFromType is ObjectArrayEventType) {
                            var oaType = (ObjectArrayEventType) selectFromType;
                            targetType = BaseNestableEventUtil.MakeOATypeCompileTime(
                                metadata.Invoke(EventTypeApplicationType.OBJECTARR),
                                oaType.Types,
                                null,
                                null,
                                oaType.StartTimestampPropertyName,
                                oaType.EndTimestampPropertyName,
                                services.BeanEventTypeFactoryPrivate,
                                services.EventTypeCompileTimeResolver);
                        }
                        else if (selectFromType is AvroSchemaEventType) {
                            var avroSchemaEventType = (AvroSchemaEventType) selectFromType;
                            var avro = new ConfigurationCommonEventTypeAvro();
                            avro.AvroSchema = avroSchemaEventType.Schema;
                            targetType = services.EventTypeAvroHandler.NewEventTypeFromSchema(
                                metadata.Invoke(EventTypeApplicationType.AVRO),
                                services.BeanEventTypeFactoryPrivate.EventBeanTypedEventFactory,
                                avro,
                                null,
                                null);
                        } else if (selectFromType is JsonEventType) {
                            JsonEventType jsonType = (JsonEventType) selectFromType;
                            targetType = JsonEventTypeUtility.MakeJsonTypeCompileTimeExistingType(
                                metadata.Invoke(EventTypeApplicationType.JSON),
                                jsonType,
                                services);
                        }
                        else if (selectFromType is MapEventType) {
                            var mapType = (MapEventType) selectFromType;
                            targetType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                                metadata.Invoke(EventTypeApplicationType.MAP),
                                mapType.Types,
                                null,
                                null,
                                mapType.StartTimestampPropertyName,
                                mapType.EndTimestampPropertyName,
                                services.BeanEventTypeFactoryPrivate,
                                services.EventTypeCompileTimeResolver);
                        }
                        else if (selectFromType is BeanEventType) {
                            var beanType = (BeanEventType) selectFromType;
                            targetType = new BeanEventType(
                                services.Container,
                                beanType.Stem,
                                metadata.Invoke(EventTypeApplicationType.CLASS),
                                services.BeanEventTypeFactoryPrivate,
                                null,
                                null,
                                beanType.StartTimestampPropertyName,
                                beanType.EndTimestampPropertyName);
                        }
                        else {
                            targetType = WrapperEventTypeUtil.MakeWrapper(
                                metadata.Invoke(EventTypeApplicationType.WRAPPER),
                                selectFromType,
                                new Dictionary<string, object>(),
                                null,
                                services.BeanEventTypeFactoryPrivate,
                                services.EventTypeCompileTimeResolver);
                        }
                    }
                }

                services.EventTypeCompileTimeRegistry.NewType(targetType);
            }
            catch (EPException ex) {
                throw new ExprValidationException(ex.Message, ex);
            }

            var filter = new FilterSpecCompiled(targetType, typeName, FilterSpecPlanForge.EMPTY, null);
            return new CreateWindowCompileResult(
                filter,
                newSelectClauseSpecRaw,
                optionalSelectFrom?.EventType,
                additionalForgeables);
        }
Пример #14
0
        /// <summary>
        /// Creates an event type from the query meta data.
        /// </summary>
        /// <param name="streamNum"></param>
        /// <param name="queryMetaData">The query meta data.</param>
        /// <param name="services"></param>
        /// <param name="databaseStreamSpec">The database stream spec.</param>
        /// <param name="columnTypeConversionHook">The column type conversion hook.</param>
        /// <param name="outputRowConversionHook">The output row conversion hook.</param>
        /// <param name="base"></param>
        private static EventType CreateEventType(
            int streamNum,
            QueryMetaData queryMetaData,
            StatementCompileTimeServices services,
            DBStatementStreamSpec databaseStreamSpec,
            SQLColumnTypeConversion columnTypeConversionHook,
            SQLOutputRowConversion outputRowConversionHook,
            StatementBaseInfo @base)
        {
            var eventTypeFields = CreateEventTypeFields(
                databaseStreamSpec,
                columnTypeConversionHook,
                queryMetaData);

            var eventTypeName = services.EventTypeNameGeneratorStatement.GetAnonymousDBHistorical(streamNum);

            EventType eventType;
            Func<EventTypeApplicationType, EventTypeMetadata> metadata = appType => new EventTypeMetadata(
                eventTypeName,
                @base.ModuleName,
                EventTypeTypeClass.DBDERIVED,
                appType,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            if (outputRowConversionHook == null) {
                eventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                    metadata.Invoke(EventTypeApplicationType.MAP),
                    eventTypeFields,
                    null,
                    null,
                    null,
                    null,
                    services.BeanEventTypeFactoryPrivate,
                    services.EventTypeCompileTimeResolver);
            }
            else {
                var carrierClass = outputRowConversionHook.GetOutputRowType(
                    new SQLOutputRowTypeContext(
                        databaseStreamSpec.DatabaseName,
                        databaseStreamSpec.SqlWithSubsParams,
                        eventTypeFields));
                if (carrierClass == null) {
                    throw new ExprValidationException("Output row conversion hook returned no type");
                }

                var stem = services.BeanEventTypeStemService.GetCreateStem(carrierClass, null);
                eventType = new BeanEventType(
                    services.Container,
                    stem,
                    metadata.Invoke(EventTypeApplicationType.CLASS),
                    services.BeanEventTypeFactoryPrivate,
                    null,
                    null,
                    null,
                    null);
            }

            return eventType;
        }
Пример #15
0
        public StmtForgeMethodResult Make(
            string @namespace,
            string classPostfix,
            StatementCompileTimeServices services)
        {
            var statementSpec = _base.StatementSpec;

            var createDesc = statementSpec.Raw.CreateVariableDesc;

            // Check if the variable is already declared
            EPLValidationUtil.ValidateAlreadyExistsTableOrVariable(
                createDesc.VariableName,
                services.VariableCompileTimeResolver,
                services.TableCompileTimeResolver,
                services.EventTypeCompileTimeResolver);

            // Get assignment value when compile-time-constant
            object initialValue = null;
            ExprForge initialValueExpr = null;
            if (createDesc.Assignment != null) {
                // Evaluate assignment expression
                StreamTypeService typeService = new StreamTypeServiceImpl(
                    new EventType[0],
                    new string[0],
                    new bool[0],
                    false,
                    false);
                var validationContext =
                    new ExprValidationContextBuilder(typeService, _base.StatementRawInfo, services).Build();
                var validated = ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.VARIABLEASSIGN,
                    createDesc.Assignment,
                    validationContext);
                if (validated.Forge.ForgeConstantType == ExprForgeConstantType.COMPILETIMECONST) {
                    initialValue = validated.Forge.ExprEvaluator.Evaluate(null, true, null);
                }

                createDesc.Assignment = validated;
                initialValueExpr = validated.Forge;
            }

            var contextName = statementSpec.Raw.OptionalContextName;
            NameAccessModifier? contextVisibility = null;
            string contextModuleName = null;
            if (contextName != null) {
                var contextDetail = services.ContextCompileTimeResolver.GetContextInfo(contextName);
                if (contextDetail == null) {
                    throw new ExprValidationException("Failed to find context '" + contextName + "'");
                }

                contextVisibility = contextDetail.ContextVisibility;
                contextModuleName = contextDetail.ContextModuleName;
            }

            // get visibility
            var visibility = services.ModuleVisibilityRules.GetAccessModifierVariable(_base, createDesc.VariableName);

            // Compile metadata
            var compileTimeConstant = createDesc.IsConstant &&
                                      initialValueExpr != null &&
                                      initialValueExpr.ForgeConstantType.IsCompileTimeConstant;
            var metaData = VariableUtil.CompileVariable(
                createDesc.VariableName,
                _base.ModuleName,
                visibility,
                contextName,
                contextVisibility,
                contextModuleName,
                createDesc.VariableType,
                createDesc.IsConstant,
                compileTimeConstant,
                initialValue,
                services.ImportServiceCompileTime,
                EventBeanTypedEventFactoryCompileTime.INSTANCE,
                services.EventTypeRepositoryPreconfigured,
                services.BeanEventTypeFactoryPrivate);

            // Register variable
            services.VariableCompileTimeRegistry.NewVariable(metaData);

            // Statement event type
            var eventTypePropertyTypes = Collections.SingletonDataMap(
                metaData.VariableName,
                metaData.Type);
            var eventTypeName = services.EventTypeNameGeneratorStatement.AnonymousTypeName;
            var eventTypeMetadata = new EventTypeMetadata(
                eventTypeName,
                _base.ModuleName,
                EventTypeTypeClass.STATEMENTOUT,
                EventTypeApplicationType.MAP,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var outputEventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                eventTypeMetadata,
                eventTypePropertyTypes,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(outputEventType);

            // Handle output format
            var defaultSelectAllSpec = new StatementSpecCompiled();
            defaultSelectAllSpec.SelectClauseCompiled.WithSelectExprList(new SelectClauseElementWildcard());
            defaultSelectAllSpec.Raw.SelectStreamDirEnum = SelectClauseStreamSelectorEnum.RSTREAM_ISTREAM_BOTH;
            StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                new EventType[] {outputEventType},
                new string[] {"trigger_stream"},
                new bool[] {true},
                false,
                false);
            var resultSetProcessor = ResultSetProcessorFactoryFactory.GetProcessorPrototype(
                new ResultSetSpec(defaultSelectAllSpec),
                streamTypeService,
                null,
                new bool[1],
                false,
                _base.ContextPropertyRegistry,
                false,
                false,
                _base.StatementRawInfo,
                services);

            // Code generation
            var statementFieldsClassName =
                CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementFields), classPostfix);
            var aiFactoryProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(
                typeof(StatementAIFactoryProvider),
                classPostfix);
            var classNameRSP = CodeGenerationIDGenerator.GenerateClassNameSimple(
                typeof(ResultSetProcessorFactoryProvider),
                classPostfix);
            var packageScope = new CodegenNamespaceScope(
                @namespace,
                statementFieldsClassName,
                services.IsInstrumented);

            var forge =
                new StatementAgentInstanceFactoryCreateVariableForge(
                    createDesc.VariableName,
                    initialValueExpr,
                    classNameRSP);
            var aiFactoryForgable = new StmtClassForgableAIFactoryProviderCreateVariable(
                aiFactoryProviderClassName,
                packageScope,
                forge,
                createDesc.VariableName);

            var informationals = StatementInformationalsUtil.GetInformationals(
                _base,
                Collections.GetEmptyList<FilterSpecCompiled>(),
                Collections.GetEmptyList<ScheduleHandleCallbackProvider>(),
                Collections.GetEmptyList<NamedWindowConsumerStreamSpec>(),
                true,
                resultSetProcessor.SelectSubscriberDescriptor,
                packageScope,
                services);
            var statementProviderClassName =
                CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementProvider), classPostfix);
            var stmtProvider = new StmtClassForgableStmtProvider(
                aiFactoryProviderClassName,
                statementProviderClassName,
                informationals,
                packageScope);

            IList<StmtClassForgable> forgables = new List<StmtClassForgable>();
            forgables.Add(
                new StmtClassForgableRSPFactoryProvider(
                    classNameRSP,
                    resultSetProcessor,
                    packageScope,
                    _base.StatementRawInfo));
            forgables.Add(aiFactoryForgable);
            forgables.Add(stmtProvider);
            forgables.Add(new StmtClassForgableStmtFields(statementFieldsClassName, packageScope, 0));
            return new StmtForgeMethodResult(
                forgables,
                Collections.GetEmptyList<FilterSpecCompiled>(),
                Collections.GetEmptyList<ScheduleHandleCallbackProvider>(),
                Collections.GetEmptyList<NamedWindowConsumerStreamSpec>(),
                Collections.GetEmptyList<FilterSpecParamExprNodeForge>());
        }
Пример #16
0
        public StmtForgeMethodResult Make(
            string @namespace,
            string classPostfix,
            StatementCompileTimeServices services)
        {
            string objectName = Register(services);

            // define output event type
            string            statementEventTypeName = services.EventTypeNameGeneratorStatement.AnonymousTypeName;
            EventTypeMetadata statementTypeMetadata  = new EventTypeMetadata(
                statementEventTypeName,
                _base.ModuleName,
                EventTypeTypeClass.STATEMENTOUT,
                EventTypeApplicationType.MAP,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            EventType statementEventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                statementTypeMetadata,
                EmptyDictionary <string, object> .Instance,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);

            services.EventTypeCompileTimeRegistry.NewType(statementEventType);

            string statementFieldsClassName =
                CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementFields), classPostfix);

            CodegenNamespaceScope namespaceScope = new CodegenNamespaceScope(
                @namespace,
                statementFieldsClassName,
                services.IsInstrumented);

            string             aiFactoryProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementAIFactoryProvider), classPostfix);
            StmtClassForgeable aiFactoryForgeable         = AiFactoryForgable(aiFactoryProviderClassName, namespaceScope, statementEventType, objectName);

            SelectSubscriberDescriptor         selectSubscriberDescriptor = new SelectSubscriberDescriptor();
            StatementInformationalsCompileTime informationals             = StatementInformationalsUtil.GetInformationals(
                _base,
                EmptyList <FilterSpecCompiled> .Instance,
                EmptyList <ScheduleHandleCallbackProvider> .Instance,
                EmptyList <NamedWindowConsumerStreamSpec> .Instance,
                false,
                selectSubscriberDescriptor,
                namespaceScope,
                services);

            informationals.Properties.Put(StatementProperty.CREATEOBJECTNAME, objectName);
            string statementProviderClassName           = CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementProvider), classPostfix);
            StmtClassForgeableStmtProvider stmtProvider = new StmtClassForgeableStmtProvider(
                aiFactoryProviderClassName,
                statementProviderClassName,
                informationals,
                namespaceScope);

            var stmtClassForgeableStmtFields = new StmtClassForgeableStmtFields(
                statementFieldsClassName,
                namespaceScope,
                1);

            IList <StmtClassForgeable> forgeables = new List <StmtClassForgeable>();

            forgeables.Add(aiFactoryForgeable);
            forgeables.Add(stmtProvider);
            forgeables.Add(stmtClassForgeableStmtFields);
            return(new StmtForgeMethodResult(
                       forgeables,
                       EmptyList <FilterSpecCompiled> .Instance,
                       EmptyList <ScheduleHandleCallbackProvider> .Instance,
                       EmptyList <NamedWindowConsumerStreamSpec> .Instance,
                       EmptyList <FilterSpecParamExprNodeForge> .Instance));
        }