[SPARK-58730][SQL] Support the ANSI SQL/JSON JSON_ARRAY constructor function - #58005
Open
ganeshashree wants to merge 1 commit into
Open
[SPARK-58730][SQL] Support the ANSI SQL/JSON JSON_ARRAY constructor function#58005ganeshashree wants to merge 1 commit into
ganeshashree wants to merge 1 commit into
Conversation
…unction Implement the ANSI SQL:2016 `JSON_ARRAY` constructor, which builds a JSON array from its arguments with `(NULL | ABSENT) ON NULL`, `RETURNING`, and per-element `FORMAT JSON` semantics. Adds `JSON_ARRAY` and `ABSENT` as non-reserved keywords.
uros-b
approved these changes
Aug 14, 2026
Member
|
Thank you @ganeshashree! cc @cloud-fan |
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.
What changes were proposed in this pull request?
Implement the ANSI SQL:2016
JSON_ARRAYconstructor function (feature T811), which builds a JSON array from a list of argument values and returns it as JSON text.Syntax (a dedicated
primaryExpressionproduction, mirroringJSON_TABLE, because theargument list carries non-expression syntax):
JsonArrayCatalyst expression that serializes each element through the sameJackson writer as
to_json, so numbers, decimals, datetimes, and nestedstructs/arrays/maps render consistently.
(NULL | ABSENT) ON NULL:ABSENT ON NULL(the standard default) drops NULLelements;
NULL ON NULLkeeps them as JSONnull.RETURNING: defaults toSTRINGand is restricted to string types (VARIANT deferred);CHAR/VARCHARare normalized toSTRING.FORMAT JSON: splices already-JSON string text verbatim instead of quotingit (validated for well-formedness at eval). A nested JSON constructor carries it
implicitly. The splice/quote decision is frozen at parse time so a later optimizer
rewrite (e.g.
CollapseProjectinlining aJSON_ARRAYalias) cannot flip it.JSON_ARRAYandABSENTadded as non-reserved keywords (matchingJSON_TABLE/JSON_VALUE).Example:
Why are the changes needed?
Spark implements none of the ANSI SQL:2016 constructor JSON functions, forcing users migrating from Oracle, SQL Server, MySQL, Trino, or BigQuery to rewrite
JSON_ARRAY(a, b, c)asto_json(array(a, b, c)), which is verbose and does not carry the standard'sON NULL/RETURNING/FORMAT JSONsemantics.Does this PR introduce any user-facing change?
Yes. It adds the new
JSON_ARRAYSQL constructor function and the new non-reserved keywordsJSON_ARRAYandABSENT. There is no change to existing queries (both keywords remain usable as identifiers, as they are non-reserved).How was this patch tested?
JsonArraySuite(49 cases): scalar/mixed/nested values, bothON NULLmodes,RETURNING(collated + CHAR/VARCHAR normalization), implicit/explicitFORMAT JSON(splicing, per-row validation, error truncation), plan-stability of the splice decision, foldable/throwable/collation behavior, and analysis-time type rejection.json-functions.sql(SQLQueryTestSuite).SQLKeywordSuiteand regeneratedkeywords*.sql.outfor the new keywords;checkErrorcoverage for the new error conditions.sql-ref-syntax-qry-select-json-array.md.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)