Search in sources :

Example 1 with ComplexRecord

use of org.apache.samza.sql.avro.schemas.ComplexRecord in project samza by apache.

the class TestAvroRelConversion method testComplexRecordConversion.

@Test
public void testComplexRecordConversion() throws IOException {
    GenericData.Record record = new GenericData.Record(ComplexRecord.SCHEMA$);
    record.put("id", id);
    record.put("bool_value", boolValue);
    record.put("double_value", doubleValue);
    record.put("float_value0", floatValue);
    record.put("string_value", testStrValue);
    record.put("bytes_value", testBytes);
    record.put("fixed_value", fixedBytes);
    record.put("long_value", longValue);
    record.put("array_values", arrayValue);
    record.put("map_values", mapValue);
    record.put("union_value", testStrValue);
    ComplexRecord complexRecord = new ComplexRecord();
    complexRecord.id = id;
    complexRecord.bool_value = boolValue;
    complexRecord.double_value = doubleValue;
    complexRecord.float_value0 = floatValue;
    complexRecord.string_value = testStrValue;
    complexRecord.bytes_value = testBytes;
    complexRecord.fixed_value = fixedBytes;
    complexRecord.long_value = longValue;
    complexRecord.array_values = new ArrayList<>();
    complexRecord.array_values.addAll(arrayValue);
    complexRecord.map_values = new HashMap<>();
    complexRecord.map_values.putAll(mapValue);
    complexRecord.union_value = testStrValue;
    byte[] serializedData = bytesFromGenericRecord(record);
    validateAvroSerializedData(serializedData, testStrValue);
    serializedData = encodeAvroSpecificRecord(ComplexRecord.class, complexRecord);
    validateAvroSerializedData(serializedData, testStrValue);
}
Also used : ComplexRecord(org.apache.samza.sql.avro.schemas.ComplexRecord) StreetNumRecord(org.apache.samza.sql.avro.schemas.StreetNumRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) SimpleRecord(org.apache.samza.sql.avro.schemas.SimpleRecord) AddressRecord(org.apache.samza.sql.avro.schemas.AddressRecord) GenericData(org.apache.avro.generic.GenericData) ComplexRecord(org.apache.samza.sql.avro.schemas.ComplexRecord) Test(org.junit.Test)

Aggregations

GenericData (org.apache.avro.generic.GenericData)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 AddressRecord (org.apache.samza.sql.avro.schemas.AddressRecord)1 ComplexRecord (org.apache.samza.sql.avro.schemas.ComplexRecord)1 SimpleRecord (org.apache.samza.sql.avro.schemas.SimpleRecord)1 StreetNumRecord (org.apache.samza.sql.avro.schemas.StreetNumRecord)1 Test (org.junit.Test)1