use of org.apache.samza.sql.avro.schemas.StreetNumRecord in project samza by apache.
the class TestAvroRelConversion method testNestedRecordConversion.
@Test
public void testNestedRecordConversion() throws IOException {
GenericData.Record record = new GenericData.Record(Profile.SCHEMA$);
record.put("id", 1);
record.put("name", "name1");
record.put("companyId", 0);
GenericData.Record addressRecord = new GenericData.Record(AddressRecord.SCHEMA$);
addressRecord.put("zip", 90000);
GenericData.Record streetNumRecord = new GenericData.Record(StreetNumRecord.SCHEMA$);
streetNumRecord.put("number", 1200);
addressRecord.put("streetnum", streetNumRecord);
record.put("address", addressRecord);
record.put("selfEmployed", "True");
GenericData.Record phoneNumberRecordH = new GenericData.Record(PhoneNumber.SCHEMA$);
phoneNumberRecordH.put("kind", Kind.Home);
phoneNumberRecordH.put("number", "111-111-1111");
GenericData.Record phoneNumberRecordC = new GenericData.Record(PhoneNumber.SCHEMA$);
phoneNumberRecordC.put("kind", Kind.Cell);
phoneNumberRecordC.put("number", "111-111-1112");
List<GenericData.Record> phoneNumbers = new ArrayList<>();
phoneNumbers.add(phoneNumberRecordH);
phoneNumbers.add(phoneNumberRecordC);
record.put("phoneNumbers", phoneNumbers);
GenericData.Record simpleRecord1 = new GenericData.Record(SimpleRecord.SCHEMA$);
simpleRecord1.put("id", 1);
simpleRecord1.put("name", "name1");
GenericData.Record simpleRecord2 = new GenericData.Record(SimpleRecord.SCHEMA$);
simpleRecord2.put("id", 2);
simpleRecord2.put("name", "name2");
HashMap<String, IndexedRecord> mapValues = new HashMap<>();
mapValues.put("key1", simpleRecord1);
mapValues.put("key2", simpleRecord2);
record.put("mapValues", mapValues);
SamzaSqlRelMessage relMessage = nestedRecordAvroRelConverter.convertToRelMessage(new KV<>("key", record));
LOG.info(relMessage.toString());
KV<Object, Object> samzaMessage = nestedRecordAvroRelConverter.convertToSamzaMessage(relMessage);
GenericRecord recordPostConversion = (GenericRecord) samzaMessage.getValue();
for (Schema.Field field : Profile.SCHEMA$.getFields()) {
// equals() on GenericRecord does the nested record equality check as well.
Assert.assertEquals(record.get(field.name()), recordPostConversion.get(field.name()));
}
}
Aggregations