use of org.apache.flink.formats.json.ogg.OggJsonDecodingFormat.ReadableMetadata in project flink by apache.
the class OggJsonSerDeSchemaTest method testDeserializationWithMetadata.
public void testDeserializationWithMetadata(String resourceFile) throws Exception {
// we only read the first line for keeping the test simple
final String firstLine = readLines(resourceFile).get(0);
final List<ReadableMetadata> requestedMetadata = Arrays.asList(ReadableMetadata.values());
final DataType producedDataTypes = DataTypeUtils.appendRowFields(PHYSICAL_DATA_TYPE, requestedMetadata.stream().map(m -> DataTypes.FIELD(m.key, m.dataType)).collect(Collectors.toList()));
final OggJsonDeserializationSchema deserializationSchema = new OggJsonDeserializationSchema(PHYSICAL_DATA_TYPE, requestedMetadata, InternalTypeInfo.of(producedDataTypes.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 -> {
assertEquals(101, row.getInt(0));
assertEquals("scooter", row.getString(1).toString());
assertEquals("Small 2-wheel scooter", row.getString(2).toString());
assertEquals(3.140000104904175, row.getFloat(3), 1e-15);
assertEquals("OGG.TBL_TEST", row.getString(4).toString());
assertEquals("id", row.getArray(5).getString(0).toString());
assertEquals(1589377175766L, row.getTimestamp(6, 6).getMillisecond());
assertEquals(1589384406000L, row.getTimestamp(7, 6).getMillisecond());
};
consumer.accept(collector.list.get(0));
}
Aggregations