Skip to content

[SPARK-52153][SQL] Fix from_json and to_json with variant #50901

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

Conversation

chenhao-db
Copy link
Contributor

What changes were proposed in this pull request?

It fixes two minor issues with from_json(variant) and to_json(variant).

  • from_json(variant) currently ignores any JSON options. This is inconsistent with from_json(nested type containing variant), which respects JSON options.
  • to_json(variant), when the variant contains special floating-point values (Infinity, NaN), the output is currently not wrapped in quotes. This is inconsistent with to_json(nested type containing floating points).
    • For example, the result of to_json(named_struct('a', cast('NaN' as double))) is {"a":"NaN"}, while the result of to_json(to_variant_object(named_struct('a', cast('NaN' as double)))) is {"a":NaN}
    • Although {"a":NaN} can be parsed by from_json when the allowNonNumericNumbers option is true, it is still not a valid JSON according to the spec. to_json should produce valid JSON.

Why are the changes needed?

This makes variant-related JSON handling more consistent with non-variant JSON handling.

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 15, 2025
@chenhao-db
Copy link
Contributor Author

@cloud-fan Could you help review? Thanks!

@HyukjinKwon HyukjinKwon changed the title [SPARK-52153] Fix from_json and to_json with variant [SPARK-52153][SQL] Fix from_json and to_json with variant May 15, 2025
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