hudi-agent commented on code in PR #18958:
URL: https://github.com/apache/hudi/pull/18958#discussion_r3408524182


##########
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) {

Review Comment:
   🤖 nit: `schema.getNonNullType()` is called twice — once in the condition and 
once to assign `enumSchema`. Could you hoist the assignment above the `if` so 
the result is reused? e.g. `HoodieSchema nonNullSchema = 
schema.getNonNullType(); if (nonNullSchema.getType() == HoodieSchemaType.ENUM) 
{ return new GenericData.EnumSymbol(nonNullSchema.toAvroSchema(), ...); }`
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
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() {
+    TableEnvironment tableEnv = batchEnv();
+    final String probeTable = "flink_blob_ddl_probe";
+    String createProbeDdl =
+        "CREATE TABLE "
+            + probeTable
+            + " (\n"
+            + "  id BIGINT,\n"
+            + "  name STRING,\n"
+            + BLOB_COLUMN_DDL
+            + "  ts BIGINT\n"
+            + ") WITH ('connector'='blackhole')";
+    tableEnv.executeSql(createProbeDdl);
+
+    ResolvedSchema resolved = tableEnv.from(probeTable).getResolvedSchema();
+    RowType physical = (RowType) 
resolved.toPhysicalRowDataType().getLogicalType();
+    int blobIdx = physical.getFieldNames().indexOf(BLOB_COLUMN);
+    RowType blobPhysical = (RowType) physical.getTypeAt(blobIdx);
+    // DDL uses NOT NULL on nested BLOB ROW fields where the canonical Hoodie 
BLOB shape is

Review Comment:
   🤖 nit: `blobPhysical` is declared here but never referenced again — 
`convertToSchema` is called with `physical`, not `blobPhysical`. Could you 
either remove this variable or add the assertion/use you intended?
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



-- 
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]

Reply via email to