voonhous commented on code in PR #20891:
URL: https://github.com/apache/hudi/pull/20891#discussion_r4716276883


##########
hudi-spark-datasource/hudi-spark/src/main/java/org/apache/hudi/cli/HDFSParquetImporterUtils.java:
##########
@@ -183,7 +184,11 @@ public JavaRDD<HoodieRecord<HoodieRecordPayload>> 
buildHoodieRecordsForImport(Ja
     job.getConfiguration().set(FileInputFormat.INPUT_DIR_RECURSIVE, "true");
     // To parallelize reading file status.
     job.getConfiguration().set(FileInputFormat.LIST_STATUS_NUM_THREADS, 
"1024");
-    AvroReadSupport.setAvroReadSchema(jsc.hadoopConfiguration(), 
HoodieSchema.parse(schemaStr).getAvroSchema());
+    Schema readSchema = HoodieSchema.parse(schemaStr).getAvroSchema();
+    // On the job's copy, which the read below uses; the shared Spark conf 
would leak the schema to every other reader.
+    AvroReadSupport.setAvroReadSchema(job.getConfiguration(), readSchema);
+    // Without the projection every source column is read, and one the read 
schema lacks fails the conversion.
+    AvroReadSupport.setRequestedProjection(job.getConfiguration(), readSchema);

Review Comment:
   Good catch, confirmed: with the widened schema the read failed with 
`incompatible types: required int64 distance_in_meters != required int32 
distance_in_meters`. Fixed in 7fcb2efbf832: strict type checking is now turned 
off on the job conf when unset, as `HoodieAvroParquetReader` does. The 
regression test widens `distance_in_meters` to long and checks the imported 
values.



##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/procedure/TestHdfsParquetImportProcedure.scala:
##########
@@ -112,6 +116,37 @@ class TestHdfsParquetImportProcedure extends 
HoodieSparkProcedureTestBase {
     }
   }
 
+  test("Test hdfs_parquet_import reads with the supplied schema and leaves the 
shared conf alone") {
+    withTempDir { tmp =>
+      val sourcePath = new Path(tmp.getCanonicalPath, "source")
+      createInsertRecords(sourcePath)
+      // The supplied schema drops `rider`, so a read that applies it yields 
records without that field.
+      val fields = HoodieTestDataGenerator.AVRO_SCHEMA.getFields.asScala
+        .filter(_.name != "rider")
+        .map(f => new Schema.Field(f.name, f.schema, f.doc, f.defaultVal))
+      val readSchema = 
Schema.createRecord(HoodieTestDataGenerator.AVRO_SCHEMA.getName, null,
+        HoodieTestDataGenerator.AVRO_SCHEMA.getNamespace, false, fields.asJava)
+      // AvroReadSupport.AVRO_READ_SCHEMA, which is private
+      val readSchemaKey = "parquet.avro.read.schema"
+      val sharedConf = spark.sparkContext.hadoopConfiguration
+      sharedConf.unset(readSchemaKey)

Review Comment:
   Done in 7fcb2efbf832: the test saves the shared value before the import and 
asserts it is unchanged afterwards, without unsetting it.



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