Skip to content

[SPARK-52233][SQL] Fix map_zip_with for Floating Point Types #50967

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 2 commits into
base: master
Choose a base branch
from

Conversation

mihailom-db
Copy link
Contributor

What changes were proposed in this pull request?

Fix to map_zip_with expression while handling floating point numbers.

Why are the changes needed?

Previously we would run getKeysWithIndexesFast which would use LinkedHashMap, which does not use proper equality on keys for floating point numbers. All NaNs would be treated in a different way. This PR aims to fix this behaviour.

Example:

select map_zip_with(map(float('NaN'), 1), map(float('NaN'), 2), (k, v1, v2) -> (v1, v2))

Output before:

{"NaN":{"v1":1,"v2":null},"NaN":{"v1":null,"v2":2}}

Output after:

{"NaN":{"v1":1,"v2":2}}

Does this PR introduce any user-facing change?

Yes, fixing the way expression works.

How was this patch tested?

Added tests to golden files.

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

No.

@github-actions github-actions bot added the SQL label May 21, 2025
getKeysWithIndexesBruteForce
keyType match {
case properEqualsType if TypeUtils.typeWithProperEquals(properEqualsType) =>
getKeysWithIndexesFast
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we simply changge getKeysWithIndexesFast to normalize the float/double values before putting into the hashmap?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the code now, could you take one more look?

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.

2 participants