private void RunAssertionCompatExisting() { string epl = "insert into AvroExistingType select 1 as myLong," + "{1L, 2L} as myLongArray," + this.GetType().FullName + ".MakeByteArray() as myByteArray, " + this.GetType().FullName + ".MakeMapStringString() as myMap " + "from SupportBean"; Schema schema = SchemaBuilder.Record("name", TypeBuilder.RequiredLong("myLong"), TypeBuilder.Field("myLongArray", TypeBuilder.Array(TypeBuilder.Long())), TypeBuilder.Field("myByteArray", TypeBuilder.Bytes()), TypeBuilder.Field("myMap", TypeBuilder.Map(TypeBuilder.String( TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE))))); _epService.EPAdministrator.Configuration.AddEventTypeAvro("AvroExistingType", new ConfigurationEventTypeAvro(schema)); EPStatement statement = _epService.EPAdministrator.CreateEPL(epl); SupportUpdateListener listener = new SupportUpdateListener(); statement.AddListener(listener); _epService.EPRuntime.SendEvent(new SupportBean()); EventBean @event = listener.AssertOneGetNewAndReset(); SupportAvroUtil.AvroToJson(@event); Assert.AreEqual(1L, @event.Get("myLong")); EPAssertionUtil.AssertEqualsExactOrder(new long[] { 1L, 2L }, @event.Get("myLongArray").UnwrapIntoArray <long>()); Assert.IsTrue(CompatExtensions.IsEqual(new byte[] { 1, 2, 3 }, ((byte[])@event.Get("myByteArray")))); Assert.AreEqual("[k1=v1]", CompatExtensions.Render(@event.Get("myMap").AsStringDictionary())); statement.Dispose(); }
private static RecordSchema GetAvroSchema() { return(SchemaBuilder.Record(SupportEventInfra.AVRO_TYPENAME, TypeBuilder.Field("indexed", TypeBuilder.Union( TypeBuilder.Null(), TypeBuilder.Int(), TypeBuilder.Array(TypeBuilder.Int()))), TypeBuilder.Field("mapped", TypeBuilder.Union( TypeBuilder.Null(), TypeBuilder.Int(), TypeBuilder.Map(TypeBuilder.Int()))))); }
private static RecordSchema GetAvroSchema() { return(SchemaBuilder.Record( "AvroSchema", TypeBuilder.Field( "indexed", TypeBuilder.Array( TypeBuilder.StringType( TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE)))), TypeBuilder.Field( "mapped", TypeBuilder.Map( TypeBuilder.StringType( TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE)))) )); }
private static RecordSchema GetAvroSchema() { Schema s4 = SchemaBuilder.Record(SupportEventInfra.AVRO_TYPENAME + "_4", TypeBuilder.RequiredInt("lvl4")); Schema s3 = SchemaBuilder.Record(SupportEventInfra.AVRO_TYPENAME + "_3", TypeBuilder.Field("l4", TypeBuilder.Array(s4)), TypeBuilder.RequiredInt("lvl3")); Schema s2 = SchemaBuilder.Record(SupportEventInfra.AVRO_TYPENAME + "_2", TypeBuilder.Field("l3", TypeBuilder.Array(s3)), TypeBuilder.RequiredInt("lvl2")); Schema s1 = SchemaBuilder.Record(SupportEventInfra.AVRO_TYPENAME + "_1", TypeBuilder.Field("l2", TypeBuilder.Array(s2)), TypeBuilder.RequiredInt("lvl1")); return(SchemaBuilder.Record(SupportEventInfra.AVRO_TYPENAME, TypeBuilder.Field("l1", TypeBuilder.Array(s1)))); }
private static RecordSchema GetAvroSchema() { return SchemaBuilder.Record( AVRO_TYPENAME, TypeBuilder.Field( "indexed", TypeBuilder.Union( TypeBuilder.NullType(), TypeBuilder.IntType(), TypeBuilder.Array(TypeBuilder.IntType()))), TypeBuilder.Field( "mapped", TypeBuilder.Union( TypeBuilder.NullType(), TypeBuilder.IntType(), TypeBuilder.Map(TypeBuilder.IntType()))) ); }
private static RecordSchema GetAvroSchema() { return(SchemaBuilder.Record( "AvroSchema", TypeBuilder.Field( "indexed", TypeBuilder.Array( TypeBuilder.String( TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE)))), TypeBuilder.Field( "mapped", TypeBuilder.Map( TypeBuilder.String(TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE)))) )); //return SchemaBuilder.Record("AvroSchema").Fields() // .Name("indexed").Type(Array().Items().StringBuilder().Prop(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE).EndString()).NoDefault() // .Name("mapped").Type(Map().Values().StringBuilder().Prop(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE).EndString()).NoDefault() // .EndRecord(); }
private void RunAssertionNewSchema() { string epl = EventRepresentationChoice.AVRO.GetAnnotationText() + " select 1 as myInt," + "{1L, 2L} as myLongArray," + this.GetType().FullName + ".MakeByteArray() as myByteArray, " + this.GetType().FullName + ".MakeMapStringString() as myMap " + "from SupportBean"; EPStatement statement = _epService.EPAdministrator.CreateEPL(epl); SupportUpdateListener listener = new SupportUpdateListener(); statement.AddListener(listener); _epService.EPRuntime.SendEvent(new SupportBean()); EventBean @event = listener.AssertOneGetNewAndReset(); string json = SupportAvroUtil.AvroToJson(@event); Console.WriteLine(json); Assert.AreEqual(1, @event.Get("myInt")); EPAssertionUtil.AssertEqualsExactOrder(new long[] { 1L, 2L }, @event.Get("myLongArray").UnwrapIntoArray <long>()); Assert.IsTrue(CompatExtensions.IsEqual(new byte[] { 1, 2, 3 }, ((byte[])@event.Get("myByteArray")))); Assert.AreEqual("[k1=v1]", CompatExtensions.Render(@event.Get("myMap").AsStringDictionary())); var designSchema = SchemaBuilder.Record("name", TypeBuilder.RequiredInt("myInt"), TypeBuilder.Field("myLongArray", TypeBuilder.Array(TypeBuilder.Union(TypeBuilder.Null(), TypeBuilder.Long()))), TypeBuilder.Field("myByteArray", TypeBuilder.Bytes()), TypeBuilder.Field("myMap", TypeBuilder.Map( TypeBuilder.String(TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE))))); var assembledSchema = ((AvroEventType)@event.EventType).SchemaAvro; var compareMsg = SupportAvroUtil.CompareSchemas(designSchema, assembledSchema); Assert.IsNull(compareMsg, compareMsg); statement.Dispose(); }
private static void AssembleFieldForCollection( string propertyName, object propertyType, JArray assembler, ConfigurationEngineDefaults.AvroSettings avroSettings, Type propertyClass, bool preferNonNull) { var componentType = propertyClass.GetIndexType(); var componentTypeBoxed = componentType.GetBoxedType(); var nullableElements = componentType == componentTypeBoxed; if (componentTypeBoxed == typeof(bool?)) { AssembleArray( nullableElements, ARRAY_OF_REQ_BOOLEAN, ARRAY_OF_OPT_BOOLEAN, assembler, propertyName, preferNonNull); } else if (componentTypeBoxed == typeof(int?)) { AssembleArray( nullableElements, ARRAY_OF_REQ_INT, ARRAY_OF_OPT_INT, assembler, propertyName, preferNonNull); } else if (componentTypeBoxed == typeof(long?)) { AssembleArray( nullableElements, ARRAY_OF_REQ_LONG, ARRAY_OF_OPT_LONG, assembler, propertyName, preferNonNull); } else if (componentTypeBoxed == typeof(float?)) { AssembleArray( nullableElements, ARRAY_OF_REQ_FLOAT, ARRAY_OF_OPT_FLOAT, assembler, propertyName, preferNonNull); } else if (componentTypeBoxed == typeof(double?)) { AssembleArray( nullableElements, ARRAY_OF_REQ_DOUBLE, ARRAY_OF_OPT_DOUBLE, assembler, propertyName, preferNonNull); } else if (componentTypeBoxed == typeof(byte?)) { AssembleArray( nullableElements, ARRAY_OF_REQ_INT, ARRAY_OF_OPT_INT, assembler, propertyName, preferNonNull); } else if (propertyClass == typeof(string[])) { JObject array; if (avroSettings.IsEnableNativeString) { array = TypeBuilder.Array(TypeBuilder.String(TypeBuilder.Property( AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE))); } else { array = TypeBuilder.Array(TypeBuilder.String()); } if (preferNonNull) { assembler.Add(TypeBuilder.Field(propertyName, array)); } else { assembler.Add(TypeBuilder.Field(propertyName, TypeBuilder.Union( TypeBuilder.Null(), array))); } } else { throw MakeEPException(propertyName, propertyType); } }
internal static void AssembleField( string propertyName, Object propertyType, JArray assembler, Attribute[] annotations, ConfigurationEngineDefaults.AvroSettings avroSettings, EventAdapterService eventAdapterService, string statementName, string engineURI, TypeRepresentationMapper optionalMapper) { if (propertyName.Contains(".")) { throw new EPException( "Invalid property name as Avro does not allow dot '.' in field names (property '" + propertyName + "')"); } Schema schema = GetAnnotationSchema(propertyName, annotations); if (schema != null) { assembler.Add(TypeBuilder.Field(propertyName, schema)); // assembler.Name(propertyName).Type(schema).NoDefault(); return; } if (optionalMapper != null && propertyType is Type) { var result = (Schema) optionalMapper.Map( new TypeRepresentationMapperContext( (Type) propertyType, propertyName, statementName, engineURI)); if (result != null) { assembler.Add(TypeBuilder.Field(propertyName, result)); // assembler.Name(propertyName).Type(result).NoDefault(); return; } } if (propertyType == null) { assembler.Add(TypeBuilder.Field(propertyName, TypeBuilder.Null())); // assembler.Name(propertyName).Type("null"); } else if (propertyType is string) { string propertyTypeName = propertyType.ToString(); bool isArray = EventTypeUtility.IsPropertyArray(propertyTypeName); if (isArray) { propertyTypeName = EventTypeUtility.GetPropertyRemoveArray(propertyTypeName); } // Add EventType itself as a property EventType eventType = eventAdapterService.GetEventTypeByName(propertyTypeName); if (!(eventType is AvroEventType)) { throw new EPException( "Type definition encountered an unexpected property type name '" + propertyType + "' for property '" + propertyName + "', expected the name of a previously-declared Avro type"); } schema = ((AvroEventType) eventType).SchemaAvro; if (!isArray) { assembler.Add(TypeBuilder.Field(propertyName, schema)); } else { assembler.Add(TypeBuilder.Field(propertyName, TypeBuilder.Array(schema))); } } else if (propertyType is EventType) { var eventType = (EventType) propertyType; CheckCompatibleType(eventType); if (eventType is AvroEventType) { schema = ((AvroEventType) eventType).SchemaAvro; assembler.Add(TypeBuilder.Field(propertyName, schema)); } else if (eventType is MapEventType) { var mapEventType = (MapEventType) eventType; var nestedSchema = AssembleNestedSchema( mapEventType, avroSettings, annotations, eventAdapterService, statementName, engineURI, optionalMapper); assembler.Add(TypeBuilder.Field(propertyName, nestedSchema)); } else { throw new IllegalStateException("Unrecognized event type " + eventType); } } else if (propertyType is EventType[]) { EventType eventType = ((EventType[]) propertyType)[0]; CheckCompatibleType(eventType); if (eventType is AvroEventType) { schema = ((AvroEventType) eventType).SchemaAvro; assembler.Add(TypeBuilder.Field(propertyName, TypeBuilder.Array(schema))); } else if (eventType is MapEventType) { var mapEventType = (MapEventType) eventType; var nestedSchema = AssembleNestedSchema( mapEventType, avroSettings, annotations, eventAdapterService, statementName, engineURI, optionalMapper); assembler.Add(TypeBuilder.Field(propertyName, TypeBuilder.Array(nestedSchema))); } else { throw new IllegalStateException("Unrecognized event type " + eventType); } } else if (propertyType is Type) { var propertyClass = (Type) propertyType; var propertyClassBoxed = propertyClass.GetBoxedType(); bool nullable = propertyClass == propertyClassBoxed; bool preferNonNull = avroSettings.IsEnableSchemaDefaultNonNull; if (propertyClassBoxed == typeof (bool?)) { AssemblePrimitive(nullable, REQ_BOOLEAN, OPT_BOOLEAN, assembler, propertyName, preferNonNull); } else if (propertyClassBoxed == typeof (int?) || propertyClassBoxed == typeof (byte?)) { AssemblePrimitive(nullable, REQ_INT, OPT_INT, assembler, propertyName, preferNonNull); } else if (propertyClassBoxed == typeof (long?)) { AssemblePrimitive(nullable, REQ_LONG, OPT_LONG, assembler, propertyName, preferNonNull); } else if (propertyClassBoxed == typeof (float?)) { AssemblePrimitive(nullable, REQ_FLOAT, OPT_FLOAT, assembler, propertyName, preferNonNull); } else if (propertyClassBoxed == typeof (double?)) { AssemblePrimitive(nullable, REQ_DOUBLE, OPT_DOUBLE, assembler, propertyName, preferNonNull); } else if (propertyClass == typeof (string)) { if (avroSettings.IsEnableNativeString) { if (preferNonNull) { assembler.Add( TypeBuilder.Field(propertyName, TypeBuilder.Primitive("string", TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE)))); } else { assembler.Add( TypeBuilder.Field( propertyName, TypeBuilder.Union( TypeBuilder.Null(), TypeBuilder.String( TypeBuilder.Property( AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE))))); } } else { AssemblePrimitive(nullable, REQ_STRING, OPT_STRING, assembler, propertyName, preferNonNull); } } else if (propertyClass == typeof (byte[])) { if (preferNonNull) { assembler.Add(TypeBuilder.RequiredBytes(propertyName)); } else { assembler.Add(TypeBuilder.Field(propertyName, TypeBuilder.Union( TypeBuilder.Null(), TypeBuilder.Bytes()))); } } else if (propertyClass.IsArray) { var componentType = propertyClass.GetElementType(); var componentTypeBoxed = componentType.GetBoxedType(); var nullableElements = componentType == componentTypeBoxed; if (componentTypeBoxed == typeof (bool?)) { AssembleArray( nullableElements, ARRAY_OF_REQ_BOOLEAN, ARRAY_OF_OPT_BOOLEAN, assembler, propertyName, preferNonNull); } else if (componentTypeBoxed == typeof (int?)) { AssembleArray( nullableElements, ARRAY_OF_REQ_INT, ARRAY_OF_OPT_INT, assembler, propertyName, preferNonNull); } else if (componentTypeBoxed == typeof (long?)) { AssembleArray( nullableElements, ARRAY_OF_REQ_LONG, ARRAY_OF_OPT_LONG, assembler, propertyName, preferNonNull); } else if (componentTypeBoxed == typeof (float?)) { AssembleArray( nullableElements, ARRAY_OF_REQ_FLOAT, ARRAY_OF_OPT_FLOAT, assembler, propertyName, preferNonNull); } else if (componentTypeBoxed == typeof(double?)) { AssembleArray( nullableElements, ARRAY_OF_REQ_DOUBLE, ARRAY_OF_OPT_DOUBLE, assembler, propertyName, preferNonNull); } else if (componentTypeBoxed == typeof (byte?)) { AssembleArray( nullableElements, ARRAY_OF_REQ_INT, ARRAY_OF_OPT_INT, assembler, propertyName, preferNonNull); } else if (propertyClass == typeof (string[])) { JObject array; if (avroSettings.IsEnableNativeString) { array = TypeBuilder.Array(TypeBuilder.String(TypeBuilder.Property( AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE))); } else { array = TypeBuilder.Array(TypeBuilder.String()); } if (preferNonNull) { assembler.Add(TypeBuilder.Field(propertyName, array)); } else { assembler.Add(TypeBuilder.Field(propertyName, TypeBuilder.Union( TypeBuilder.Null(), array))); } } else if (propertyClass.CanUnwrap<object>()) { } else { throw MakeEPException(propertyName, propertyType); } } else if (propertyClass.IsGenericDictionary()) { JToken value; if (avroSettings.IsEnableNativeString) { value = TypeBuilder.String( TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE)); } else { value = TypeBuilder.String(); } if (preferNonNull) { assembler.Add(TypeBuilder.Field(propertyName, TypeBuilder.Map(value))); } else { assembler.Add(TypeBuilder.Field(propertyName, TypeBuilder.Union( TypeBuilder.Null(), TypeBuilder.Map(value)))); } } else if (propertyClass.IsGenericCollection()) { AssembleFieldForCollection(propertyName, propertyType, assembler, avroSettings, propertyClass, preferNonNull); } else { throw MakeEPException(propertyName, propertyType); } } else { throw MakeEPException(propertyName, propertyType); } }
private void RunAssertionNamedWindowSetMapProps( EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum) { // test named-window update epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); epService.EPAdministrator.CreateEPL( eventRepresentationEnum.GetAnnotationText() + " create schema MyNWInfraType(simple string, myarray int[], mymap Map)"); var stmtWin = epService.EPAdministrator.CreateEPL("create window MyWindow#keepall as MyNWInfraType"); epService.EPAdministrator.CreateEPL( eventRepresentationEnum.GetAnnotationText() + " insert into MyWindow select * from MyNWInfraType"); if (eventRepresentationEnum.IsObjectArrayEvent()) { epService.EPRuntime.SendEvent( new object[] { null, new int[10], new Dictionary <string, object>() }, "MyNWInfraType"); } else if (eventRepresentationEnum.IsMapEvent()) { epService.EPRuntime.SendEvent( MakeMapEvent(new Dictionary <string, object>(), new int[10]), "MyNWInfraType"); } else if (eventRepresentationEnum.IsAvroEvent()) { var @event = new GenericRecord( SupportAvroUtil.GetAvroSchema(epService, "MyNWInfraType").AsRecordSchema()); @event.Put("myarray", Collections.List(0, 0, 0, 0, 0)); @event.Put("mymap", new Dictionary <string, object>()); epService.EPRuntime.SendEventAvro(@event, "MyNWInfraType"); } else { Assert.Fail(); } epService.EPAdministrator.CreateEPL( "on SupportBean update MyWindow set simple='A', mymap('abc') = IntPrimitive, myarray[2] = IntPrimitive"); epService.EPRuntime.SendEvent(new SupportBean("E1", 10)); EPAssertionUtil.AssertPropsPerRow( stmtWin.GetEnumerator(), "simple,mymap('abc'),myarray[2]".Split(','), new[] { new object[] { "A", 10, 10 } }); // test null and array too small if (eventRepresentationEnum.IsObjectArrayEvent()) { epService.EPRuntime.SendEvent(new object[] { null, new int[2], null }, "MyNWInfraType"); } else if (eventRepresentationEnum.IsMapEvent()) { epService.EPRuntime.SendEvent(MakeMapEvent(null, new int[2]), "MyNWInfraType"); } else if (eventRepresentationEnum.IsAvroEvent()) { var @event = new GenericRecord( SchemaBuilder.Record("name", TypeBuilder.OptionalString("simple"), TypeBuilder.Field("myarray", TypeBuilder.Array(TypeBuilder.LongType())), TypeBuilder.Field("mymap", TypeBuilder.Map(TypeBuilder.StringType())))); @event.Put("myarray", Collections.List(0, 0)); @event.Put("mymap", null); epService.EPRuntime.SendEventAvro(@event, "MyNWInfraType"); } else { Assert.Fail(); } epService.EPRuntime.SendEvent(new SupportBean("E2", 20)); EPAssertionUtil.AssertPropsPerRowAnyOrder( stmtWin.GetEnumerator(), "simple,mymap('abc'),myarray[2]".Split(','), new[] { new object[] { "A", 20, 20 }, new object[] { "A", null, null } }); epService.EPAdministrator.DestroyAllStatements(); foreach (var name in "MyNWInfraType,MyWindow".Split(',')) { epService.EPAdministrator.Configuration.RemoveEventType(name, true); } }
public void Run(RegressionEnvironment env) { // Bean BiConsumer <EventType, NullableObject <string[]> > bean = ( type, nullable) => { if (nullable == null) { env.SendEventBean(new LocalEvent()); } else { env.SendEventBean(new LocalEventSubA(nullable.Value)); } }; var beanepl = $"@public @buseventtype create schema LocalEvent as {typeof(LocalEvent).MaskTypeName()};\n" + $"@public @buseventtype create schema LocalEventSubA as {typeof(LocalEventSubA).MaskTypeName()};\n"; RunAssertion(env, beanepl, bean); // Map BiConsumer <EventType, NullableObject <string[]> > map = ( type, nullable) => { if (nullable == null) { env.SendEventMap(EmptyDictionary <string, object> .Instance, "LocalEvent"); } else { env.SendEventMap(Collections.SingletonDataMap("Array", nullable.Value), "LocalEvent"); } }; var mapepl = "@public @buseventtype create schema LocalEvent();\n"; RunAssertion(env, mapepl, map); // Object-Array var oaepl = "@public @buseventtype create objectarray schema LocalEvent();\n" + "@public @buseventtype create objectarray schema LocalEventSubA (Array string[]) inherits LocalEvent;\n"; RunAssertion(env, oaepl, null); // Json BiConsumer <EventType, NullableObject <string[]> > json = ( type, nullable) => { if (nullable == null) { env.SendEventJson("{}", "LocalEvent"); } else if (nullable.Value == null) { env.SendEventJson(new JObject(new JProperty("Array", null)).ToString(), "LocalEvent"); } else { var @event = new JObject(); var array = new JArray(); @event.Add("Array", array); foreach (var value in nullable.Value) { array.Add(value); } env.SendEventJson(@event.ToString(), "LocalEvent"); } }; RunAssertion( env, "@public @buseventtype @JsonSchema(Dynamic=true) create json schema LocalEvent();\n", json); // Json-Class-Provided RunAssertion( env, "@JsonSchema(ClassName='" + typeof(MyLocalJsonProvided).MaskTypeName() + "') @public @buseventtype @JsonSchema() create json schema LocalEvent();\n", json); // Avro BiConsumer <EventType, NullableObject <string[]> > avro = ( type, nullable) => { var schema = SchemaBuilder.Record("name", TypeBuilder.Field("Array", TypeBuilder.Array(TypeBuilder.StringType()))); GenericRecord @event; if (nullable == null) { // no action @event = new GenericRecord(SupportAvroUtil.GetAvroSchema(type).AsRecordSchema()); } else if (nullable.Value == null) { @event = new GenericRecord(schema); } else { @event = new GenericRecord(schema); @event.Put("Array", Arrays.AsList(nullable.Value)); } env.SendEventAvro(@event, "LocalEvent"); }; RunAssertion(env, "@public @buseventtype create avro schema LocalEvent();\n", avro); }
private static void Configure(Configuration configuration) { foreach (Type clazz in new[] { typeof(SupportBean), typeof(SupportObjectArrayOneDim), typeof(SupportBeanSimple), typeof(SupportBean_A), typeof(SupportRFIDEvent), typeof(SupportBean_S0), typeof(SupportBean_S1), typeof(SupportMarketDataBean), typeof(SupportTemperatureBean), typeof(SupportBeanComplexProps), typeof(SupportBeanInterfaceProps), typeof(SupportBeanErrorTestingOne), typeof(SupportBeanErrorTestingTwo), typeof(SupportBeanReadOnly), typeof(SupportBeanArrayCollMap), typeof(SupportBean_N), typeof(SupportBeanObject), typeof(SupportBeanCtorOne), typeof(SupportBeanCtorTwo), typeof(SupportBean_ST0), typeof(SupportBean_ST1), typeof(SupportEventWithCtorSameType), typeof(SupportBeanCtorThree), typeof(SupportBeanCtorOne), typeof(SupportBean_ST0), typeof(SupportBean_ST1), typeof(SupportEventWithMapFieldSetter), typeof(SupportBeanNumeric), typeof(SupportBeanArrayEvent), typeof(SupportBean_A), typeof(SupportBean_B), typeof(SupportEventContainsSupportBean) }) { configuration.Common.AddEventType(clazz); } Schema avroExistingTypeSchema = SchemaBuilder.Record( "name", TypeBuilder.RequiredLong("MyLong"), TypeBuilder.Field( "MyLongArray", TypeBuilder.Array(TypeBuilder.LongType())), TypeBuilder.Field("MyByteArray", TypeBuilder.BytesType()), TypeBuilder.Field( "MyMap", TypeBuilder.Map( TypeBuilder.StringType( TypeBuilder.Property( AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE))))); configuration.Common.AddEventTypeAvro("AvroExistingType", new ConfigurationCommonEventTypeAvro(avroExistingTypeSchema)); IDictionary<string, object> mapTypeInfo = new Dictionary<string, object>(); mapTypeInfo.Put("one", typeof(string)); mapTypeInfo.Put("two", typeof(string)); configuration.Common.AddEventType("MapOne", mapTypeInfo); configuration.Common.AddEventType("MapTwo", mapTypeInfo); string[] props = {"one", "two"}; object[] types = {typeof(string), typeof(string)}; configuration.Common.AddEventType("OAOne", props, types); configuration.Common.AddEventType("OATwo", props, types); Schema avroOneAndTwoSchema = SchemaBuilder.Record( "name", TypeBuilder.RequiredString("one"), TypeBuilder.RequiredString("two")); configuration.Common.AddEventTypeAvro("AvroOne", new ConfigurationCommonEventTypeAvro(avroOneAndTwoSchema)); configuration.Common.AddEventTypeAvro("AvroTwo", new ConfigurationCommonEventTypeAvro(avroOneAndTwoSchema)); ConfigurationCommonEventTypeBean legacySupportBeanString = new ConfigurationCommonEventTypeBean(); legacySupportBeanString.FactoryMethod = "GetInstance"; configuration.Common.AddEventType("SupportBeanString", typeof(SupportBeanString), legacySupportBeanString); ConfigurationCommonEventTypeBean legacySupportSensorEvent = new ConfigurationCommonEventTypeBean(); legacySupportSensorEvent.FactoryMethod = typeof(SupportSensorEventFactory).FullName + ".GetInstance"; configuration.Common.AddEventType("SupportSensorEvent", typeof(SupportSensorEvent), legacySupportSensorEvent); configuration.Common.AddImportType(typeof(SupportEnum)); IDictionary<string, object> mymapDef = new Dictionary<string, object>(); mymapDef.Put("Anint", typeof(int)); mymapDef.Put("IntBoxed", typeof(int?)); mymapDef.Put("FloatBoxed", typeof(float?)); mymapDef.Put("IntArr", typeof(int[])); mymapDef.Put("MapProp", typeof(IDictionary<string, object>)); mymapDef.Put("IsaImpl", typeof(ISupportAImpl)); mymapDef.Put("IsbImpl", typeof(ISupportBImpl)); mymapDef.Put("IsgImpl", typeof(ISupportAImplSuperGImpl)); mymapDef.Put("IsabImpl", typeof(ISupportBaseABImpl)); mymapDef.Put("Nested", typeof(SupportBeanComplexProps.SupportBeanSpecialGetterNested)); configuration.Common.AddEventType("MyMap", mymapDef); IDictionary<string, object> defMap = new Dictionary<string, object>(); defMap.Put("intVal", typeof(int)); defMap.Put("stringVal", typeof(string)); defMap.Put("doubleVal", typeof(double?)); defMap.Put("nullVal", null); configuration.Common.AddEventType("MyMapType", defMap); string[] propsMyOAType = new string[] {"intVal", "stringVal", "doubleVal", "nullVal"}; object[] typesMyOAType = new object[] {typeof(int), typeof(string), typeof(double?), null}; configuration.Common.AddEventType("MyOAType", propsMyOAType, typesMyOAType); Schema schema = SchemaBuilder.Record( "MyAvroType", TypeBuilder.RequiredInt("intVal"), TypeBuilder.RequiredString("stringVal"), TypeBuilder.RequiredDouble("doubleVal"), TypeBuilder.Field("nullVal", TypeBuilder.NullType())); configuration.Common.AddEventTypeAvro("MyAvroType", new ConfigurationCommonEventTypeAvro(schema)); ConfigurationCommonEventTypeXMLDOM xml = new ConfigurationCommonEventTypeXMLDOM(); xml.RootElementName = "abc"; configuration.Common.AddEventType("xmltype", xml); IDictionary<string, object> mapDef = new Dictionary<string, object>(); mapDef.Put("IntPrimitive", typeof(int)); mapDef.Put("LongBoxed", typeof(long?)); mapDef.Put("TheString", typeof(string)); mapDef.Put("BoolPrimitive", typeof(bool?)); configuration.Common.AddEventType("MySupportMap", mapDef); IDictionary<string, object> type = MakeMap( new object[][] { new object[] {"Id", typeof(string)} }); configuration.Common.AddEventType("AEventMap", type); configuration.Common.AddEventType("BEventMap", type); IDictionary<string, object> metadata = MakeMap( new object[][] {new object[] {"Id", typeof(string)}}); configuration.Common.AddEventType("AEventTE", metadata); configuration.Common.AddEventType("BEventTE", metadata); configuration.Common.AddImportType(typeof(SupportStaticMethodLib)); configuration.Common.AddImportNamespace(typeof(EPLInsertIntoPopulateUnderlying)); IDictionary<string, object> complexMapMetadata = MakeMap( new object[][] { new object[] { "Nested", MakeMap( new object[][] { new object[] {"NestedValue", typeof(string)} }) } }); configuration.Common.AddEventType("ComplexMap", complexMapMetadata); configuration.Compiler.ByteCode.AllowSubscriber = true; configuration.Compiler.AddPlugInSingleRowFunction("generateMap", typeof(EPLInsertIntoTransposeStream), "LocalGenerateMap"); configuration.Compiler.AddPlugInSingleRowFunction("generateOA", typeof(EPLInsertIntoTransposeStream), "LocalGenerateOA"); configuration.Compiler.AddPlugInSingleRowFunction("generateAvro", typeof(EPLInsertIntoTransposeStream), "LocalGenerateAvro"); configuration.Compiler.AddPlugInSingleRowFunction("generateJson", typeof(EPLInsertIntoTransposeStream), "LocalGenerateJson"); configuration.Compiler.AddPlugInSingleRowFunction("custom", typeof(SupportStaticMethodLib), "MakeSupportBean"); configuration.Compiler.AddPlugInSingleRowFunction("customOne", typeof(SupportStaticMethodLib), "MakeSupportBean"); configuration.Compiler.AddPlugInSingleRowFunction("customTwo", typeof(SupportStaticMethodLib), "MakeSupportBeanNumeric"); }
public void Run(RegressionEnvironment env) { /* * // Bean * BiConsumer<EventType, NullableObject<int?>> bean = ( * type, * nullable) => { * if (nullable == null) { * env.SendEventBean(new LocalEvent()); * } * else if (nullable.Value == null) { * env.SendEventBean(new LocalEventSubA(null)); * } * else { * var array = new LocalInnerEvent[nullable.Value.Value]; * for (var i = 0; i < array.Length; i++) { * array[i] = new LocalInnerEvent(); * } * * env.SendEventBean(new LocalEventSubA(array)); * } * }; * var beanepl = * $"@public @buseventtype create schema LocalInnerEvent as {typeof(LocalInnerEvent).MaskTypeName()};\n" + * $"@public @buseventtype create schema LocalEvent as {typeof(LocalEvent).MaskTypeName()};\n" + * "@public @buseventtype create schema LocalEventSubA as " + * typeof(LocalEventSubA).MaskTypeName() + * ";\n"; * RunAssertion(env, beanepl, bean); * * // Map * BiConsumer<EventType, NullableObject<int?>> map = ( * type, * nullable) => { * if (nullable == null) { * env.SendEventMap(EmptyDictionary<string, object>.Instance, "LocalEvent"); * } * else if (nullable.Value == null) { * env.SendEventMap(Collections.SingletonDataMap("Array", null), "LocalEvent"); * } * else { * var array = new IDictionary<string, object>[nullable.Value.Value]; * for (var i = 0; i < array.Length; i++) { * array[i] = new Dictionary<string, object>(); * } * * env.SendEventMap(Collections.SingletonDataMap("Array", array), "LocalEvent"); * } * }; * var mapepl = * "@public @buseventtype create schema LocalInnerEvent();\n" + * "@public @buseventtype create schema LocalEvent(Array LocalInnerEvent[]);\n"; * RunAssertion(env, mapepl, map); * * // Object-array * var oaepl = * "@public @buseventtype create objectarray schema LocalEvent();\n" + * "@public @buseventtype create objectarray schema LocalEventSubA (Array string[]) inherits LocalEvent;\n"; * RunAssertion(env, oaepl, null); */ // Json BiConsumer <EventType, NullableObject <int?> > json = ( type, nullable) => { if (nullable == null) { env.SendEventJson("{}", "LocalEvent"); } else if (nullable.Value == null) { env.SendEventJson(new JObject(new JProperty("Array", null)).ToString(), "LocalEvent"); } else { var @event = new JObject(); var array = new JArray(); @event.Add("Array", array); for (var i = 0; i < nullable.Value; i++) { array.Add(new JObject()); } env.SendEventJson(@event.ToString(), "LocalEvent"); } }; var epl = "@public @buseventtype create json schema LocalInnerEvent();\n" + "@public @buseventtype create json schema LocalEvent(Array LocalInnerEvent[]);\n"; RunAssertion(env, epl, json); // Json-Class-Provided var eplJsonProvided = $"@JsonSchema(ClassName='{typeof(MyLocalJsonProvided).MaskTypeName()}') " + "@public @buseventtype create json schema LocalEvent();\n"; RunAssertion(env, eplJsonProvided, json); // Avro BiConsumer <EventType, NullableObject <int?> > avro = ( type, nullable) => { var inner = SchemaBuilder.Record("inner"); var schema = SchemaBuilder.Record("name", TypeBuilder.Field("Array", TypeBuilder.Array(inner))); GenericRecord @event; if (nullable == null) { // no action @event = new GenericRecord(SupportAvroUtil.GetAvroSchema(type).AsRecordSchema()); } else if (nullable.Value == null) { @event = new GenericRecord(schema); } else { @event = new GenericRecord(schema); ICollection <GenericRecord> inners = new List <GenericRecord>(); for (var i = 0; i < nullable.Value; i++) { inners.Add(new GenericRecord(inner)); } @event.Put("Array", inners); } env.SendEventAvro(@event, "LocalEvent"); }; var avroepl = "@public @buseventtype create avro schema LocalInnerEvent();\n" + "@public @buseventtype create avro schema LocalEvent(Array LocalInnerEvent[]);\n"; RunAssertion(env, avroepl, avro); }
private void RunAssertionNamedWindowSetMapProps(EventRepresentationChoice eventRepresentationEnum) { // test named-window update _epService.EPAdministrator.Configuration.AddEventType(typeof(SupportBean)); _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyNWInfraType(simple string, myarray int[], mymap com.espertech.esper.compat.collections.StringMap)"); EPStatement stmtWin = _epService.EPAdministrator.CreateEPL("create window MyWindow#keepall as MyNWInfraType"); _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " insert into MyWindow select * from MyNWInfraType"); if (eventRepresentationEnum.IsObjectArrayEvent()) { _epService.EPRuntime.SendEvent(new Object[] { null, new int[10], new Dictionary <string, Object>() }, "MyNWInfraType"); } else if (eventRepresentationEnum.IsMapEvent()) { _epService.EPRuntime.SendEvent(MakeMapEvent(new Dictionary <string, object>(), new int[10]), "MyNWInfraType"); } else if (eventRepresentationEnum.IsAvroEvent()) { GenericRecord theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "MyNWInfraType").AsRecordSchema()); theEvent.Put("myarray", Collections.List(0, 0, 0, 0, 0)); theEvent.Put("mymap", new Dictionary <string, object>()); _epService.EPRuntime.SendEventAvro(theEvent, "MyNWInfraType"); } else { Assert.Fail(); } _epService.EPAdministrator.CreateEPL("on SupportBean update MyWindow set simple='A', mymap('abc') = intPrimitive, myarray[2] = intPrimitive"); _epService.EPRuntime.SendEvent(new SupportBean("E1", 10)); EPAssertionUtil.AssertPropsPerRow(stmtWin.GetEnumerator(), "simple,mymap('abc'),myarray[2]".Split(','), new Object[][] { new Object[] { "A", 10, 10 } }); // test null and array too small if (eventRepresentationEnum.IsObjectArrayEvent()) { _epService.EPRuntime.SendEvent(new Object[] { null, new int[2], null }, "MyNWInfraType"); } else if (eventRepresentationEnum.IsMapEvent()) { _epService.EPRuntime.SendEvent(MakeMapEvent(null, new int[2]), "MyNWInfraType"); } else if (eventRepresentationEnum.IsAvroEvent()) { GenericRecord theEvent = new GenericRecord( SchemaBuilder.Record( "name", TypeBuilder.OptionalString("simple"), TypeBuilder.Field("myarray", TypeBuilder.Array(TypeBuilder.Long())), TypeBuilder.Field("mymap", TypeBuilder.Map(TypeBuilder.String())))); theEvent.Put("myarray", Collections.List(0, 0)); theEvent.Put("mymap", null); _epService.EPRuntime.SendEventAvro(theEvent, "MyNWInfraType"); } else { Assert.Fail(); } _epService.EPRuntime.SendEvent(new SupportBean("E2", 20)); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtWin.GetEnumerator(), "simple,mymap('abc'),myarray[2]".Split(','), new Object[][] { new Object[] { "A", 20, 20 }, new Object[] { "A", null, null } }); _epService.Initialize(); }