[SPARK-52267] Match field ID in ParquetToSparkSchemaConverter #50990
+53
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
In the vectorized Parquet reader, there are two classes to resolve the Parquet schema when reading a Parquet file:
ParquetReadSupport
: it clips the Parquet schema to only include the necessary part used by the Spark requested schema. The matching considers both field name and ID.ParquetToSparkSchemaConverter
: it resolves the Parquet schema to a Spark type by connecting it to the Spark requested schema. The matching only considers field name.When the field ID matches but field name doesn't, the first step will clip the Parquet schema to the same structure as the Spark requested schema as expected. In the second step, the Parquet type cannot be connected to a Spark type in the requested schema, and it will be inferred as a Spark type. It will usually work as expected if the inferred type is the same as the requested type. But it is possible that they are different and the read is still valid. For example, if the Parquet type is
int
and the Spark type islong
. In this case, the vectorized Parquet reader will produceint
data in column vectors, which will be interpreted aslong
data by subsequent operations.This can happen in real user cases if an Iceberg table with both rename and change column type (int -> long) operations is converted into a Delta table. This situation may be very rare, though.
This PR fixes by bug by matching field ID in
ParquetToSparkSchemaConverter
when the name cannot be matched. I know thatParquetReadSupport
gives priority to field ID when it exists, but I am not fully confident about this change and would like to keep the semantic change minimal.Why are the changes needed?
It fixes a correctness issue.
Does this PR introduce any user-facing change?
Yes, as stated above.
How was this patch tested?
Unit test.
Was this patch authored or co-authored using generative AI tooling?
No.