Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Which issue does this PR close?
Rationale for this change
Spark's
to_jsonaccepts a map or an array as the value to serialize, and an optionalmap(...)of options as a second argument. Both were rejected at planning time:to_json(map('a', 1))failed with "expects a struct argument", and a second argument failed with "but received 2".What changes are included in this PR?
to_jsonaccepts a struct, a map, any Arrow list type, or an untyped NULL. The encoder already serialized maps and lists when nested, so only the planning check changed; the root type gets the same validation as nested types.to_json(expr, options): the second argument is a constant map of strings, read as Spark'sJSONOptionsdoes (case-insensitive names,true/falsein any case).ToJsonOption, named after Spark's JSON data source options(https://spark.apache.org/docs/latest/sql-data-sources-json.html#data-source-option). This PR implements one,
ignoreNullFields. Any other option is an error that lists the supported ones.struct_to_jsonis renamedto_json, matching feat: addto_jsonscalar function datafusion#27518.Are these changes tested?
Yes.
to_json.rsfor the planning check, map/list input as a column and as a scalar (NULL rows, sliced input,LargeList,FixedSizeList), option parsing, andignoreNullFields.json/to_json.slt, written without[...]literals so that Spark can parse them.crates/sqllogictest/scripts. It found one difference,to_json(NULL), which Spark answers with NULL; this PR matches that.Known differences from Spark, marked
# xfail spark: intendedin the SLT:Are there any user-facing changes?
to_jsonaccepts map and array input and theignoreNullFieldsoption.to_json(NULL)returns NULL instead of a planning error.argument".
No change to the public API:
expr_fn::to_json(input)still takes one argument.