use of org.apache.samza.sql.serializers.SamzaSqlRelMessageSerdeFactory.SamzaSqlRelMessageSerde in project samza by apache.
the class TestSamzaSqlRelMessageSerde method testNestedRecordConversion.
@Test
public void testNestedRecordConversion() {
Map<String, String> props = new HashMap<>();
SystemStream ss1 = new SystemStream("test", "nestedRecord");
props.put(String.format(ConfigBasedAvroRelSchemaProviderFactory.CFG_SOURCE_SCHEMA, ss1.getSystem(), ss1.getStream()), Profile.SCHEMA$.toString());
ConfigBasedAvroRelSchemaProviderFactory factory = new ConfigBasedAvroRelSchemaProviderFactory();
AvroRelSchemaProvider nestedRecordSchemaProvider = (AvroRelSchemaProvider) factory.create(ss1, new MapConfig(props));
AvroRelConverter nestedRecordAvroRelConverter = new AvroRelConverter(ss1, nestedRecordSchemaProvider, new MapConfig());
Pair<SamzaSqlRelMessage, GenericData.Record> messageRecordPair = createNestedSamzaSqlRelMessage(nestedRecordAvroRelConverter);
SamzaSqlRelMessageSerde serde = (SamzaSqlRelMessageSerde) new SamzaSqlRelMessageSerdeFactory().getSerde(null, null);
SamzaSqlRelMessage resultMsg = serde.fromBytes(serde.toBytes(messageRecordPair.getKey()));
KV<Object, Object> samzaMessage = nestedRecordAvroRelConverter.convertToSamzaMessage(resultMsg);
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(messageRecordPair.getValue().get(field.name()), recordPostConversion.get(field.name()));
}
}
use of org.apache.samza.sql.serializers.SamzaSqlRelMessageSerdeFactory.SamzaSqlRelMessageSerde in project samza by apache.
the class TestSamzaSqlRelMessageSerde method testWithDifferentFields.
@Test
public void testWithDifferentFields() {
SamzaSqlRelMessage message = new SamzaSqlRelMessage(names, values, new SamzaSqlRelMsgMetadata(0L, 0L));
SamzaSqlRelMessageSerde serde = (SamzaSqlRelMessageSerde) new SamzaSqlRelMessageSerdeFactory().getSerde(null, null);
SamzaSqlRelMessage resultMsg = serde.fromBytes(serde.toBytes(message));
Assert.assertEquals(names, resultMsg.getSamzaSqlRelRecord().getFieldNames());
Assert.assertEquals(values, resultMsg.getSamzaSqlRelRecord().getFieldValues());
}
Aggregations