use of org.apache.flink.formats.json.maxwell.MaxwellJsonDecodingFormat.ReadableMetadata in project flink by apache.
the class MaxwellJsonSerDerTest method testDeserializationWithMetadata.
@Test
public void testDeserializationWithMetadata() throws Exception {
// we only read the first line for keeping the test simple
final String firstLine = readLines("maxwell-data.txt").get(0);
final List<ReadableMetadata> requestedMetadata = Arrays.asList(ReadableMetadata.values());
final DataType producedDataType = DataTypeUtils.appendRowFields(PHYSICAL_DATA_TYPE, requestedMetadata.stream().map(m -> DataTypes.FIELD(m.key, m.dataType)).collect(Collectors.toList()));
final MaxwellJsonDeserializationSchema deserializationSchema = new MaxwellJsonDeserializationSchema(PHYSICAL_DATA_TYPE, requestedMetadata, InternalTypeInfo.of(producedDataType.getLogicalType()), false, TimestampFormat.ISO_8601);
final SimpleCollector collector = new SimpleCollector();
deserializationSchema.deserialize(firstLine.getBytes(StandardCharsets.UTF_8), collector);
assertEquals(1, collector.list.size());
Consumer<RowData> consumer = row -> {
assertThat(row.getInt(0), equalTo(101));
assertThat(row.getString(1).toString(), equalTo("scooter"));
assertThat(row.getString(2).toString(), equalTo("Small 2-wheel scooter"));
assertThat(row.getFloat(3), equalTo(3.14f));
assertThat(row.getString(4).toString(), equalTo("test"));
assertThat(row.getString(5).toString(), equalTo("product"));
assertThat(row.getArray(6).getString(0).toString(), equalTo("id"));
assertThat(row.getTimestamp(7, 3).getMillisecond(), equalTo(1596684883000L));
};
consumer.accept(collector.list.get(0));
}
Aggregations