wombatu-kun commented on code in PR #20891:
URL: https://github.com/apache/hudi/pull/20891#discussion_r4709037522
##########
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:
Using the supplied schema as the Parquet projection rejects valid numeric
widening such as `INT32` to `long` under the default strict type checking. Set
`ParquetInputFormat.STRICT_TYPE_CHECKING` to `false` on the job configuration
and cover an int-to-long import in the regression test.
##########
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:
This `unset` mutates the shared Hadoop conf from a suite that runs
concurrently with other procedure suites. Capture the existing value and assert
that it is unchanged after the import instead of clearing 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]