cshuo commented on code in PR #18958:
URL: https://github.com/apache/hudi/pull/18958#discussion_r3402400583
##########
hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/util/RowDataToAvroConverters.java:
##########
@@ -232,7 +240,8 @@ public Object convert(HoodieSchema schema, Object object) {
converter = createArrayConverter((ArrayType) type, utcTimezone);
break;
case ROW:
- converter = createRowConverter((RowType) type, utcTimezone);
+ RowType rowType = (RowType) type;
Review Comment:
unnecessary change.
##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/table/ITTestBlobWrite.java:
##########
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.table;
+
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.schema.HoodieSchema;
+import org.apache.hudi.common.schema.HoodieSchemaField;
+import org.apache.hudi.common.schema.HoodieSchemaUtils;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.TableSchemaResolver;
+import org.apache.hudi.util.HoodieSchemaConverter;
+import org.apache.hudi.util.StreamerUtil;
+import org.apache.hudi.utils.FlinkMiniCluster;
+
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.TableResult;
+import org.apache.flink.table.api.config.ExecutionConfigOptions;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.CollectionUtil;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+
+import java.io.File;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * IT case for writing out-of-line (OOL) BLOB columns through the Flink writer
and reading them back.
+ *
+ * <p>Verifies that the Hudi {@link HoodieSchema.Blob} structure round-trips
through the Flink
+ * write/read pipeline (both COW and MOR), that updates land through the MOR
Avro log path, and that
+ * the stored table schema keeps the BLOB logical type instead of degrading
the column to a generic
+ * Flink/Avro record.
+ */
+@ExtendWith(FlinkMiniCluster.class)
+public class ITTestBlobWrite {
+
+ @TempDir
+ File tempFile;
+
+ private static final String BLOB_COLUMN = "blob_col";
+
+ private static final String BLOB_COLUMN_DDL =
+ " " + BLOB_COLUMN + " ROW<\n"
+ + " `type` STRING NOT NULL,\n"
+ + " `data` BYTES,\n"
+ + " `reference` ROW<\n"
+ + " external_path STRING NOT NULL,\n"
+ + " `offset` BIGINT,\n"
+ + " `length` BIGINT,\n"
+ + " managed BOOLEAN NOT NULL\n"
+ + " >\n"
+ + " >,\n";
+
+ /**
+ * Regression for {@code HoodieSchemaConverter#isBlobStructure}: Flink SQL
{@code CREATE TABLE}
+ * may declare nested {@code ROW} fields as {@code NOT NULL}, but
+ * {@link ResolvedSchema#toPhysicalRowDataType()} does not always preserve
those constraints in
+ * the {@link RowType}. Schema inference must still recognize the BLOB shape
(same path as
+ * {@code HoodieTableFactory#inferAvroSchema}), otherwise {@code blob_col}
would degrade to a
+ * generic RECORD in the committed Hoodie schema.
+ */
+ @Test
+ public void testFlinkSqlDdlPhysicalRowTypeStillMapsToHoodieBlob() {
Review Comment:
This test is a unit test, can we move it to `TestHoodieSchemaConverter`
##########
hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/util/RowDataToAvroConverters.java:
##########
@@ -148,6 +148,14 @@ public Object convert(HoodieSchema schema, Object object) {
@Override
public Object convert(HoodieSchema schema, Object object) {
+ // The BLOB `type` discriminator is a STRING in Flink but an
ENUM in Avro.
+ // Detect that at call time from the HoodieSchema so the
converter stays
+ // reusable across any row shape — not hard-wired by Flink row
structure alone.
+ if (schema.getNonNullType().getType() ==
HoodieSchemaType.ENUM) {
+ HoodieSchema enumSchema = schema.getNonNullType();
+ return new GenericData.EnumSymbol(
+ enumSchema.toAvroSchema(), ((BinaryStringData)
object).toString());
Review Comment:
Cast to `BinaryStringData` is unnecessary.
--
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]