Skip to content

[SPARK-52267] Match field ID in ParquetToSparkSchemaConverter #50990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

chenhao-db
Copy link
Contributor

@chenhao-db chenhao-db commented May 22, 2025

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 is long. In this case, the vectorized Parquet reader will produce int data in column vectors, which will be interpreted as long 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 that ParquetReadSupport 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.

@github-actions github-actions bot added the SQL label May 22, 2025
@chenhao-db
Copy link
Contributor Author

@cloud-fan @jackierwzhang Please take a look. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant