use of org.apache.flink.table.types.logical.RowType in project flink by apache.
the class RegistryAvroRowDataSeDeSchemaTest method testRowDataWriteReadWithSchema.
private void testRowDataWriteReadWithSchema(Schema schema) throws Exception {
DataType dataType = AvroSchemaConverter.convertToDataType(schema.toString());
RowType rowType = (RowType) dataType.getLogicalType();
AvroRowDataSerializationSchema serializer = getSerializationSchema(rowType, schema);
Schema writeSchema = AvroSchemaConverter.convertToSchema(dataType.getLogicalType());
AvroRowDataDeserializationSchema deserializer = getDeserializationSchema(rowType, writeSchema);
serializer.open(null);
deserializer.open(null);
assertNull(deserializer.deserialize(null));
RowData oriData = address2RowData(address);
byte[] serialized = serializer.serialize(oriData);
RowData rowData = deserializer.deserialize(serialized);
assertThat(rowData.getArity(), equalTo(schema.getFields().size()));
assertEquals(address.getNum(), rowData.getInt(0));
assertEquals(address.getStreet(), rowData.getString(1).toString());
if (schema != ADDRESS_SCHEMA_COMPATIBLE) {
assertEquals(address.getCity(), rowData.getString(2).toString());
assertEquals(address.getState(), rowData.getString(3).toString());
assertEquals(address.getZip(), rowData.getString(4).toString());
}
}
use of org.apache.flink.table.types.logical.RowType in project flink by apache.
the class RegistryAvroRowDataSeDeSchemaTest method testRowDataReadWithNonRegistryAvro.
@Test
public void testRowDataReadWithNonRegistryAvro() throws Exception {
DataType dataType = AvroSchemaConverter.convertToDataType(ADDRESS_SCHEMA.toString());
RowType rowType = (RowType) dataType.getLogicalType();
AvroRowDataDeserializationSchema deserializer = getDeserializationSchema(rowType, ADDRESS_SCHEMA);
deserializer.open(null);
client.register(SUBJECT, ADDRESS_SCHEMA);
byte[] oriBytes = writeRecord(address, ADDRESS_SCHEMA);
expectedEx.expect(IOException.class);
expectedEx.expect(containsCause(new IOException("Unknown data format. Magic number does not match")));
deserializer.deserialize(oriBytes);
}
use of org.apache.flink.table.types.logical.RowType in project flink by apache.
the class AvroFormatFactory method createDecodingFormat.
@Override
public DecodingFormat<DeserializationSchema<RowData>> createDecodingFormat(DynamicTableFactory.Context context, ReadableConfig formatOptions) {
FactoryUtil.validateFactoryOptions(this, formatOptions);
return new ProjectableDecodingFormat<DeserializationSchema<RowData>>() {
@Override
public DeserializationSchema<RowData> createRuntimeDecoder(DynamicTableSource.Context context, DataType physicalDataType, int[][] projections) {
final DataType producedDataType = Projection.of(projections).project(physicalDataType);
final RowType rowType = (RowType) producedDataType.getLogicalType();
final TypeInformation<RowData> rowDataTypeInfo = context.createTypeInformation(producedDataType);
return new AvroRowDataDeserializationSchema(rowType, rowDataTypeInfo);
}
@Override
public ChangelogMode getChangelogMode() {
return ChangelogMode.insertOnly();
}
};
}
use of org.apache.flink.table.types.logical.RowType in project flink by apache.
the class DebeziumAvroSerDeSchemaTest method testDeserialization.
public List<String> testDeserialization(String dataPath) throws Exception {
RowType rowTypeDe = DebeziumAvroDeserializationSchema.createDebeziumAvroRowType(fromLogicalToDataType(rowType));
client.register(SUBJECT, DEBEZIUM_SCHEMA_COMPATIBLE_TEST, 1, 81);
DebeziumAvroDeserializationSchema dbzDeserializer = new DebeziumAvroDeserializationSchema(InternalTypeInfo.of(rowType), getDeserializationSchema(rowTypeDe));
dbzDeserializer.open(mock(DeserializationSchema.InitializationContext.class));
SimpleCollector collector = new SimpleCollector();
dbzDeserializer.deserialize(readBytesFromFile(dataPath), collector);
return collector.list.stream().map(Object::toString).collect(Collectors.toList());
}
use of org.apache.flink.table.types.logical.RowType in project flink by apache.
the class AvroRowDataDeSerializationSchemaTest method createDeserializationSchema.
private AvroRowDataDeserializationSchema createDeserializationSchema(DataType dataType) throws Exception {
final RowType rowType = (RowType) dataType.getLogicalType();
final TypeInformation<RowData> typeInfo = InternalTypeInfo.of(rowType);
AvroRowDataDeserializationSchema deserializationSchema = new AvroRowDataDeserializationSchema(rowType, typeInfo);
deserializationSchema.open(null);
return deserializationSchema;
}
Aggregations