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


##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/io/storage/row/HoodieRowParquetWriteSupport.java:
##########
@@ -872,16 +878,25 @@ private Type convertField(HoodieSchema fieldSchema, 
StructField structField, Typ
                   .named(MAP_REPEATED_NAME))
           .named(structField.name());
     } else if (dataType instanceof StructType) {
+      StructType nestedStruct = (StructType) dataType;
       Types.GroupBuilder<GroupType> groupBuilder = 
Types.buildGroup(repetition);
-      Arrays.stream(((StructType) dataType).fields()).forEach(field -> {
+      Arrays.stream(nestedStruct.fields()).forEach(field -> {
         // Note: Cannot use HoodieSchemaField::schema method reference due to 
Java 17 compilation ambiguity
         HoodieSchema nestedFieldSchema = Option.ofNullable(resolvedSchema)
             .flatMap(s -> s.getField(field.name()))
             .map(f -> f.schema())
             .orElse(null);
         groupBuilder.addField(convertField(nestedFieldSchema, field));
       });
-      return groupBuilder.named(structField.name());
+      // A shredded variant column reaches here as a marked struct (the 
VariantType was replaced by
+      // its {metadata, value, typed_value} shredding schema). Tag the parquet 
group with the VARIANT
+      // logical type so external readers recognize it as a Variant, matching 
Spark's native shredded
+      // parquet schema. No-op on Spark 4.0/3.x (the annotation only exists in 
parquet 1.16+).
+      Types.GroupBuilder<GroupType> finalBuilder =

Review Comment:
   🤖 nit: could you rename `finalBuilder` to `annotatedBuilder` (or 
`taggedBuilder`)? In Parquet's builder API `.named()` is the actual 
"finalizing" call that closes the builder chain, so `finalBuilder` reads as 
though the builder has already been completed rather than as "the builder we'll 
eventually call `.named()` on".
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
hudi-common/src/main/java/org/apache/hudi/avro/VariantShreddingRuntime.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.avro;
+
+import org.apache.hudi.common.util.Option;
+
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * Classpath detection of engine-specific variant shredding components.
+ *
+ * <p>Engine modules (currently the Spark 4.x bundles) ship implementations of
+ * {@link VariantShreddingProvider} and {@link 
VariantShreddingSchemaInferrer}; hudi-common
+ * discovers them by probing well-known class names so that it stays free of 
engine
+ * dependencies. Probes are memoized: classpath content does not change within 
a JVM.</p>
+ */
+@Slf4j
+public final class VariantShreddingRuntime {
+
+  /** Provider candidates, most specific first. Mirrors what each Spark bundle 
ships. */
+  private static final String[] PROVIDER_CANDIDATES = {
+      "org.apache.hudi.variant.Spark4VariantShreddingProvider"
+  };
+
+  /**
+   * Inferrer candidates, one per Spark version module that ships one 
(inference exists only in
+   * Spark 4.1+, SPARK-53659). A new Spark version module adds its 
implementation here.
+   */
+  private static final String[] INFERRER_CANDIDATES = {
+      "org.apache.hudi.variant.Spark41VariantShreddingSchemaInferrer"
+  };
+
+  private static final Option<String> PROVIDER_CLASS = 
probe(PROVIDER_CANDIDATES);
+  private static final Option<VariantShreddingSchemaInferrer> INFERRER = 
loadInferrer();
+
+  private VariantShreddingRuntime() {
+  }
+
+  /**
+   * The fully-qualified name of the first {@link VariantShreddingProvider} 
implementation
+   * found on the classpath, if any.
+   */
+  public static Option<String> detectProviderClass() {

Review Comment:
   🤖 nit: `detectProviderClass` implies active classpath scanning on every 
call, but it's just returning the pre-computed `PROVIDER_CLASS` field. 
Something like `getProviderClass` would make the memoized-result semantics 
immediately obvious without needing to chase the class-level Javadoc.
   
   <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