예제 #1
0
        private void RunAssertionAvroSchemaWAnnotation(EPServiceProvider epService)
        {
            var schema         = SchemaBuilder.Union(TypeBuilder.IntType(), TypeBuilder.StringType());
            var schemaAsString = SchemaToJsonEncoder.Encode(schema).ToString(Formatting.None);
            var epl            = "@AvroSchemaField(Name='carId',Schema='" + schemaAsString + "') create avro schema MyEvent(carId object)";

            epService.EPAdministrator.CreateEPL(epl);
            Log.Info(schema.ToString());
        }
예제 #2
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(*)"));
        }
예제 #3
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(*)"));
        }
예제 #4
0
        /// <summary>
        /// Decompiles the schema into a json object.
        /// </summary>
        /// <param name="schema">The schema.</param>
        /// <returns></returns>
        public static JToken ToJsonObject(this Schema schema)
        {
            var jsonRepr = SchemaToJsonEncoder.Encode(schema);

            return(jsonRepr);
        }