Repository navigation
Conversation
01e4665 to
95d3d3c
Compare
cloud-fan
left a comment
There was a problem hiding this comment.
Review summary
I found two non-blocking issues in the expanded escape support. The new decoded key domain is not encoded safely when mutation errors reconstruct failedAt, so some supported keys yield a malformed or different diagnostic prefix. The added tests also omit three independently implemented short-control mappings, allowing regressions in \b, \f, or \r to pass unnoticed. The distributed SQL performance review found only bounded linear per-path work and no material regression.
Findings
2 total: 0 P0, 0 P1, 2 P2, 0 P3.
Non-blocking (P2)
- Preserve escaped keys in failedAt paths —
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/variant/variantExpressions.scala:377— see inline. - Cover the remaining short control escapes —
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/variant/VariantExpressionSuite.scala:744— see inline.
Teach VariantPathParser to decode escape sequences in the single-quoted `['...']` bracket key form so paths emitted by recursive variant_explode round trip through variant_get. Decodes `\\`, `\'`, the short control-char escapes `\b \t \n \f \r`, and `\uXXXX`; a backslash that does not begin one of these is kept literally, so paths with literal backslashes keep working. The dot notation and the double-quoted `["..."]` form are unchanged.
HyukjinKwon
left a comment
There was a problem hiding this comment.
Review summary
The escape-support implementation is clean and well-scoped: the decode set matches RFC 9535 (unknown escapes left literal, matching-delimiter quote only), and the new quoteKey renderer keeps failedAt diagnostics round-trippable. The prior review's findings are resolved -- renderVariantPath now re-encodes decoded keys via quoteKey (fixing the unescaped-diagnostic issue), and the parse-side control escapes \b/\f/\r now have assertions.
Two items remain, both non-blocking. A P3 test gap, flagged inline: quoteKey's control-character render escaping has no round-trip case (the added cases use only quote/backslash keys), so a regression there would ship silently. And a backward-compatibility decision for the author (in the Decision challenges section): the RFC escaping reinterprets or rejects previously-valid literal-backslash quoted-key paths, which is intended but observable on documented SQL functions -- worth confirming whether it needs a legacy guard or migration note.
Generated by Omnigent on Databricks
Findings
1 total: 0 P0, 0 P1, 0 P2, 1 P3.
Nit (P3)
- quoteKey control-character render escaping is untested —
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/variant/VariantExpressionSuite.scala:1679— see inline.
Decision challenges
Backward-incompatible reinterpretation of previously-valid quoted-key paths
Decoding RFC 9535 escapes in bracket-quoted keys is a backward-incompatible change to the documented variant_get/try_variant_get/variant_insert path grammar. Previously the bracket content was literal ([^']* / [^"]*), so a path like $['a\nb'] resolved the literal key a\nb, and $['foo\'] resolved the literal key foo\. With this change $['a\nb'] now resolves a<newline>b, and $['foo\'] fails to parse (the \' is consumed as an escaped quote, so the closing '] is never matched). This aligns with RFC 9535 and is the PR's intent, but existing user queries with backslashes in quoted keys will silently change results or newly error. Could you confirm this breaking change is acceptable as-is, or whether it warrants a legacy-config fallback and/or a migration-guide note?
7337b43 to
fa28b34
Compare
f4a406e to
fae0e35
Compare
|
@bojana-db can you fix merge conflicts? |
…er-escapes # Conflicts: # docs/sql-migration-guide.md
…er-escapes # Conflicts: # docs/sql-migration-guide.md
Done. |
cloud-fan
left a comment
There was a problem hiding this comment.
Review summary
This round reviews the escape decoding for bracket-quoted Variant path keys and the new spark.sql.legacy.variantPathBackslashAsLiteral fallback. The decoder, the mode captured at analysis and threaded through interpreted evaluation, codegen and Parquet pushdown, and the quoteKey rendering of failedAt all hold up; the issues found sit at the surfaces around that core.
Both findings from the previous Spark Dev review are fixed: failedAt prefixes are now re-encoded with quoteKey, and lookups for \b, \f and \r are asserted. The later follow-ups from HyukjinKwon are also addressed: a control-character failedAt round-trip case was added, and the compatibility question was answered with the legacy flag and a 4.4 migration-guide entry.
- The DSv2
VariantGettranslation drops the captured mode, so a third-party connector receives the same expression in both modes for bracket keys containing backslashes. - The
VariantExtraction.metadata()Javadoc does not document the new mode key or the escape grammar that extraction-pushdown connectors now need. - Colon syntax still validates and names paths with
JsonPathParser, so aliases of escaped keys no longer match the key read, and escaped quotes are rejected there. - Mode-flip tests miss several threading sites and the registry constructors, and the grammar's boundaries plus most
quoteKeybranches have no assertions. - The migration note does not list which escapes are recognized.
Review-level concerns
- Shared problem: Now that a variant path's meaning depends on the parser mode captured when the query is analyzed, both places where Spark hands path strings to DSv2 connectors need one stated grammar. These are the connector VariantGet used for pushed predicates, metadata-only deletes, constraints and generated columns, and the VariantExtraction metadata used for extraction pushdown. The coordinated response is to document the escaped JSONPath grammar on both connector surfaces and to keep legacy mode from being ambiguous: decline predicate translation for mode-sensitive legacy paths, and document the metadata key that extraction pushdown already carries. Fixing only one surface would leave connectors guessing on the other. These are non-blocking issues that can be addressed before or after merge.
Cross-cutting observations
- The new escape grammar (recognized escapes, the enclosing-quote-only rule, surrogate handling, and undecoded dot keys) is currently defined only in VariantPathParser. The connector documentation, the colon-syntax front end and the migration note each need the same definition, so writing it once, or reusing the parser directly as the colon-syntax fix does, keeps these surfaces from drifting apart.
Separation: Each surface has its own owner, audience and repair mechanism and can be fixed independently; sharing one definition is a consistency aid and does not create a coordination dependency or change any repair's scope.
Findings
6 total: 0 P0, 0 P1, 1 P2, 5 P3.
Non-blocking (P2)
- DSv2 VariantGet translation drops the captured path mode —
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/variant/variantExpressions.scala:570— see inline.
Nit (P3)
- Colon syntax still validates and names bracket keys with the literal grammar —
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/variant/variantExpressions.scala:384— see inline. - VariantExtraction metadata contract omits the new path-mode key —
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/PushVariantIntoScan.scala:61— see inline. - Captured-mode tests miss dynamic-path, failedAt and registry branches —
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/variant/VariantExpressionSuite.scala:813— see inline. - Escaped-grammar boundaries and quoteKey branches lack assertions —
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/variant/VariantExpressionSuite.scala:759— see inline. - Migration note never lists the recognized escapes —
docs/sql-migration-guide.md:31— see inline.
Re-review status
Prior AI findings: 2 addressed, 0 still present; additional unresolved findings in this review: 6.
New attribution: 5 newly introduced, 1 late catch, 0 previously raised, 0 unattributed.
Remaining prior AI findings
No prior AI findings remain.
PR description suggestions
- In the user-facing change section, note that some previously valid paths now fail (for example
$['a\']), that\/and UTF-16 surrogate pairs are also decoded, and that settingspark.sql.legacy.variantPathBackslashAsLiteraltotruerestores the old literal behavior. - Mention that analyzed-plan and EXPLAIN strings for the Variant path functions now end with an extra boolean (the captured parser mode), which is why the Connect explain and analyzer golden files changed.
cloud-fan
left a comment
There was a problem hiding this comment.
Review summary
This round re-reviews head d46ef02 against the previous Spark Dev review. Four of its six findings are fixed. The VariantExtraction.metadata() Javadoc now documents legacyPathBackslashAsLiteral and the decoded escapes. The captured-mode tests now flip the conf for constant and dynamic paths of all six functions, for failedAt, and for the SQL registry constructors. The grammar boundaries ($['a\'], $['a\']b'], literal dot keys and every quoteKey branch) are asserted. The migration note lists the recognized escapes.
Two findings remain open on their existing threads. The DSv2 connector VariantGet still carries no parser mode, so a third-party connector receives the same path in both modes for bracket keys that contain a backslash. The reply on that thread addresses the question about losing legacy-mode pushdown. Colon syntax still validates and names bracket keys with JsonPathParser. The author's plan to fix that in a follow-up is reasonable for a P3 limited to colon-syntax keys with backslashes, and the reply asks for a tracked JIRA.
One new finding: with the default escape-decoding grammar, non-foldable bracket-quoted paths pay extra CPU on every row, because the new key regex is recompiled on each parse and matches characters slowly. Constant paths, dot-only paths and scan pushdown are unaffected.
Cross-cutting observations
- The PR threads the captured parser mode through Spark's own evaluators, generated code, scan metadata, and Parquet pushdown, but two places that re-read the same path text outside that plumbing still assume a single grammar: DSv2 predicate translation hands connectors a path whose meaning now depends on the mode, and colon-syntax parsing validates and names paths with the literal JSON path grammar. Checking any other place that re-exposes or re-parses a Variant path string against the captured mode would catch the same class of gap.
Separation: The two gaps share a cause but not an owner, state, or transition. Each closes at its own boundary with its own mechanism, so they stay independent repairs with unchanged severity.
Findings
3 total: 0 P0, 0 P1, 1 P2, 2 P3.
Non-blocking (P2)
- DSv2 VariantGet translation drops the captured path mode —
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/variant/variantExpressions.scala:570— unresolved in existing discussion.
Nit (P3)
- Colon syntax still validates and names bracket keys with the literal grammar —
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/variant/variantExpressions.scala:384— unresolved in existing discussion. - Dynamic bracket paths recompile and slowly match the new key regex per row —
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/variant/variantExpressions.scala:384— see inline.
Re-review status
Prior AI findings: 4 addressed, 2 still present; additional unresolved findings in this review: 1.
New attribution: 0 newly introduced, 1 late catch, 0 previously raised, 0 unattributed.
Remaining prior AI findings
- DSv2 VariantGet translation drops the captured path mode —
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/variant/variantExpressions.scala:570 - Colon syntax still validates and names bracket keys with the literal grammar —
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/variant/variantExpressions.scala:384
Verification
- JsonPathParser's bracket pattern accepts
$['a\nb']with a literal backslash and rejects$['a\'b'], checked locally with java.util.regex. - Local jshell timing (200k iterations): the new quoted-key pattern took about 0.81us vs 0.27us compile plus match for a 4-character key and 4.54us vs 0.57us for a 200-character key; the unrolled form took 1.66us and matched the same prefixes on boundary inputs.
|
@bojana-db can you fix merge conflicts? |
…er-escapes # Conflicts: # docs/sql-migration-guide.md
Done. |
cloud-fan
left a comment
There was a problem hiding this comment.
Review summary
This round re-reviews head 07b18ad against the previous Spark Dev review of d46ef02, and all three of that review's findings are settled. V2ExpressionBuilder now translates a VariantGet that captured legacy mode only when the legacy and default parses of its path give the same segments, and the connector VariantGet Javadoc states that path follows the default grammar, so a connector no longer receives one path string that can name two different keys. The colon-syntax validation and alias divergence is deferred by agreement to SPARK-58540, which the author filed as requested. The per-row parse cost of dynamic bracket paths is fixed: the escaped key parser is now built once and uses possessive, unrolled patterns.
One new nit, in the tests only: the surrogate-pair branch of the new decoder accepts lower-case hex and any high surrogate up to DBFF, but the added cases exercise only upper-case pairs with a D8 high surrogate, so narrowing either part of the pattern would leave the suite green.
Findings
1 total: 0 P0, 0 P1, 0 P2, 1 P3.
Nit (P3)
- Surrogate-pair tests cover only upper-case D8xx escapes —
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/variant/VariantExpressionSuite.scala:761— see inline.
Re-review status
Prior AI findings: 3 addressed, 0 still present; additional unresolved findings in this review: 1.
New attribution: 0 newly introduced, 1 late catch, 0 previously raised, 0 unattributed.
Remaining prior AI findings
No prior AI findings remain.
Verification
- A local java.util.regex run of the current
escapeSeqpattern matched\ud83d\ude00and\uDBFF\uDFFFeach as one pair; upper-case-only and D8-only narrowings still matched the suite's existing\uD83D\uDE00input as one pair but split the corresponding new form into two unpaired escapes.
PR description suggestions
- In the user-facing change section, note that the connector-facing paths change too: the DSv2 connector
VariantGetpath andVariantExtractionmetadata now follow the escaped grammar, extraction metadata carries the newlegacyPathBackslashAsLiteralkey, and in legacy mode Spark declines DSv2 translation of avariant_getwhose path parses differently under the two grammars. - Mention that colon-syntax bracket keys (
v:['...']) also decode escapes at execution, while their parse-time validation and column aliases still use the old literal grammar until the SPARK-58540 follow-up.
### What changes were proposed in this pull request? `VariantPathParser` now decodes escape sequences in the single-quoted `['...']` and double-quoted `["..."]` bracket form — \', \\, the short control escapes `\b` `\t` `\n` `\f` `\r`, and `\uXXXX`, and escapes of the enclosing quote (`\'` in `['...']`, `\"` in `["..."]`). Notes: - `\/` and valid Unicode surrogate pairs are also decoded. Unknown escapes and unpaired surrogate escapes remain literal. - Existing paths may match different keys. `$['a\']` and `$["a\"]` now error because the backslash escapes the closing quote; double the backslash to keep it literal. - Set `spark.sql.legacy.variantPathBackslashAsLiteral=true` before creating the query to restore the previous behavior. - Analyzed plans and `EXPLAIN` output include an extra boolean for the captured parser mode. ### Why are the changes needed? There was no support before and generated recursive `variant_explode paths` must round-trip through variant path consumers.. ### Does this PR introduce _any_ user-facing change? Yes. Inside both bracket forms of a variant path, a backslash now introduces an escape. Examples: - Previously the content was literal, e.g. `$['a\tb']` addressed the key `a\tb` (backslash + t). - Now `$['a\tb']` addresses a+TAB+b; `$['a\'b']` addresses a'b (previously rejected); `$["a\"b"]` addresses `a"b`; `$['a\\b']` / `$["a\\b"]` address `a\b`. ### How was this patch tested? Added unit tests. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code Closes #59097 from bojana-db/variant-path-parser-escapes. Authored-by: bojana-db <[email protected]> Signed-off-by: Wenchen Fan <[email protected]> (cherry picked from commit 2713865) Signed-off-by: Wenchen Fan <[email protected]>
What changes were proposed in this pull request?
VariantPathParsernow decodes escape sequences in the single-quoted['...']and double-quoted["..."]bracket form — ', \, the short control escapes\b\t\n\f\r, and\uXXXX, and escapes of the enclosing quote (\'in['...'],\"in["..."]).Notes:
\/and valid Unicode surrogate pairs are also decoded. Unknown escapes and unpaired surrogate escapes remain literal.$['a\']and$["a\"]now error because the backslash escapes the closing quote; double the backslash to keep it literal.spark.sql.legacy.variantPathBackslashAsLiteral=truebefore creating the query to restore the previous behavior.EXPLAINoutput include an extra boolean for the captured parser mode.Why are the changes needed?
There was no support before and generated recursive
variant_explode pathsmust round-trip through variant path consumers..Does this PR introduce any user-facing change?
Yes. Inside both bracket forms of a variant path, a backslash now introduces an escape. Examples:
$['a\tb']addressed the keya\tb(backslash + t).$['a\tb']addresses a+TAB+b;$['a\'b']addresses a'b (previously rejected);$["a\"b"]addressesa"b;$['a\\b']/$["a\\b"]addressa\b.How was this patch tested?
Added unit tests.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code