protected abstract AvroSchemaEventType MakeType(
     EventTypeMetadata metadata,
     string eventTypeName,
     int typeId,
     EventAdapterService eventAdapterService,
     RecordSchema schema,
     ConfigurationEventTypeAvro optionalConfig,
     EventType[] supertypes,
     ICollection <EventType> deepSupertypes);
Esempio n. 2
0
 public void AddEventTypeAvro(string eventTypeName, ConfigurationEventTypeAvro avro)
 {
     CheckTableExists(eventTypeName);
     try {
         _eventAdapterService.AddAvroType(eventTypeName, avro, false, true, true, false, false);
     } catch (EventAdapterException t) {
         throw new ConfigurationException(t.Message, t);
     }
 }
        public AvroSchemaEventType NewEventTypeFromNormalized(
            EventTypeMetadata metadata,
            string eventTypeName,
            int typeId,
            EventAdapterService eventAdapterService,
            IDictionary <string, object> properties,
            Attribute[] annotations,
            ConfigurationEventTypeAvro optionalConfig,
            EventType[] superTypes,
            ICollection <EventType> deepSuperTypes,
            string statementName,
            string engineURI)
        {
            JArray assembler = new JArray();
            //FieldAssembler<Schema> assembler = Record(eventTypeName).Fields();

            // 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 (Field field in superType.SchemaAvro.GetFields())
                    {
                        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, eventAdapterService, statementName,
                        engineURI, _optionalTypeMapper);
                    added.Add(prop.Key);
                }
            }

            var schema = SchemaBuilder.Record(
                eventTypeName, assembler);

            //Schema schema = assembler.EndRecord();
            return(MakeType(
                       metadata, eventTypeName, typeId, eventAdapterService, schema, optionalConfig, superTypes, deepSuperTypes));
        }
Esempio n. 4
0
 public AvroSchemaEventType NewEventTypeFromSchema(
     EventTypeMetadata metadata,
     string eventTypeName,
     int typeId,
     EventAdapterService eventAdapterService,
     ConfigurationEventTypeAvro requiredConfig,
     EventType[] supertypes,
     ICollection <EventType> deepSupertypes)
 {
     throw GetUnsupported();
 }
        public AvroSchemaEventType NewEventTypeFromSchema(
            EventTypeMetadata metadata,
            string eventTypeName,
            int typeId,
            EventAdapterService eventAdapterService,
            ConfigurationEventTypeAvro requiredConfig,
            EventType[] superTypes,
            ICollection <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).FullName + " but received " +
                          avroSchemaObj.GetType().FullName);
            }

            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, eventTypeName, typeId, eventAdapterService, schema.AsRecordSchema(), requiredConfig, superTypes, deepSuperTypes));
        }
 protected override AvroSchemaEventType MakeType(
     EventTypeMetadata metadata,
     string eventTypeName,
     int typeId,
     EventAdapterService eventAdapterService,
     RecordSchema schema,
     ConfigurationEventTypeAvro optionalConfig,
     EventType[] supertypes,
     ICollection <EventType> deepSupertypes)
 {
     return(new AvroEventType(
                metadata, eventTypeName, typeId, eventAdapterService, schema,
                optionalConfig == null ? null : optionalConfig.StartTimestampPropertyName,
                optionalConfig == null ? null : optionalConfig.EndTimestampPropertyName, supertypes, deepSupertypes));
 }
Esempio n. 7
0
 public AvroSchemaEventType NewEventTypeFromNormalized(
     EventTypeMetadata metadata,
     string eventTypeName,
     int typeId,
     EventAdapterService eventAdapterService,
     IDictionary <string, Object> properties,
     Attribute[] annotations,
     ConfigurationEventTypeAvro optionalConfig,
     EventType[] superTypes,
     ICollection <EventType> deepSuperTypes,
     string statementName,
     string engineURI)
 {
     throw GetUnsupported();
 }
Esempio n. 8
0
        public override void Run(EPServiceProvider epService)
        {
            // schema from statement
            var epl            = EventRepresentationChoice.AVRO.GetAnnotationText() + "select 1 as carId, 'abc' as carType from System.Object";
            var stmt           = epService.EPAdministrator.CreateEPL(epl);
            var schema         = (Schema)((AvroSchemaEventType)stmt.EventType).Schema;
            var schemaAsString = SchemaToJsonEncoder.Encode(schema).ToString(Formatting.None);

            Assert.AreEqual("{\"type\":\"record\",\"name\":\"anonymous_1_result_\",\"fields\":[{\"name\":\"carId\",\"type\":\"int\"},{\"name\":\"carType\",\"type\":{\"type\":\"string\",\"avro.string\":\"string\"}}]}", schemaAsString);
            stmt.Dispose();

            // schema to-string Avro
            var schemaTwo = SchemaBuilder.Record("MyAvroEvent",
                                                 TypeBuilder.RequiredInt("carId"),
                                                 TypeBuilder.Field("carType",
                                                                   TypeBuilder.StringType(
                                                                       TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE))));
            var schemaTwoAsString = SchemaToJsonEncoder.Encode(schemaTwo).ToString(Formatting.None);

            Assert.AreEqual("{\"type\":\"record\",\"name\":\"MyAvroEvent\",\"fields\":[{\"name\":\"carId\",\"type\":\"int\"},{\"name\":\"carType\",\"type\":{\"type\":\"string\",\"avro.string\":\"string\"}}]}", schemaTwoAsString);

            // Define CarLocUpdateEvent event type (example for runtime-configuration interface)
            var schemaThree = SchemaBuilder.Record("CarLocUpdateEvent",
                                                   TypeBuilder.Field("carId",
                                                                     TypeBuilder.StringType(
                                                                         TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE))),
                                                   TypeBuilder.RequiredInt("direction"));
            var avroEvent = new ConfigurationEventTypeAvro(schemaThree);

            epService.EPAdministrator.Configuration.AddEventTypeAvro("CarLocUpdateEvent", avroEvent);

            stmt = epService.EPAdministrator.CreateEPL("select count(*) from CarLocUpdateEvent(direction = 1)#time(1 min)");
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;
            var @event = new GenericRecord(schemaThree);

            @event.Put("carId", "A123456");
            @event.Put("direction", 1);
            epService.EPRuntime.SendEventAvro(@event, "CarLocUpdateEvent");
            Assert.AreEqual(1L, listener.AssertOneGetNewAndReset().Get("count(*)"));
        }
Esempio n. 9
0
        public void TestSampleConfigDocOutputSchema()
        {
            // schema from statement
            string      epl            = EventRepresentationChoice.AVRO.GetAnnotationText() + "select 1 as carId, 'abc' as carType from " + Name.Of <object>();
            EPStatement stmt           = _epService.EPAdministrator.CreateEPL(epl);
            Schema      schema         = (Schema)((AvroSchemaEventType)stmt.EventType).Schema;
            String      schemaAsString = SchemaToJsonEncoder.Encode(schema).ToString(Formatting.None);

            Assert.AreEqual("{\"type\":\"record\",\"name\":\"anonymous_1_result_\",\"fields\":[{\"name\":\"carId\",\"type\":\"int\"},{\"name\":\"carType\",\"type\":{\"type\":\"string\",\"avro.string\":\"string\"}}]}", schemaAsString);
            stmt.Dispose();

            // schema to-string Avro
            Schema schemaTwo = SchemaBuilder.Record(
                "MyAvroEvent",
                TypeBuilder.RequiredInt("carId"),
                TypeBuilder.Field((string)"carType", TypeBuilder.TypeWithProperty("string", AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE)));
            String schemaTwoAsString = SchemaToJsonEncoder.Encode(schemaTwo).ToString(Formatting.None);

            Assert.AreEqual("{\"type\":\"record\",\"name\":\"MyAvroEvent\",\"fields\":[{\"name\":\"carId\",\"type\":\"int\"},{\"name\":\"carType\",\"type\":{\"type\":\"string\",\"avro.string\":\"string\"}}]}", schemaTwoAsString);

            // Define CarLocUpdateEvent event type (example for runtime-configuration interface)
            RecordSchema schemaThree = SchemaBuilder.Record(
                "CarLocUpdateEvent",
                TypeBuilder.Field((string)"carId", TypeBuilder.TypeWithProperty("string", AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE)),
                TypeBuilder.RequiredInt("direction"));
            ConfigurationEventTypeAvro avroEvent = new ConfigurationEventTypeAvro(schemaThree);

            _epService.EPAdministrator.Configuration.AddEventTypeAvro("CarLocUpdateEvent", avroEvent);

            stmt = _epService.EPAdministrator.CreateEPL("select count(*) from CarLocUpdateEvent(direction = 1)#time(1 min)");
            SupportUpdateListener listener = new SupportUpdateListener();

            stmt.AddListener(listener);
            GenericRecord @event = new GenericRecord(schemaThree);

            @event.Put("carId", "A123456");
            @event.Put("direction", 1);
            _epService.EPRuntime.SendEventAvro(@event, "CarLocUpdateEvent");
            Assert.AreEqual(1L, listener.AssertOneGetNewAndReset().Get("count(*)"));
        }
Esempio n. 10
0
        private void AddAvroEventTypes(EPServiceProvider epService)
        {
            var fake      = SchemaBuilder.Record("fake");
            var avro_root = new ConfigurationEventTypeAvro();

            avro_root.AvroSchema = fake;
            epService.EPAdministrator.Configuration.AddEventTypeAvro("Avro_Type_Root", avro_root);
            var avro_1 = new ConfigurationEventTypeAvro();

            avro_1.SuperTypes = Collections.SingletonSet("Avro_Type_Root");
            avro_1.AvroSchema = fake;
            epService.EPAdministrator.Configuration.AddEventTypeAvro("Avro_Type_1", avro_1);
            var avro_2 = new ConfigurationEventTypeAvro();

            avro_2.SuperTypes = Collections.SingletonSet("Avro_Type_Root");
            avro_2.AvroSchema = fake;
            epService.EPAdministrator.Configuration.AddEventTypeAvro("Avro_Type_2", avro_2);
            var avro_2_1 = new ConfigurationEventTypeAvro();

            avro_2_1.SuperTypes = Collections.SingletonSet("Avro_Type_2");
            avro_2_1.AvroSchema = fake;
            epService.EPAdministrator.Configuration.AddEventTypeAvro("Avro_Type_2_1", avro_2_1);
        }
Esempio n. 11
0
        private void RunNestedMap(EPServiceProvider epService)
        {
            var innerSchema = SchemaBuilder.Record(
                "InnerSchema", TypeBuilder.Field("mymap", TypeBuilder.Map(TypeBuilder.StringType())));
            var recordSchema = SchemaBuilder.Record(
                "OuterSchema", TypeBuilder.Field("i", innerSchema));
            var avro = new ConfigurationEventTypeAvro(recordSchema);

            epService.EPAdministrator.Configuration.AddEventTypeAvro("MyNestedMap", avro);

            var stmt     = epService.EPAdministrator.CreateEPL("select i.mymap('x') as c0 from MyNestedMap");
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            var inner = new GenericRecord(innerSchema);

            inner.Put("mymap", Collections.SingletonMap("x", "y"));
            var record = new GenericRecord(recordSchema);

            record.Put("i", inner);
            epService.EPRuntime.SendEventAvro(record, "MyNestedMap");
            Assert.AreEqual("y", listener.AssertOneGetNewAndReset().Get("c0"));
        }