[SPARK-58222][SQL] Add try_variant_array_append expression#57378
Closed
bojana-db wants to merge 3 commits into
Closed
[SPARK-58222][SQL] Add try_variant_array_append expression#57378bojana-db wants to merge 3 commits into
try_variant_array_append expression#57378bojana-db wants to merge 3 commits into
Conversation
try_variant_array_append expressiontry_variant_array_append expression
harshmotw-db
approved these changes
Jul 21, 2026
harshmotw-db
left a comment
Contributor
There was a problem hiding this comment.
LGTM, thanks for the feature!
uros-b
approved these changes
Jul 21, 2026
uros-b
left a comment
Member
There was a problem hiding this comment.
Thank you @bojana-db and @harshmotw-db!
try_variant_array_append expressiontry_variant_array_append expression
uros-b
pushed a commit
that referenced
this pull request
Jul 21, 2026
### What changes were proposed in this pull request? Adds the SQL function `try_variant_array_append(v, path, val)`, the error-tolerant counterpart of `variant_array_append`. It appends a value to the array in a Variant value at a single JSONPath location, returning NULL instead of failing the query when the operation hits a recoverable error. Details: - On a valid append, behaves exactly like `variant_array_append`: appends `val` as a new last element of the array at `path` (e.g. `$.a`, `$[0]`, `$.a[1]`); the root path `$` targets the whole Variant, which must itself be an array; a missing key or out-of-range array index along the path leaves `v` unchanged; - Recoverable errors are caught and return NULL instead of throwing: a path type mismatch (`VARIANT_PATH_TYPE_MISMATCH`), raised when a path segment is applied to a value of an incompatible type or when the target is not an array; - Non-recoverable errors still throw, matching `variant_array_append`: a malformed path is rejected with `INVALID_VARIANT_PATH` (the path is parsed before the append), and a result exceeding the size limit raises `VARIANT_SIZE_LIMIT`; - Any NULL argument returns NULL; - The value may be any expression castable to variant. An array value is appended as a single nested element rather than flattened, and a variant null appends a null element. ### Why are the changes needed? Error-tolerant counterpart of `variant_array_append`. ### Does this PR introduce _any_ user-facing change? Yes, a new SQL function `try_variant_array_append` (and the corresponding Scala/Python `functions` API). ### How was this patch tested? Unit tests. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Cursor with Claude Opus 4.8 Closes #57378 from bojana-db/try-variant-array-append. Authored-by: bojana-db <bojana.zecevic@databricks.com> Signed-off-by: Uros Bojanic <221401595+uros-b@users.noreply.github.com> (cherry picked from commit f0cbaf7) Signed-off-by: Uros Bojanic <221401595+uros-b@users.noreply.github.com>
Member
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?
Adds the SQL function
try_variant_array_append(v, path, val), the error-tolerant counterpart ofvariant_array_append. It appends a value to the array in a Variant value at a single JSONPath location, returning NULL instead of failing the query when the operation hits a recoverable error.Details:
variant_array_append: appendsvalas a new last element of the array atpath(e.g.$.a,$[0],$.a[1]); the root path$targets the whole Variant, which must itself be an array; a missing key or out-of-range array index along the path leavesvunchanged;VARIANT_PATH_TYPE_MISMATCH), raised when a path segment is applied to a value of an incompatible type or when the target is not an array;variant_array_append: a malformed path is rejected withINVALID_VARIANT_PATH(the path is parsed before the append), and a result exceeding the size limit raisesVARIANT_SIZE_LIMIT;Why are the changes needed?
Error-tolerant counterpart of
variant_array_append.Does this PR introduce any user-facing change?
Yes, a new SQL function
try_variant_array_append(and the corresponding Scala/PythonfunctionsAPI).How was this patch tested?
Unit tests.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor with Claude Opus 4.8