@Test public void shouldDeserializeMapToMap() { shouldDeserializeTypeCorrectly( org.apache.avro.SchemaBuilder.map().values().intType(), ImmutableMap.of("one", 1, "two", 2, "three", 3), SchemaBuilder.map( Schema.OPTIONAL_STRING_SCHEMA, Schema.OPTIONAL_INT32_SCHEMA ).optional().build() ); }
@Test public void testMap() { Schema intSchema = Schema.create(Schema.Type.INT); Schema expected = Schema.createMap(intSchema); Schema schema1 = SchemaBuilder.map().values().intType(); Assert.assertEquals(expected, schema1); Schema schema2 = SchemaBuilder.map().values(intSchema); Assert.assertEquals(expected, schema2); Schema schema3 = SchemaBuilder.map().prop("p", "v") .values().type("int"); expected.addProp("p", "v"); Assert.assertEquals(expected, schema3); }
public void run(RegressionEnvironment env) { String epl = "@name('s0') " + EventRepresentationChoice.AVRO.getAnnotationText() + " select 1 as myInt," + "{1L, 2L} as myLongArray," + EPLInsertIntoPopulateCreateStreamAvro.class.getName() + ".makeByteArray() as myByteArray, " + EPLInsertIntoPopulateCreateStreamAvro.class.getName() + ".makeMapStringString() as myMap " + "from SupportBean"; env.compileDeploy(epl).addListener("s0"); env.sendEventBean(new SupportBean()); EventBean event = env.listener("s0").assertOneGetNewAndReset(); String json = SupportAvroUtil.avroToJson(event); System.out.println(json); assertEquals(1, event.get("myInt")); EPAssertionUtil.assertEqualsExactOrder(new Long[]{1L, 2L}, ((Collection) event.get("myLongArray")).toArray()); assertTrue(Arrays.equals(new byte[]{1, 2, 3}, ((ByteBuffer) event.get("myByteArray")).array())); assertEquals("{k1=v1}", ((Map) event.get("myMap")).toString()); Schema designSchema = record("name").fields() .requiredInt("myInt") .name("myLongArray").type(array().items(unionOf().nullType().and().longType().endUnion())).noDefault() .name("myByteArray").type("bytes").noDefault() .name("myMap").type(map().values().stringBuilder().prop(AvroConstant.PROP_JAVA_STRING_KEY, AvroConstant.PROP_JAVA_STRING_VALUE).endString()).noDefault() .endRecord(); Schema assembledSchema = ((AvroEventType) event.getEventType()).getSchemaAvro(); String compareMsg = SupportAvroUtil.compareSchemas(designSchema, assembledSchema); assertNull(compareMsg, compareMsg); env.undeployAll(); } }
.optionalString("simple") .name("myarray").type(array().items().longType()).noDefault() .name("mymap").type(map().values().stringType()).noDefault() .endRecord()); event.put("myarray", Arrays.asList(0, 0));
@Test public void testMapOfStringToBytes() { Type map = Types.MapType.ofRequired(33, 34, Types.StringType.get(), Types.BinaryType.get()); Schema schema = addKeyId(33, addValueId(34, SchemaBuilder.map().values( Schema.create(Schema.Type.BYTES)))); Assert.assertEquals("Avro schema to map", map, AvroSchemaUtil.convert(schema)); Assert.assertEquals("Map to Avro schema", schema, AvroSchemaUtil.convert(map)); }
@Test public void testMapOfStringToStructs() { Type map = Types.MapType.ofRequired(33, 34, Types.StringType.get(), Types.StructType.of( required(35, "a", Types.IntegerType.get()), optional(36, "b", Types.IntegerType.get()) )); Schema schema = addKeyId(33, addValueId(34, SchemaBuilder.map().values( record("r34", requiredField(35, "a", Schema.create(Schema.Type.INT)), optionalField(36, "b", Schema.create(Schema.Type.INT)))))); Assert.assertEquals("Avro schema to map", map, AvroSchemaUtil.convert(schema)); Assert.assertEquals("Map to Avro schema", schema, AvroSchemaUtil.convert(map)); }