protected abstract AvroSchemaEventType MakeType(
     EventTypeMetadata metadata,
     EventBeanTypedEventFactory eventAdapterService,
     Schema schema,
     ConfigurationCommonEventTypeAvro optionalConfig,
     EventType[] supertypes,
     ISet<EventType> deepSupertypes);
 private static void BuildAvroType(
     EventTypeRepositoryImpl eventTypeRepositoryPreconfigured,
     string eventTypeName,
     ConfigurationCommonEventTypeAvro config,
     EventTypeAvroHandler eventTypeAvroHandler,
     EventBeanTypedEventFactory eventBeanTypedEventFactory)
 {
     var metadata = new EventTypeMetadata(
         eventTypeName,
         null,
         EventTypeTypeClass.APPLICATION,
         EventTypeApplicationType.AVRO,
         NameAccessModifier.PRECONFIGURED,
         EventTypeBusModifier.NONBUS,
         false,
         new EventTypeIdPair(CRC32Util.ComputeCRC32(eventTypeName), -1));
     var avroSuperTypes = EventTypeUtility.GetSuperTypesDepthFirst(
         config.SuperTypes,
         EventUnderlyingType.AVRO,
         eventTypeRepositoryPreconfigured);
     var newEventType = eventTypeAvroHandler.NewEventTypeFromSchema(
         metadata,
         eventBeanTypedEventFactory,
         config,
         avroSuperTypes.First,
         avroSuperTypes.Second);
     eventTypeRepositoryPreconfigured.AddType(newEventType);
 }
 public AvroSchemaEventType NewEventTypeFromSchema(
     EventTypeMetadata metadata,
     EventBeanTypedEventFactory eventBeanTypedEventFactory,
     ConfigurationCommonEventTypeAvro requiredConfig,
     EventType[] supertypes,
     ISet<EventType> deepSupertypes)
 {
     throw new UnsupportedOperationException();
 }
 public AvroSchemaEventType NewEventTypeFromNormalized(
     EventTypeMetadata metadata,
     EventTypeNameResolver eventTypeNameResolver,
     EventBeanTypedEventFactory eventBeanTypedEventFactory,
     IDictionary<string, object> properties,
     Attribute[] annotations,
     ConfigurationCommonEventTypeAvro optionalConfig,
     EventType[] superTypes,
     ISet<EventType> deepSuperTypes,
     string statementName)
 {
     throw new UnsupportedOperationException();
 }
        public AvroSchemaEventType NewEventTypeFromNormalized(
            EventTypeMetadata metadata,
            EventTypeNameResolver eventTypeNameResolver,
            EventBeanTypedEventFactory eventAdapterService,
            IDictionary<string, object> properties,
            Attribute[] annotations,
            ConfigurationCommonEventTypeAvro optionalConfig,
            EventType[] superTypes,
            ISet<EventType> deepSuperTypes,
            string statementName)
        {
            var assembler = new JArray();
            var eventTypeName = metadata.Name;

            // add supertypes first so the positions are comparable
            var added = new HashSet<string>();
            if (superTypes != null) {
                for (var i = 0; i < superTypes.Length; i++) {
                    var superType = (AvroEventType) superTypes[i];
                    foreach (var field in superType.SchemaAvro.AsRecordSchema().Fields) {
                        if (properties.ContainsKey(field.Name) || added.Contains(field.Name)) {
                            continue;
                        }

                        added.Add(field.Name);
                        assembler.Add(TypeBuilder.Field(field.Name, field.Schema));
                        //assembler.Name(field.Name).Type(field.Schema).NoDefault();
                    }
                }
            }

            foreach (var prop in properties) {
                if (!added.Contains(prop.Key)) {
                    AvroSchemaUtil.AssembleField(
                        prop.Key,
                        prop.Value,
                        assembler,
                        annotations,
                        _avroSettings,
                        eventTypeNameResolver,
                        statementName,
                        _optionalTypeMapper);
                    added.Add(prop.Key);
                }
            }

            var schema = SchemaBuilder.Record(eventTypeName, assembler);
            //Schema schema = assembler.EndRecord();
            return MakeType(metadata, eventAdapterService, schema, optionalConfig, superTypes, deepSuperTypes);
        }
Example #6
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);
        }
Example #7
0
 protected override AvroSchemaEventType MakeType(
     EventTypeMetadata metadata,
     EventBeanTypedEventFactory eventBeanTypedEventFactory,
     Schema schema,
     ConfigurationCommonEventTypeAvro optionalConfig,
     EventType[] supertypes,
     ISet<EventType> deepSupertypes)
 {
     return new AvroEventType(
         metadata,
         schema,
         optionalConfig?.StartTimestampPropertyName,
         optionalConfig?.EndTimestampPropertyName,
         supertypes,
         deepSupertypes,
         eventBeanTypedEventFactory,
         this);
 }
        public AvroSchemaEventType NewEventTypeFromSchema(
            EventTypeMetadata metadata,
            EventBeanTypedEventFactory eventAdapterService,
            ConfigurationCommonEventTypeAvro requiredConfig,
            EventType[] superTypes,
            ISet<EventType> deepSuperTypes)
        {
            var avroSchemaObj = requiredConfig.AvroSchema;
            var avroSchemaText = requiredConfig.AvroSchemaText;

            if (avroSchemaObj == null && avroSchemaText == null) {
                throw new ArgumentException("Null value for schema and schema text");
            }

            if (avroSchemaObj != null && avroSchemaText != null) {
                throw new ArgumentException(
                    "Both avro schema and avro schema text are supplied and one can be provided");
            }

            if (avroSchemaObj != null && !(avroSchemaObj is Schema)) {
                throw new ArgumentException(
                    "Schema expected of type " + typeof(Schema).Name + " but received " + avroSchemaObj.GetType().Name);
            }

            Schema schema;
            if (avroSchemaObj != null) {
                schema = (Schema) avroSchemaObj;
            }
            else {
                try {
                    schema = Schema.Parse(avroSchemaText);
                }
                catch (Exception ex) {
                    throw new EPException("Failed for parse avro schema: " + ex.Message, ex);
                }
            }

            return MakeType(metadata, eventAdapterService, schema, requiredConfig, superTypes, deepSuperTypes);
        }
Example #9
0
        private static void Configure(Configuration configuration)
        {
            foreach (var clazz in new[] {typeof(SupportBean)}) {
                configuration.Common.AddEventType(clazz);
            }

            var schemaUser =
                "******"namespace\": \"example.avro\",\n" +
                " \"type\": \"record\",\n" +
                " \"name\": \"User\",\n" +
                " \"fields\": [\n" +
                "     {\"name\": \"name\",  \"type\": {\n" +
                "                              \"type\": \"string\",\n" +
                "                              \"avro.string\": \"String\"\n" +
                "                            }},\n" +
                "     {\"name\": \"favorite_number\",  \"type\": \"int\"},\n" +
                "     {\"name\": \"favorite_color\",  \"type\": {\n" +
                "                              \"type\": \"string\",\n" +
                "                              \"avro.string\": \"String\"\n" +
                "                            }}\n" +
                " ]\n" +
                "}";
            var schema = Schema.Parse(schemaUser);
            configuration.Common.AddEventTypeAvro("User", new ConfigurationCommonEventTypeAvro(schema));

            var schemaCarLocUpdateEvent = SchemaBuilder.Record(
                "CarLocUpdateEvent",
                TypeBuilder.Field(
                    "carId",
                    TypeBuilder.StringType(
                        TypeBuilder.Property(PROP_STRING_KEY, PROP_STRING_VALUE))),
                TypeBuilder.RequiredInt("direction"));
            var avroEvent = new ConfigurationCommonEventTypeAvro(schemaCarLocUpdateEvent);
            configuration.Common.AddEventTypeAvro("CarLocUpdateEvent", avroEvent);

            var avro = new ConfigurationCommonEventTypeAvro(EventAvroEventBean.RECORD_SCHEMA);
            configuration.Common.AddEventTypeAvro("MyNestedMap", avro);
        }
Example #10
0
        // The create window command:
        //      create window windowName[.window_view_list] as [select properties from] type
        //
        // This section expected s single FilterStreamSpecCompiled representing the selected type.
        // It creates a new event type representing the window type and a sets the type selected on the filter stream spec.
        protected internal static CreateWindowCompileResult HandleCreateWindow(
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var createWindowDesc = @base.StatementSpec.Raw.CreateWindowDesc;
            var columns = createWindowDesc.Columns;
            var typeName = createWindowDesc.WindowName;
            EventType targetType;

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

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

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

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

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

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

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

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

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

                        var selectFromType = optionalSelectFrom.EventType;

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

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

            var filter = new FilterSpecCompiled(targetType, typeName, FilterSpecPlanForge.EMPTY, null);
            return new CreateWindowCompileResult(
                filter,
                newSelectClauseSpecRaw,
                optionalSelectFrom?.EventType,
                additionalForgeables);
        }