[SPARK-58723][SQL] Support the ANSI SQL/JSON_QUERY function - #57957
Open
s-ganesha wants to merge 1 commit into
Open
[SPARK-58723][SQL] Support the ANSI SQL/JSON_QUERY function#57957s-ganesha wants to merge 1 commit into
s-ganesha wants to merge 1 commit into
Conversation
Add the ANSI SQL:2016 JSON_QUERY function (feature T828): extract the JSON
value located by a SQL/JSON path from a JSON input and return it as JSON text.
Syntax:
JSON_QUERY(jsonExpr, path
[ RETURNING type ]
[ (WITHOUT | WITH [CONDITIONAL | UNCONDITIONAL]) [ARRAY] WRAPPER ]
[ (KEEP | OMIT) QUOTES ]
[ (NULL | ERROR | EMPTY ARRAY | EMPTY OBJECT) ON EMPTY ]
[ (NULL | ERROR | EMPTY ARRAY | EMPTY OBJECT) ON ERROR ])
Implemented as a parser-only production (no FunctionRegistry entry), mirroring
the merged JSON_VALUE (SPARK-58685) and reusing the JSON path evaluator from
JSON_TABLE. The matched object/array/scalar is serialized verbatim; a scalar is
emitted as JSON text under the default WITHOUT ARRAY WRAPPER, OMIT QUOTES
unquotes a scalar string, the array wrapper wraps per the standard, and
ON EMPTY / ON ERROR default to NULL. RETURNING is STRING-only for now (VARIANT
deferred) and CHAR/VARCHAR are normalized to STRING. Paths are wildcard-free.
uros-b
approved these changes
Aug 12, 2026
Member
|
Thank you @ganeshashree! |
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?
Add the ANSI SQL:2016
JSON_QUERYfunction (feature T828), which extracts the JSON value located by a SQL/JSON path from a JSON input and returns it as JSON text.It is implemented as a parser-only production (no FunctionRegistry entry), mirroring the merged JSON_VALUE (SPARK-58685) and reusing the JSON path evaluator from JSON_TABLE (SPARK-58366). The matched object/array/scalar is serialized verbatim; a scalar is emitted as JSON text under the default WITHOUT ARRAY WRAPPER, OMIT QUOTES unquotes a scalar string, the array wrapper wraps per the standard (CONDITIONAL wraps only a scalar), and ON EMPTY / ON ERROR default to NULL. RETURNING is STRING-only for now (VARIANT deferred); paths are wildcard-free.
Example (j = {"id":7,"name":"Ada","tags":["x","y"],"addr":{"city":"NYC"}}):
Follow-ups (shared with JSON_VALUE, out of scope here): default-collation rewrite of the result, whole-stage codegen, and cross-expression parse sharing for sibling projections.
Why are the changes needed?
JSON_QUERY is the SQL-standard way to extract an object/array/scalar fragment from JSON, supported by Oracle, SQL Server, PostgreSQL, Trino, Flink, and others. Spark had no equivalent, forcing migrated queries onto get_json_object, whose NULL/error semantics differ (it conflates "missing" and "parse error", always returns STRING, and offers no wrapper/quotes control). This is the natural follow-on to JSON_VALUE.
Does this PR introduce any user-facing change?
Yes. It adds the new JSON_QUERY SQL function and its documentation, and adds JSON_QUERY, WRAPPER, QUOTES, KEEP, OMIT, CONDITIONAL, UNCONDITIONAL, and OBJECT as non-reserved keywords (usable as identifiers in both modes). No change to existing behavior.
How was this patch tested?
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.8)