kbuci commented on code in PR #18958:
URL: https://github.com/apache/hudi/pull/18958#discussion_r3400995115
##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/utils/TestRowDataToAvroConverters.java:
##########
@@ -81,4 +85,48 @@ void testRowDataToAvroStringToRowDataWithUtcTimezone()
throws JsonProcessingExce
Assertions.assertEquals("2021-03-30 08:44:29",
formatter.format(LocalDateTime.ofInstant(Instant.ofEpochMilli((Long)
avroRecord.get(0)), ZoneId.of("UTC+1"))));
Assertions.assertEquals("2021-03-30 15:44:29",
formatter.format(LocalDateTime.ofInstant(Instant.ofEpochMilli((Long)
avroRecord.get(0)), ZoneId.of("Asia/Shanghai"))));
}
+
+ @Test
+ void testRowDataToAvroBlobTypeFieldWritesEnumSymbol() {
+ // Flink models the BLOB `type` discriminator as STRING, but its Avro
encoding is an ENUM
+ // (blob_storage_type). The converter must emit a GenericData.EnumSymbol,
not a plain Utf8,
+ // otherwise Avro log-block writes (MOR) fail with "value OUT_OF_LINE (a
Utf8) is not a
+ // blob_storage_type".
+ DataType blobRow = DataTypes.ROW(
+ DataTypes.FIELD(HoodieSchema.Blob.TYPE, DataTypes.STRING().notNull()),
+ DataTypes.FIELD(HoodieSchema.Blob.INLINE_DATA_FIELD,
DataTypes.BYTES().nullable()),
+ DataTypes.FIELD(HoodieSchema.Blob.EXTERNAL_REFERENCE, DataTypes.ROW(
+ DataTypes.FIELD(HoodieSchema.Blob.EXTERNAL_REFERENCE_PATH,
DataTypes.STRING().notNull()),
+ DataTypes.FIELD(HoodieSchema.Blob.EXTERNAL_REFERENCE_OFFSET,
DataTypes.BIGINT().nullable()),
+ DataTypes.FIELD(HoodieSchema.Blob.EXTERNAL_REFERENCE_LENGTH,
DataTypes.BIGINT().nullable()),
+ DataTypes.FIELD(HoodieSchema.Blob.EXTERNAL_REFERENCE_IS_MANAGED,
DataTypes.BOOLEAN().notNull())
+ ).nullable()));
+ RowType rowType = (RowType) DataTypes.ROW(DataTypes.FIELD("blob_col",
blobRow)).getLogicalType();
+
+ GenericRowData reference = new GenericRowData(4);
+ reference.setField(0, StringData.fromString("file1.bin"));
+ reference.setField(1, 0L);
+ reference.setField(2, 100L);
+ reference.setField(3, false);
+
+ GenericRowData blob = new GenericRowData(3);
+ blob.setField(0, StringData.fromString(HoodieSchema.Blob.OUT_OF_LINE));
+ blob.setField(1, null);
+ blob.setField(2, reference);
+
+ GenericRowData top = new GenericRowData(1);
+ top.setField(0, blob);
+
+ RowDataToAvroConverters.RowDataToAvroConverter converter =
+ RowDataToAvroConverters.createConverter(rowType);
+ GenericRecord avroRecord =
+ (GenericRecord)
converter.convert(HoodieSchemaConverter.convertToSchema(rowType), top);
Review Comment:
Sure, I added a unit test that builds a BLOB-shaped Flink RowType but
supplies a plain HoodieSchema RECORD where the type field is STRING (not ENUM).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]