[SPARK-59325][SQL] Add an optional maximum nesting depth for variant values - #58607
Open
HyukjinKwon wants to merge 1 commit into
Open
[SPARK-59325][SQL] Add an optional maximum nesting depth for variant values#58607HyukjinKwon wants to merge 1 commit into
HyukjinKwon wants to merge 1 commit into
Conversation
HyukjinKwon
force-pushed
the
SPARK-59325-variant-max-depth
branch
2 times, most recently
from
September 8, 2026 22:32
a7061fa to
26b96a0
Compare
…values ### What changes were proposed in this pull request? Add an opt-in `spark.sql.variant.maxNestingDepth` (internal, default `-1` = unlimited = unchanged). When set to a positive value, rendering a variant value whose nesting exceeds it fails instead of recursing without bound. The limit is threaded as a parameter into the recursive variant read paths so `common/variant` does not need `SQLConf` access: - `Variant.toJson` / `toJsonImpl` and `VariantVal.toJson` gain overloads carrying the limit; the existing signatures delegate with `-1` (unchanged). - The SQL cast/`variant_get`-to-string path, the Parquet variant shredding read, and `to_json` obtain the limit once (per expression / per task), not per row. ### Why are the changes needed? `Variant.toJsonImpl` recursed per nested element with no bound, so a deeply nested variant could exhaust the stack when rendered. The existing size limit does not prevent this (a small-per-level variant can nest very deeply within the size cap). This adds an optional bound. ### Does this PR introduce _any_ user-facing change? No by default. When `spark.sql.variant.maxNestingDepth` is set to a positive value, variant values nested more deeply than the limit raise an error when rendered. ### How was this patch tested? New `VariantExpressionSuite` case: a deeply nested variant renders fully when the limit is unset or generous and is rejected when the limit is smaller than its depth. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Isaac This pull request and its description were written by Isaac. Co-authored-by: Isaac <no-reply@databricks.com>
HyukjinKwon
force-pushed
the
SPARK-59325-variant-max-depth
branch
from
September 9, 2026 11:00
26b96a0 to
d784c05
Compare
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 an opt-in
spark.sql.variant.maxNestingDepth(internal, default-1= unlimited = unchanged).When set to a positive value, rendering a variant value whose nesting exceeds it fails instead of
recursing without bound. The limit is threaded as a parameter into the recursive variant read
paths so
common/variantdoes not needSQLConfaccess:Variant.toJson/toJsonImplandVariantVal.toJsongain overloads carrying the limit; theexisting signatures delegate with
-1(unchanged).variant_get-to-string path, the Parquet variant shredding read, andto_jsonobtain the limit once (per expression / per task), not per row.Why are the changes needed?
Variant.toJsonImplrecursed per nested element with no bound, so a deeply nested variant couldexhaust the stack when rendered. The existing size limit does not prevent this (a small-per-level
variant can nest very deeply within the size cap). This adds an optional bound.
Does this PR introduce any user-facing change?
No by default. When
spark.sql.variant.maxNestingDepthis set to a positive value, variant valuesnested more deeply than the limit raise an error when rendered.
How was this patch tested?
New
VariantExpressionSuitecase: a deeply nested variant renders fully when the limit is unset orgenerous and is rejected when the limit is smaller than its depth.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Isaac
This pull request and its description were written by Isaac.
Co-authored-by: Isaac no-reply@databricks.com