示例#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
        private static EventType GetDefineMultimatchEventType(
            LinkedHashMap<string, Pair<int, bool>> variableStreams,
            EventType parentEventType,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            IDictionary<string, object> multievent = new LinkedHashMap<string, object>();
            foreach (var entry in variableStreams) {
                if (entry.Value.Second) {
                    multievent.Put(entry.Key, new[] {parentEventType});
                }
            }

            var multimatchAllTypeName = services.EventTypeNameGeneratorStatement.AnonymousRowrecogMultimatchAllName;
            var multimatchAllTypeMetadata = new EventTypeMetadata(
                multimatchAllTypeName,
                @base.ModuleName,
                EventTypeTypeClass.MATCHRECOGDERIVED,
                EventTypeApplicationType.OBJECTARR,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var multimatchAllEventType = BaseNestableEventUtil.MakeOATypeCompileTime(
                multimatchAllTypeMetadata,
                multievent,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(multimatchAllEventType);
            return multimatchAllEventType;
        }
示例#3
0
        /// <summary>Initializes a new instance of the <see cref="SupportEventTypeFactory"/> class.</summary>
        /// <param name="container">The container.</param>
        public SupportEventTypeFactory(IContainer container)
        {
            Container = container;

            STEM_BUILDER = new BeanEventTypeStemBuilder(null, PropertyResolutionStyle.CASE_SENSITIVE);

            BEAN_STEM_SVC = new BeanEventTypeStemService(
                null, null, PropertyResolutionStyle.CASE_SENSITIVE, AccessorStyle.NATIVE);

            BEAN_EVENT_TYPE_FACTORY = new BeanEventTypeFactoryPrivate(
                new EventBeanTypedEventFactoryRuntime(null),
                EventTypeFactoryImpl.GetInstance(container),
                BEAN_STEM_SVC);

            METADATA_CLASS = name => new EventTypeMetadata(
                name, null,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.CLASS,
                NameAccessModifier.INTERNAL,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());

            SUPPORTBEAN_EVENTTTPE = MakeType(typeof(SupportBean));
            SUPPORTBEAN_S0_EVENTTTPE = MakeType(typeof(SupportBean_S0));
            SUPPORTBEAN_S1_EVENTTTPE = MakeType(typeof(SupportBean_S1));
            SUPPORTBEAN_S2_EVENTTTPE = MakeType(typeof(SupportBean_S2));
            SUPPORTBEAN_A_EVENTTTPE = MakeType(typeof(SupportBean_A));
            SUPPORTBEANCOMPLEXPROPS_EVENTTTPE = MakeType(typeof(SupportBeanComplexProps));
            SUPPORTBEANSIMPLE_EVENTTTPE = MakeType(typeof(SupportBeanSimple));
        }
示例#4
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;
 }
示例#5
0
 public static ObjectArrayEventType MakeTransientOAType(
     string enumMethod,
     string propertyName,
     Type type,
     StatementRawInfo statementRawInfo,
     StatementCompileTimeServices services)
 {
     IDictionary<string, object> propsResult = new Dictionary<string, object>();
     propsResult.Put(propertyName, Boxing.GetBoxedType(type));
     var eventTypeName =
         services.EventTypeNameGeneratorStatement.GetAnonymousTypeNameEnumMethod(enumMethod, propertyName);
     var metadata = new EventTypeMetadata(
         eventTypeName,
         statementRawInfo.ModuleName,
         EventTypeTypeClass.ENUMDERIVED,
         EventTypeApplicationType.OBJECTARR,
         NameAccessModifier.TRANSIENT,
         EventTypeBusModifier.NONBUS,
         false,
         EventTypeIdPair.Unassigned());
     var oatype = BaseNestableEventUtil.MakeOATypeCompileTime(
         metadata,
         propsResult,
         null,
         null,
         null,
         null,
         services.BeanEventTypeFactoryPrivate,
         services.EventTypeCompileTimeResolver);
     services.EventTypeCompileTimeRegistry.NewType(oatype);
     return oatype;
 }
示例#6
0
        private static ObjectArrayEventType MakeTransientOATypeInternal(
            string enumMethod,
            IDictionary <string, object> boxedPropertyTypes,
            string eventTypeNameUUid,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            var eventTypeName =
                services.EventTypeNameGeneratorStatement.GetAnonymousTypeNameEnumMethod(enumMethod, eventTypeNameUUid);
            var metadata = new EventTypeMetadata(
                eventTypeName,
                statementRawInfo.ModuleName,
                EventTypeTypeClass.ENUMDERIVED,
                EventTypeApplicationType.OBJECTARR,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var oatype = BaseNestableEventUtil.MakeOATypeCompileTime(
                metadata,
                boxedPropertyTypes,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);

            services.EventTypeCompileTimeRegistry.NewType(oatype);
            return(oatype);
        }
示例#7
0
 private static BeanEventType MakeBeanType(
     string methodName,
     Type clazz,
     ExprValidationContext validationContext)
 {
     var eventTypeName =
         validationContext.StatementCompileTimeService.EventTypeNameGeneratorStatement
             .GetAnonymousTypeNameUDFMethod(methodName, clazz.Name);
     var metadata = new EventTypeMetadata(
         eventTypeName,
         validationContext.ModuleName,
         EventTypeTypeClass.UDFDERIVED,
         EventTypeApplicationType.CLASS,
         NameAccessModifier.TRANSIENT,
         EventTypeBusModifier.NONBUS,
         false,
         EventTypeIdPair.Unassigned());
     var stem = validationContext.StatementCompileTimeService.BeanEventTypeStemService
         .GetCreateStem(clazz, null);
     var beantype = new BeanEventType(
         validationContext.Container,
         stem,
         metadata,
         validationContext.StatementCompileTimeService.BeanEventTypeFactoryPrivate,
         null,
         null,
         null,
         null);
     validationContext.StatementCompileTimeService.EventTypeCompileTimeRegistry.NewType(beantype);
     return beantype;
 }
示例#8
0
 static ExcludePlanHintExprUtil()
 {
     LinkedHashMap<string, object> properties = new LinkedHashMap<string, object>();
     properties.Put("from_streamnum", typeof(int?));
     properties.Put("to_streamnum", typeof(int?));
     properties.Put("from_streamname", typeof(string));
     properties.Put("to_streamname", typeof(string));
     properties.Put("opname", typeof(string));
     properties.Put("exprs", typeof(string[]));
     string eventTypeName = EventTypeNameUtil.GetAnonymousTypeNameExcludePlanHint();
     EventTypeMetadata eventTypeMetadata = new EventTypeMetadata(
         eventTypeName,
         null,
         EventTypeTypeClass.EXCLUDEPLANHINTDERIVED,
         EventTypeApplicationType.OBJECTARR,
         NameAccessModifier.TRANSIENT,
         EventTypeBusModifier.NONBUS,
         false,
         EventTypeIdPair.Unassigned());
     OAEXPRESSIONTYPE = BaseNestableEventUtil.MakeOATypeCompileTime(
         eventTypeMetadata,
         properties,
         null,
         null,
         null,
         null,
         new BeanEventTypeFactoryDisallow(EventBeanTypedEventFactoryCompileTime.INSTANCE),
         null);
 }
示例#9
0
        private EventType HandleVariantType(
            CreateSchemaDesc spec,
            StatementCompileTimeServices services)
        {
            if (spec.CopyFrom != null && !spec.CopyFrom.IsEmpty()) {
                throw new ExprValidationException("Copy-from types are not allowed with variant types");
            }

            var eventTypeName = spec.SchemaName;

            // determine typing
            var isAny = false;
            ISet<EventType> types = new LinkedHashSet<EventType>();
            foreach (var typeName in spec.Types) {
                if (typeName.Trim().Equals("*")) {
                    isAny = true;
                }
                else {
                    var eventType = services.EventTypeCompileTimeResolver.GetTypeByName(typeName);
                    if (eventType == null) {
                        throw new ExprValidationException(
                            "Event type by name '" +
                            typeName +
                            "' could not be found for use in variant stream by name '" +
                            eventTypeName +
                            "'");
                    }

                    types.Add(eventType);
                }
            }

            var eventTypes = types.ToArray();
            var variantSpec = new VariantSpec(eventTypes, isAny ? TypeVariance.ANY : TypeVariance.PREDEFINED);

            var visibility =
                services.ModuleVisibilityRules.GetAccessModifierEventType(@base.StatementRawInfo, spec.SchemaName);
            var eventBusVisibility =
                services.ModuleVisibilityRules.GetBusModifierEventType(@base.StatementRawInfo, eventTypeName);
            EventTypeUtility.ValidateModifiers(spec.SchemaName, eventBusVisibility, visibility);

            var metadata = new EventTypeMetadata(
                eventTypeName,
                @base.ModuleName,
                EventTypeTypeClass.VARIANT,
                EventTypeApplicationType.VARIANT,
                visibility,
                eventBusVisibility,
                false,
                EventTypeIdPair.Unassigned());
            var variantEventType = new VariantEventType(metadata, variantSpec);
            services.EventTypeCompileTimeRegistry.NewType(variantEventType);
            return variantEventType;
        }
示例#10
0
        public EventType CreateMapType(IDictionary <string, object> map)
        {
            var metadata = new EventTypeMetadata(
                UuidGenerator.Generate(), null,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.MAP,
                NameAccessModifier.INTERNAL,
                EventTypeBusModifier.NONBUS, false,
                EventTypeIdPair.Unassigned());

            return(new MapEventType(metadata, map, null, null, null, null, BEAN_EVENT_TYPE_FACTORY));
        }
示例#11
0
 public static AvroEventType MakeAvroSupportEventType(Schema schema)
 {
     EventTypeMetadata metadata = new EventTypeMetadata(
         "typename",
         null,
         EventTypeTypeClass.STREAM,
         EventTypeApplicationType.AVRO,
         NameAccessModifier.TRANSIENT,
         EventTypeBusModifier.NONBUS,
         false,
         EventTypeIdPair.Unassigned());
     return new AvroEventType(metadata, schema, null, null, null, null, null, new EventTypeAvroHandlerImpl());
 }
示例#12
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);
        }
示例#13
0
        public BeanEventType MakeBeanEventTypeAnonymous(Type beanType)
        {
            var metadata = new EventTypeMetadata(
                beanType.Name,
                null,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.CLASS,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var stem = _stemSvc.GetCreateStem(beanType, null);

            return(new BeanEventType(_container, stem, metadata, _factoryPrivate, null, null, null, null));
        }
示例#14
0
        internal static FragmentEventType GetFragmentEventTypeForField(
            Schema fieldSchema,
            string moduleName,
            EventBeanTypedEventFactory eventBeanTypedEventFactory,
            EventTypeAvroHandler eventTypeAvroHandler,
            AvroEventTypeFragmentTypeCache fragmentTypeCache)
        {
            Schema recordSchema;
            var indexed = false;
            if (fieldSchema.Tag == Schema.Type.Record) {
                recordSchema = fieldSchema;
            }
            else if (fieldSchema.Tag == Schema.Type.Array &&
                     fieldSchema.AsArraySchema().ItemSchema.Tag == Schema.Type.Record) {
                recordSchema = fieldSchema.AsArraySchema().ItemSchema;
                indexed = true;
            }
            else {
                return null;
            }

            var cached = fragmentTypeCache.Get(recordSchema.Name);
            if (cached != null) {
                return new FragmentEventType(cached, indexed, false);
            }

            var metadata = new EventTypeMetadata(
                recordSchema.Name,
                moduleName,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.AVRO,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var config = new ConfigurationCommonEventTypeAvro();
            config.AvroSchema = recordSchema;

            var fragmentType = eventTypeAvroHandler.NewEventTypeFromSchema(
                metadata,
                eventBeanTypedEventFactory,
                config,
                null,
                null);

            fragmentTypeCache.Add(recordSchema.Name, fragmentType);
            return new FragmentEventType(fragmentType, indexed, false);
        }
示例#15
0
        private DataFlowOpForgeInitializeResult InitializeTypeUndeclared(DataFlowOpForgeInitializeContext context)
        {
            // No type has been declared, we can create one
            var types = new LinkedHashMap<string, object>();
            var props = allProperties.Keys;
            props.RemoveAll(PARAMETER_PROPERTIES);

            var count = 0;
            evaluatorForges = new ExprForge[props.Count];
            foreach (var propertyName in props) {
                var exprNode = allProperties.Get(propertyName);
                var validated = EPLValidationUtil.ValidateSimpleGetSubtree(
                    ExprNodeOrigin.DATAFLOWBEACON,
                    exprNode,
                    null,
                    false,
                    context.StatementRawInfo,
                    context.Services);
                types.Put(propertyName, validated.Forge.EvaluationType);
                evaluatorForges[count] = validated.Forge;
                count++;
            }

            var eventTypeName =
                context.Services.EventTypeNameGeneratorStatement.GetDataflowOperatorTypeName(context.OperatorNumber);
            var metadata = new EventTypeMetadata(
                eventTypeName,
                context.Base.ModuleName,
                EventTypeTypeClass.DBDERIVED,
                EventTypeApplicationType.OBJECTARR,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            outputEventType = BaseNestableEventUtil.MakeOATypeCompileTime(
                metadata,
                types,
                null,
                null,
                null,
                null,
                context.Services.BeanEventTypeFactoryPrivate,
                context.Services.EventTypeCompileTimeResolver);
            context.Services.EventTypeCompileTimeRegistry.NewType(outputEventType);

            return new DataFlowOpForgeInitializeResult(new[] {new GraphTypeDesc(false, true, outputEventType)});
        }
示例#16
0
        private SupportEventTypeFactory(IContainer container)
        {
            _container = container;

            STEM_BUILDER = new BeanEventTypeStemBuilder(
                null,
                PropertyResolutionStyle.CASE_SENSITIVE);

            BEAN_STEM_SVC = new BeanEventTypeStemService(
                null,
                null,
                PropertyResolutionStyle.CASE_SENSITIVE,
                AccessorStyle.NATIVE);

            BEAN_EVENT_TYPE_FACTORY = new BeanEventTypeFactoryPrivate(
                new EventBeanTypedEventFactoryRuntime(null),
                EventTypeFactoryImpl.GetInstance(container),
                BEAN_STEM_SVC);

            METADATA_CLASS = name => new EventTypeMetadata(
                name,
                null,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.CLASS,
                NameAccessModifier.INTERNAL,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());

            SUPPORTBEAN_EVENTTTPE                       = MakeType(typeof(SupportBean));
            SUPPORTBEAN_S0_EVENTTTPE                    = MakeType(typeof(SupportBean_S0));
            SUPPORTBEAN_S1_EVENTTTPE                    = MakeType(typeof(SupportBean_S1));
            SUPPORTBEAN_S2_EVENTTTPE                    = MakeType(typeof(SupportBean_S2));
            SUPPORTBEAN_S3_EVENTTTPE                    = MakeType(typeof(SupportBean_S3));
            SUPPORTBEAN_S4_EVENTTTPE                    = MakeType(typeof(SupportBean_S4));
            SUPPORTBEAN_A_EVENTTTPE                     = MakeType(typeof(SupportBean_A));
            SUPPORTMARKETDATABEAN_EVENTTTPE             = MakeType(typeof(SupportMarketDataBean));
            SUPPORTBEANSTRING_EVENTTTPE                 = MakeType(typeof(SupportBeanString));
            SUPPORTBEANCOMPLEXPROPS_EVENTTTPE           = MakeType(typeof(SupportBeanComplexProps));
            SUPPORTLEGACYBEAN_EVENTTTPE                 = MakeType(typeof(SupportLegacyBean));
            SUPPORTBEANCOMBINEDPROPS_EVENTTTPE          = MakeType(typeof(SupportBeanCombinedProps));
            SUPPORTBEANPROPERTYNAMES_EVENTTTPE          = MakeType(typeof(SupportBeanPropertyNames));
            SUPPORTBEANSIMPLE_EVENTTTPE                 = MakeType(typeof(SupportBeanSimple));
            SUPPORTBEANITERABLEPROPS_EVENTTTPE          = MakeType(typeof(SupportBeanIterableProps));
            SUPPORTABCDEEVENT_EVENTTTPE                 = MakeType(typeof(SupportABCDEEvent));
            SUPPORTBEANITERABLEPROPSCONTAINER_EVENTTYPE = MakeType(typeof(SupportBeanIterablePropsContainer));
        }
示例#17
0
        public void TestEquals()
        {
            var metadata = new EventTypeMetadata(
                "MyType",
                null,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.MAP,
                NameAccessModifier.INTERNAL,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());

            IDictionary <string, object> mapTwo = new LinkedHashMap <string, object>();

            mapTwo.Put("MyInt", typeof(int));
            mapTwo.Put("MySupportBean", typeof(SupportBean));
            mapTwo.Put("MyNullableSupportBean", typeof(SupportBean));
            mapTwo.Put("MyComplexBean", typeof(SupportBeanComplexProps));
            Assert.IsFalse(
                new MapEventType(metadata, mapTwo, null, null, null, null, supportEventTypeFactory.BEAN_EVENT_TYPE_FACTORY).Equals(eventType));
            mapTwo.Put("MyString", typeof(string));
            mapTwo.Put("MyNullableString", typeof(string));
            mapTwo.Put("MyNullType", null);

            // compare, should equal
            Assert.IsNull(
                new MapEventType(metadata, mapTwo, null, null, null, null, supportEventTypeFactory.BEAN_EVENT_TYPE_FACTORY).EqualsCompareType(
                    eventType));
            Assert.AreEqual(
                null,
                new MapEventType(metadata, mapTwo, null, null, null, null, supportEventTypeFactory.BEAN_EVENT_TYPE_FACTORY).EqualsCompareType(
                    eventType));

            // Test boxed and primitive compatible
            IDictionary <string, object> mapOne = new LinkedHashMap <string, object>();

            mapOne.Put("MyInt", typeof(int));
            mapTwo = new LinkedHashMap <string, object>();
            mapTwo.Put("MyInt", typeof(int?));
            Assert.IsNull(
                new MapEventType(metadata, mapOne, null, null, null, null, supportEventTypeFactory.BEAN_EVENT_TYPE_FACTORY).EqualsCompareType(
                    new MapEventType(metadata, mapTwo, null, null, null, null,
                                     supportEventTypeFactory.BEAN_EVENT_TYPE_FACTORY)));
        }
示例#18
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;
        }
示例#19
0
        public void SetUp()
        {
            var metadata = new EventTypeMetadata(
                "MyType",
                null,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.MAP,
                NameAccessModifier.INTERNAL,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());

            IDictionary <string, object> testTypesMap = new Dictionary <string, object>();

            testTypesMap.Put("MyInt", typeof(int?));
            testTypesMap.Put("MyString", typeof(string));
            testTypesMap.Put("MyNullableString", typeof(string));
            testTypesMap.Put("MySupportBean", typeof(SupportBean));
            testTypesMap.Put("MyComplexBean", typeof(SupportBeanComplexProps));
            testTypesMap.Put("MyNullableSupportBean", typeof(SupportBean));
            testTypesMap.Put("MyNullType", null);
            eventType = new MapEventType(metadata, testTypesMap, null, null, null, null,
                                         supportEventTypeFactory.BEAN_EVENT_TYPE_FACTORY);
        }
示例#20
0
        public static EventType GetBuiltInEventType(
            string moduleName,
            BeanEventTypeFactory beanEventTypeFactory)
        {
            var metadata = new EventTypeMetadata(
                "anonymous",
                moduleName,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.OBJECTARR,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());

            return(BaseNestableEventUtil.MakeOATypeCompileTime(
                       metadata,
                       TYPEINFO,
                       null,
                       null,
                       null,
                       null,
                       beanEventTypeFactory,
                       null));
        }
示例#21
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;
            }
        }
示例#22
0
        public void TestNestedMap()
        {
            IDictionary <string, object> levelThree = new Dictionary <string, object>();

            levelThree.Put("simpleThree", typeof(long));
            levelThree.Put("objThree", typeof(SupportBean_D));
            levelThree.Put("nodefmapThree", typeof(IDictionary <string, object>));

            IDictionary <string, object> levelTwo = new Dictionary <string, object>();

            levelTwo.Put("simpleTwo", typeof(float));
            levelTwo.Put("objTwo", typeof(SupportBean_C));
            levelTwo.Put("nodefmapTwo", typeof(IDictionary <string, object>));
            levelTwo.Put("mapTwo", levelThree);

            IDictionary <string, object> levelOne = new Dictionary <string, object>();

            levelOne.Put("simpleOne", typeof(int?));
            levelOne.Put("objOne", typeof(SupportBean_B));
            levelOne.Put("nodefmapOne", typeof(IDictionary <string, object>));
            levelOne.Put("mapOne", levelTwo);

            IDictionary <string, object> levelZero = new Dictionary <string, object>();

            levelZero.Put("simple", typeof(double?));
            levelZero.Put("obj", typeof(SupportBean_A));
            levelZero.Put("nodefmap", typeof(IDictionary <string, object>));
            levelZero.Put("map", levelOne);

            var metadata = new EventTypeMetadata(
                "MyType",
                null,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.MAP,
                NameAccessModifier.INTERNAL,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var mapType  = new MapEventType(metadata, levelZero, null, null, null, null, supportEventTypeFactory.BEAN_EVENT_TYPE_FACTORY);
            var testData = GetTestData();
            var theEvent = new MapEventBean(testData, mapType);

            object[][] expected =
            {
                new object[] { "map.mapOne.simpleTwo",          typeof(float?),                                 300f },
                new object[] { "nodefmap.item?",                typeof(object),             "|nodefmap.item|"        },
                new object[] { "map.objOne",                    typeof(SupportBean_B),      new SupportBean_B("B1")  },
                new object[] { "map.simpleOne",                 typeof(int?),                                     20 },
                new[]        {
                    "map.mapOne", typeof(IDictionary <string, object>),
                    testData.Get("map").AsDataMap().Get("mapOne")
                },
                new object[] { "map.mapOne.objTwo",             typeof(SupportBean_C),      new SupportBean_C("C1")  },
                new[]        {
                    "map.mapOne.mapTwo", typeof(IDictionary <string, object>),
                    testData.Get("map").AsDataMap().Get("mapOne").AsDataMap().Get("mapTwo")
                },
                new object[] { "map.mapOne.mapTwo.simpleThree", typeof(long?),                                 4000L },
                new object[] { "map.mapOne.mapTwo.objThree",    typeof(SupportBean_D),      new SupportBean_D("D1")  },
                new object[] { "simple",                        typeof(double?),                                  1d },
                new object[] { "obj",                           typeof(SupportBean_A),      new SupportBean_A("A1")  },
                new[]        { "nodefmap",                      typeof(IDictionary <string, object>), testData.Get("nodefmap")},
                new[]        { "map",                           typeof(IDictionary <string, object>), testData.Get("map")}
            };

            // assert getter available for all properties
            for (var i = 0; i < expected.Length; i++)
            {
                var propName = (string)expected[i][0];
                Assert.IsNotNull(mapType.GetGetter(propName), "failed for property:" + propName);
            }

            // assert property types
            for (var i = 0; i < expected.Length; i++)
            {
                var propName    = (string)expected[i][0];
                var propType    = (Type)expected[i][1];
                var mapPropType = mapType.GetPropertyType(propName);
                Assert.AreEqual(propType, mapPropType, "failed for property:" + propName);
            }

            // assert property names
            string[] expectedPropNames = { "simple", "obj", "map", "nodefmap" };
            var      receivedPropNames = mapType.PropertyNames;

            EPAssertionUtil.AssertEqualsAnyOrder(expectedPropNames, receivedPropNames);

            // assert get value through (1) type getter  (2) event-get
            for (var i = 0; i < expected.Length; i++)
            {
                var propName      = (string)expected[i][0];
                var valueExpected = expected[i][2];
                Assert.AreEqual(valueExpected, mapType.GetGetter(propName).Get(theEvent), "failed for property type-getter:" + propName);
                Assert.AreEqual(valueExpected, theEvent.Get(propName), "failed for property event-getter:" + propName);
            }

            // assert access to objects nested within
            expected = new[] {
                new object[] { "map.objOne.Id", typeof(string), "B1" },
                new object[] { "map.mapOne.objTwo.Id", typeof(string), "C1" },
                new object[] { "obj.Id", typeof(string), "A1" }
            };
            for (var i = 0; i < expected.Length; i++)
            {
                var propName      = (string)expected[i][0];
                var propType      = (Type)expected[i][1];
                var valueExpected = expected[i][2];
                var getter        = mapType.GetGetter(propName);
                Assert.AreEqual(propType, mapType.GetPropertyType(propName), "failed for property:" + propName);
                Assert.AreEqual(valueExpected, getter.Get(theEvent), "failed for property type-getter:" + propName);
                Assert.AreEqual(valueExpected, theEvent.Get(propName), "failed for property event-getter:" + propName);
            }
        }
示例#23
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);
        }
示例#24
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);
        }
示例#25
0
        private TableAccessAnalysisResult AnalyzePlanAggregations(
            string tableName,
            IList<TableColumnDesc> columns,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            // once upfront: obtains aggregation factories for each aggregation
            // we do this once as a factory may be a heavier object
            IDictionary<TableColumnDesc, AggregationForgeFactory> aggregationFactories =
                new Dictionary<TableColumnDesc, AggregationForgeFactory>();
            foreach (var column in columns) {
                if (column is TableColumnDescAgg) {
                    var agg = (TableColumnDescAgg) column;
                    var factory = agg.Aggregation.Factory;
                    aggregationFactories.Put(column, factory);
                }
            }

            // sort into these categories:
            // plain / method-agg / access-agg
            // compile all-column public types
            IList<TableColumnDescTyped> plainColumns = new List<TableColumnDescTyped>();
            IList<TableColumnDescAgg> methodAggColumns = new List<TableColumnDescAgg>();
            IList<TableColumnDescAgg> accessAggColumns = new List<TableColumnDescAgg>();
            var allColumnsPublicTypes = new LinkedHashMap<string, object>();
            foreach (var column in columns) {
                // handle plain types
                if (column is TableColumnDescTyped) {
                    var typed = (TableColumnDescTyped) column;
                    plainColumns.Add(typed);
                    allColumnsPublicTypes.Put(column.ColumnName, typed.UnresolvedType);
                    continue;
                }

                // handle aggs
                var agg = (TableColumnDescAgg) column;
                var aggFactory = aggregationFactories.Get(agg);
                if (aggFactory.IsAccessAggregation) {
                    accessAggColumns.Add(agg);
                }
                else {
                    methodAggColumns.Add(agg);
                }

                allColumnsPublicTypes.Put(column.ColumnName, agg.Aggregation.EvaluationType);
            }

            // determine column metadata
            //
            var columnMetadata = new LinkedHashMap<string, TableMetadataColumn>();

            // handle typed columns
            var allColumnsInternalTypes = new LinkedHashMap<string, object>();
            allColumnsInternalTypes.Put(INTERNAL_RESERVED_PROPERTY, typeof(object));
            var indexPlain = 1;
            var assignPairsPlain = new TableMetadataColumnPairPlainCol[plainColumns.Count];
            foreach (var typedColumn in plainColumns) {
                allColumnsInternalTypes.Put(typedColumn.ColumnName, typedColumn.UnresolvedType);
                columnMetadata.Put(
                    typedColumn.ColumnName,
                    new TableMetadataColumnPlain(typedColumn.ColumnName, typedColumn.IsKey, indexPlain));
                assignPairsPlain[indexPlain - 1] = new TableMetadataColumnPairPlainCol(
                    typedColumn.PositionInDeclaration,
                    indexPlain);
                indexPlain++;
            }

            // determine internally-used event type
            var visibility = services.ModuleVisibilityRules.GetAccessModifierTable(@base, tableName);
            var internalName = EventTypeNameUtil.GetTableInternalTypeName(tableName);
            var internalMetadata = new EventTypeMetadata(
                internalName,
                @base.ModuleName,
                EventTypeTypeClass.TABLE_INTERNAL,
                EventTypeApplicationType.OBJECTARR,
                visibility,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var internalEventType = BaseNestableEventUtil.MakeOATypeCompileTime(
                internalMetadata,
                allColumnsInternalTypes,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(internalEventType);

            // for use by indexes and lookups
            var publicName = EventTypeNameUtil.GetTablePublicTypeName(tableName);
            var publicMetadata = new EventTypeMetadata(
                publicName,
                @base.ModuleName,
                EventTypeTypeClass.TABLE_PUBLIC,
                EventTypeApplicationType.OBJECTARR,
                visibility,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var publicEventType = BaseNestableEventUtil.MakeOATypeCompileTime(
                publicMetadata,
                allColumnsPublicTypes,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(publicEventType);

            // handle aggregation-methods single-func first.
            var methodFactories = new AggregationForgeFactory[methodAggColumns.Count];
            var index = 0;
            var assignPairsMethod = new TableMetadataColumnPairAggMethod[methodAggColumns.Count];
            foreach (var column in methodAggColumns) {
                var factory = aggregationFactories.Get(column);
                var optionalEnumerationType = EPTypeHelper.OptionalFromEnumerationExpr(
                    statementRawInfo,
                    services,
                    column.Aggregation);
                methodFactories[index] = factory;
                var bindingInfo = factory.AggregationPortableValidation;
                var expression =
                    ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(factory.AggregationExpression);
                columnMetadata.Put(
                    column.ColumnName,
                    new TableMetadataColumnAggregation(
                        column.ColumnName,
                        false,
                        index,
                        bindingInfo,
                        expression,
                        true,
                        optionalEnumerationType));
                assignPairsMethod[index] = new TableMetadataColumnPairAggMethod(column.PositionInDeclaration);
                index++;
            }

            // handle access-aggregation (sharable, multi-value) aggregations
            var stateFactories = new AggregationStateFactoryForge[accessAggColumns.Count];
            var accessAccessorForges = new AggregationAccessorSlotPairForge[accessAggColumns.Count];
            var assignPairsAccess = new TableMetadataColumnPairAggAccess[accessAggColumns.Count];
            var accessNum = 0;
            foreach (var column in accessAggColumns) {
                var factory = aggregationFactories.Get(column);
                var forge = factory.GetAggregationStateFactory(false);
                stateFactories[accessNum] = forge;
                var accessor = factory.AccessorForge;
                var bindingInfo = factory.AggregationPortableValidation;
                accessAccessorForges[accessNum] = new AggregationAccessorSlotPairForge(accessNum, accessor);
                var expression =
                    ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(factory.AggregationExpression);
                var optionalEnumerationType = EPTypeHelper.OptionalFromEnumerationExpr(
                    statementRawInfo,
                    services,
                    column.Aggregation);
                columnMetadata.Put(
                    column.ColumnName,
                    new TableMetadataColumnAggregation(
                        column.ColumnName,
                        false,
                        index,
                        bindingInfo,
                        expression,
                        false,
                        optionalEnumerationType));
                assignPairsAccess[accessNum] =
                    new TableMetadataColumnPairAggAccess(column.PositionInDeclaration, accessor);
                index++;
                accessNum++;
            }

            // determine primary key index information
            var primaryKeyColumns = new List<string>();
            var primaryKeyTypes = new List<Type>();
            var primaryKeyGetters = new List<EventPropertyGetterSPI>();
            var primaryKeyColNums = new List<int>();
            
            var colNum = -1;
            foreach (var typedColumn in plainColumns) {
                colNum++;
                if (typedColumn.IsKey) {
                    primaryKeyColumns.Add(typedColumn.ColumnName);
                    primaryKeyTypes.Add(internalEventType.GetPropertyType(typedColumn.ColumnName));
                    primaryKeyGetters.Add(internalEventType.GetGetterSPI(typedColumn.ColumnName));
                    primaryKeyColNums.Add(colNum + 1);
                }
            }

            string[] primaryKeyColumnArray = null;
            Type[] primaryKeyTypeArray = null;
            EventPropertyGetterSPI[] primaryKeyGetterArray = null;

            int[] primaryKeyColNumsArray = null;
            if (!primaryKeyColumns.IsEmpty()) {
                primaryKeyColumnArray = primaryKeyColumns.ToArray();
                primaryKeyTypeArray = primaryKeyTypes.ToArray();
                primaryKeyGetterArray = primaryKeyGetters.ToArray();
                primaryKeyColNumsArray = primaryKeyColNums.ToArray();
            }

            var forgeDesc = new AggregationRowStateForgeDesc(
                methodFactories,
                null,
                stateFactories,
                accessAccessorForges,
                new AggregationUseFlags(false, false, false));
            
            
            var multiKeyPlan = MultiKeyPlanner.PlanMultiKey(
                primaryKeyTypeArray, false, statementRawInfo, services.SerdeResolver);

            var propertyForges = new DataInputOutputSerdeForge[internalEventType.PropertyNames.Length - 1];

            var additionalForgeables = new List<StmtClassForgeableFactory>(multiKeyPlan.MultiKeyForgeables);
            for (var i = 1; i < internalEventType.PropertyNames.Length; i++) {
                var propertyName = internalEventType.PropertyNames[i];
                var propertyType = internalEventType.Types.Get(propertyName);
                var desc = SerdeEventPropertyUtility.ForgeForEventProperty(
                    publicEventType, propertyName, propertyType, statementRawInfo, services.SerdeResolver);
                propertyForges[i - 1] = desc.Forge;

                // plan serdes for nested types
                foreach (var eventType in desc.NestedTypes) {
                    var serdeForgeables = SerdeEventTypeUtility.Plan(
                        eventType,
                        statementRawInfo,
                        services.SerdeEventTypeRegistry,
                        services.SerdeResolver);
                    additionalForgeables.AddAll(serdeForgeables);
                }
            }

            return new TableAccessAnalysisResult(
                columnMetadata,
                internalEventType,
                propertyForges,
                publicEventType,
                assignPairsPlain,
                assignPairsMethod,
                assignPairsAccess,
                forgeDesc,
                primaryKeyColumnArray,
                primaryKeyGetterArray,
                primaryKeyTypeArray,
                primaryKeyColNumsArray,
                multiKeyPlan.ClassRef,
                additionalForgeables);
        }
示例#26
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);
            }
        }
示例#27
0
        private static StreamTypeService BuildDefineStreamTypeServiceDefine(
            int defineNum,
            LinkedHashMap<string, Pair<int, bool>> variableStreams,
            MatchRecognizeDefineItem defineItem,
            IDictionary<string, ISet<string>> visibilityByIdentifier,
            EventType parentViewType,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            if (!variableStreams.ContainsKey(defineItem.Identifier)) {
                throw new ExprValidationException("Variable '" + defineItem.Identifier + "' does not occur in pattern");
            }

            var streamNamesDefine = new string[variableStreams.Count + 1];
            var typesDefine = new EventType[variableStreams.Count + 1];
            var isIStreamOnly = new bool[variableStreams.Count + 1];
            CompatExtensions.Fill(isIStreamOnly, true);

            var streamNumDefine = variableStreams.Get(defineItem.Identifier).First;
            streamNamesDefine[streamNumDefine] = defineItem.Identifier;
            typesDefine[streamNumDefine] = parentViewType;

            // add visible single-value
            var visibles = visibilityByIdentifier.Get(defineItem.Identifier);
            var hasVisibleMultimatch = false;
            if (visibles != null) {
                foreach (var visible in visibles) {
                    var def = variableStreams.Get(visible);
                    if (!def.Second) {
                        streamNamesDefine[def.First] = visible;
                        typesDefine[def.First] = parentViewType;
                    }
                    else {
                        hasVisibleMultimatch = true;
                    }
                }
            }

            // compile multi-matching event type (in last position), if any are used
            if (hasVisibleMultimatch) {
                IDictionary<string, object> multievent = new LinkedHashMap<string, object>();
                foreach (var entry in variableStreams) {
                    var identifier = entry.Key;
                    if (entry.Value.Second) {
                        if (visibles.Contains(identifier)) {
                            multievent.Put(identifier, new[] {parentViewType});
                        }
                        else {
                            multievent.Put("esper_matchrecog_internal", null);
                        }
                    }
                }

                var multimatchTypeName =
                    services.EventTypeNameGeneratorStatement.GetAnonymousRowrecogMultimatchDefineName(defineNum);
                var multimatchTypeMetadata = new EventTypeMetadata(
                    multimatchTypeName,
                    statementRawInfo.ModuleName,
                    EventTypeTypeClass.MATCHRECOGDERIVED,
                    EventTypeApplicationType.OBJECTARR,
                    NameAccessModifier.TRANSIENT,
                    EventTypeBusModifier.NONBUS,
                    false,
                    EventTypeIdPair.Unassigned());
                var multimatchEventType = BaseNestableEventUtil.MakeOATypeCompileTime(
                    multimatchTypeMetadata,
                    multievent,
                    null,
                    null,
                    null,
                    null,
                    services.BeanEventTypeFactoryPrivate,
                    services.EventTypeCompileTimeResolver);

                typesDefine[typesDefine.Length - 1] = multimatchEventType;
                streamNamesDefine[streamNamesDefine.Length - 1] = multimatchEventType.Name;
            }

            return new StreamTypeServiceImpl(typesDefine, streamNamesDefine, isIStreamOnly, false, true);
        }
示例#28
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);
        }
示例#29
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);
        }
示例#30
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));
        }