use of org.apache.flink.table.data.RowData in project flink by apache.
the class RegistryAvroFormatFactoryTest method testDeserializationSchemaWithOptionalProperties.
@Test
public void testDeserializationSchemaWithOptionalProperties() {
final AvroRowDataDeserializationSchema expectedDeser = new AvroRowDataDeserializationSchema(ConfluentRegistryAvroDeserializationSchema.forGeneric(AvroSchemaConverter.convertToSchema(ROW_TYPE), REGISTRY_URL, EXPECTED_OPTIONAL_PROPERTIES), AvroToRowDataConverters.createRowConverter(ROW_TYPE), InternalTypeInfo.of(ROW_TYPE));
final DynamicTableSource actualSource = createTableSource(SCHEMA, getOptionalProperties());
assertThat(actualSource, instanceOf(TestDynamicTableFactory.DynamicTableSourceMock.class));
TestDynamicTableFactory.DynamicTableSourceMock scanSourceMock = (TestDynamicTableFactory.DynamicTableSourceMock) actualSource;
DeserializationSchema<RowData> actualDeser = scanSourceMock.valueFormat.createRuntimeDecoder(ScanRuntimeProviderContext.INSTANCE, SCHEMA.toPhysicalRowDataType());
assertEquals(expectedDeser, actualDeser);
}
use of org.apache.flink.table.data.RowData 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.data.RowData in project flink by apache.
the class AvroBulkFormatTest method testRestoreReader.
@Test
public void testRestoreReader() throws IOException {
AvroBulkFormatTestUtils.TestingAvroBulkFormat bulkFormat = new AvroBulkFormatTestUtils.TestingAvroBulkFormat();
long splitLength = tmpFile.length() / 3;
String splitId = UUID.randomUUID().toString();
FileSourceSplit split = new FileSourceSplit(splitId, new Path(tmpFile.toString()), splitLength * 2, tmpFile.length());
BulkFormat.Reader<RowData> reader = bulkFormat.createReader(new Configuration(), split);
long offset1 = assertBatch(reader, new BatchInfo(3, 5));
assertBatch(reader, new BatchInfo(5, 6));
assertThat(reader.readBatch()).isNull();
reader.close();
split = new FileSourceSplit(splitId, new Path(tmpFile.toString()), splitLength * 2, tmpFile.length(), StringUtils.EMPTY_STRING_ARRAY, new CheckpointedPosition(offset1, 1));
reader = bulkFormat.restoreReader(new Configuration(), split);
long offset2 = assertBatch(reader, new BatchInfo(3, 5), 1);
assertBatch(reader, new BatchInfo(5, 6));
assertThat(reader.readBatch()).isNull();
reader.close();
assertThat(offset2).isEqualTo(offset1);
}
use of org.apache.flink.table.data.RowData in project flink by apache.
the class AvroBulkFormatTest method assertSplit.
private void assertSplit(AvroBulkFormatTestUtils.TestingAvroBulkFormat bulkFormat, List<SplitInfo> splitInfos) throws IOException {
for (SplitInfo splitInfo : splitInfos) {
FileSourceSplit split = new FileSourceSplit(UUID.randomUUID().toString(), new Path(tmpFile.toString()), splitInfo.start, splitInfo.end - splitInfo.start);
BulkFormat.Reader<RowData> reader = bulkFormat.createReader(new Configuration(), split);
List<Long> offsets = new ArrayList<>();
for (BatchInfo batch : splitInfo.batches) {
offsets.add(assertBatch(reader, batch));
}
assertThat(reader.readBatch()).isNull();
for (int j = 1; j < offsets.size(); j++) {
assertThat(offsets.get(j - 1) < offsets.get(j)).isTrue();
}
reader.close();
}
}
use of org.apache.flink.table.data.RowData 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