Skip to content
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

[SPARK-47803][FOLLOWUP] Check nulls when casting nested type to variant. #46486

Closed

Conversation

chenhao-db
Copy link
Contributor

What changes were proposed in this pull request?

It adds null checks when accessing a nested element when casting a nested type to variant. It is necessary because the get API doesn't guarantee to return null when the slot is null. For example, ColumnarArray.get may return the default value of a primitive type if the slot is null.

Why are the changes needed?

It is a bug fix is necessary for the cast-to-variant expression to work correctly.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Two new unit tests. One directly uses ColumnarArray as the input of the cast. The other creates a real-world situation where ColumnarArray is the input of the cast (scan). Both of them would fail without the code change in this PR.

Was this patch authored or co-authored using generative AI tooling?

No.

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

@cloud-fan could you help review? Thanks a lot!

@cloud-fan
Copy link
Contributor

The docker test failure is unrelated, thanks, merging to master!

@cloud-fan cloud-fan closed this in 3fd38d4 May 9, 2024
JacobZheng0927 pushed a commit to JacobZheng0927/spark that referenced this pull request May 11, 2024
### What changes were proposed in this pull request?

It adds null checks when accessing a nested element when casting a nested type to variant. It is necessary because the `get` API doesn't guarantee to return null when the slot is null. For example, `ColumnarArray.get` may return the default value of a primitive type if the slot is null.

### Why are the changes needed?

It is a bug fix is necessary for the cast-to-variant expression to work correctly.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Two new unit tests. One directly uses `ColumnarArray` as the input of the cast. The other creates a real-world situation where `ColumnarArray` is the input of the cast (scan). Both of them would fail without the code change in this PR.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes apache#46486 from chenhao-db/fix_cast_nested_to_variant.

Authored-by: Chenhao Li <chenhao.li@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants