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


##########
hudi-hadoop-common/src/main/java/org/apache/hudi/io/storage/hadoop/VariantReconstruction.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * 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.io.storage.hadoop;
+
+import org.apache.hudi.avro.VariantSchemaUtils;
+import org.apache.hudi.avro.VariantShreddingProvider;
+import org.apache.hudi.common.config.HoodieStorageConfig;
+import org.apache.hudi.common.schema.HoodieSchema;
+import org.apache.hudi.common.schema.HoodieSchemaField;
+import org.apache.hudi.common.schema.HoodieSchemaType;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.ReflectionUtils;
+import org.apache.hudi.storage.HoodieStorage;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.generic.IndexedRecord;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;

Review Comment:
   🤖 nit: this `PROVIDER_CANDIDATES` list is duplicated verbatim in 
`HoodieAvroFileWriterFactory.detectShreddingProvider()` — could you pull it 
(and the Class.forName loop) into a small shared helper (e.g. a static 
`VariantShreddingProvider.detectFromClasspath()`) so future provider 
implementations only need to be registered in one place?
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieHadoopFsRelationFactory.scala:
##########
@@ -56,12 +56,41 @@ trait HoodieHadoopFsRelationFactory {
   def buildOptions(): Map[String, String]
 }
 
+object HoodieBaseHadoopFsRelationFactory {
+  /**
+   * Resolves the variant allow-reading-shredded value using the precedence:
+   * table option > hoodie session conf > explicit Spark conf > Hudi default.
+   */
+  private[hudi] def resolveVariantAllowReadingShredded(tableOption: 
Option[String],
+                                                       hoodieSessionValue: 
Option[String],
+                                                       sparkConfValue: 
Option[String],
+                                                       hudiDefault: String): 
String =
+    
tableOption.orElse(hoodieSessionValue).orElse(sparkConfValue).getOrElse(hudiDefault)
+}
+
 abstract class HoodieBaseHadoopFsRelationFactory(val sqlContext: SQLContext,
                                                  val metaClient: 
HoodieTableMetaClient,
                                                  val options: Map[String, 
String],
                                                  val schemaSpec: 
Option[StructType],
                                                  val isBootstrap: Boolean
                                                 ) extends SparkAdapterSupport 
with HoodieHadoopFsRelationFactory with Logging {
+  // Propagate Hudi's variant allow-reading-shredded config to Spark's SQLConf.
+  // ParquetToSparkSchemaConverter reads this from SQLConf.get(), so it must 
be set
+  // before query execution starts here during table resolution
+  if (HoodieSparkUtils.gteqSpark4_0) {
+    val sqlConf = sqlContext.sparkSession.sessionState.conf
+    val hoodieConfKey = 
HoodieStorageConfig.PARQUET_VARIANT_ALLOW_READING_SHREDDED.key
+    // Literal, not SQLConf.VARIANT_ALLOW_READING_SHREDDED.key: that field is 
absent when this module compiles against Spark 3.x.
+    val sparkConfKey = "spark.sql.variant.allowReadingShredded"
+    // Precedence: table option > hoodie session key > explicit Spark conf > 
Hudi default.
+    val allowReadingShredded = 
HoodieBaseHadoopFsRelationFactory.resolveVariantAllowReadingShredded(
+      options.get(hoodieConfKey),
+      if (sqlConf.contains(hoodieConfKey)) 
Some(sqlConf.getConfString(hoodieConfKey)) else None,
+      if (sqlConf.contains(sparkConfKey)) 
Some(sqlConf.getConfString(sparkConfKey)) else None,
+      
HoodieStorageConfig.PARQUET_VARIANT_ALLOW_READING_SHREDDED.defaultValue.toString)
+    sqlConf.setConfString(sparkConfKey, allowReadingShredded)

Review Comment:
   🤖 Setting `spark.sql.variant.allowReadingShredded` on the session's SQLConf 
here persists across queries. If query A on a Hudi table sets 
`hoodie.parquet.variant.allow.reading.shredded=false` via tblproperties, the 
SQLConf change leaks to subsequent queries B/C in the same session (including 
non-Hudi variant tables, which will then silently refuse to read shredded 
variants). It also creates a write-from-multiple-threads concern if concurrent 
queries share the session. Is there a way to scope this to the current 
relation/query (e.g., propagate via hadoopConf only) instead of mutating 
session-level state?
   
   <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