Skip to content

Accept only Spark $ Variant paths - #187

Merged
sdf-jkl merged 2 commits into
mainfrom
sdf-jkl/spark-only-paths
Nov 12, 2026
Merged

sdf-jkl merged 2 commits into
mainfrom
sdf-jkl/spark-only-paths

Conversation

@sdf-jkl

@sdf-jkl sdf-jkl commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #166.

Variant path arguments now follow Spark 4.2 only. Until now, a path starting with $ used the Spark parser from #143, and anything else fell back to the Arrow VariantPath grammar, with different escaping and with '$type' meaning something else in each dialect. This drops the rootless dialect instead of keeping both.

Query Before After
variant_get(v, 'a.b') field a, then b error: invalid Variant path "a.b": paths start with $, such as $.a[0]``
variant_get(v, '') the whole value error
variant_get(v, p) where p is SQL NULL the whole value SQL NULL, as in Spark
v:a.b, v:['k'] rootless 'a.b', "['k']" '$.a.b', "$['k']", built like Spark's visitSemiStructuredExtract
  • The : operator keeps working and keeps its column names (events.event:name). Since v:a and variant_get(v, '$.a') are now the same expression, both are named v:a.
  • CAST(variant AS type) lowers to variant_get(v, '$', type) instead of ''.
  • The NULL rule applies to variant_get, try_variant_get and variant_get_json, for scalar and column paths. variant_object_keys still rejects a NULL path, as before.
  • Quoted keys after : now keep backslashes, like every other $ path (Spark 4.2). For example, v:["a\b"] selects the field a\b, not ab.

This is a breaking change for anyone using rootless paths: the only release, 0.1.0, predates $ paths. The error message names the fix. Spark-style paths in arrow-rs are tracked in apache/arrow-rs#11627, and the TODO(arrow-rs) on parse_rooted_path drops this crate's parser once that lands.

Most of the diff rewrites rootless paths to $ paths in the SLTs, docs, doctests, CLI tests, JSONBench queries and benches. Tests that compared the two dialects now check that rootless paths are rejected, the \] case that relied on Arrow escaping is gone, and $['a]b'] is no longer skipped. variant_root_paths.slt adds rejection cases for rootless and empty paths, and NULL paths for scalar and column Variants with literal and column paths.

Validation
The grammar, NULL handling and : path building were checked against Spark's v4.2.0 source. cargo test --workspace (unit, SLT, doctests, the docs harness and CLI integration), cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings and cargo bench --bench variant_get -- --test pass. docs/sql-reference.md is regenerated. I did not run sphinx-build, and the docs changes are SQL path literals only.

🤖 Generated with Claude Code

sdf-jkl and others added 2 commits November 12, 2026 14:55
Drop the rootless Arrow path dialect. Paths must start with `$`, as in
Spark 4.2. The `:` operator builds `$` paths the way Spark does, root
casts read `$`, and a SQL NULL path returns SQL NULL.

Closes #166.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep one SLT per rejected-path rule and fold NULL-path coverage into the
existing column-path queries. Each NULL branch, the root cast, and the
`:` prefix still fail the suite when reverted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sdf-jkl
sdf-jkl marked this pull request as ready for review November 12, 2026 22:08
@sdf-jkl
sdf-jkl merged commit db33110 into main Nov 12, 2026
6 checks passed
@sdf-jkl
sdf-jkl deleted the sdf-jkl/spark-only-paths branch November 12, 2026 22:09
sdf-jkl added a commit that referenced this pull request Nov 12, 2026
#187 rejects paths without `$`, returns SQL NULL for a SQL NULL path,
and builds `:` paths the way Spark does. Drop the rootless and
Spark-differences sections, show how `:` builds its path, and fold the
`variant_delete` rule into the syntax section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
SELECT variant_get(data, 'did', 'VARCHAR') AS user_id,
MAX(variant_get(data, 'time_us', 'BIGINT')) / 1000
- MIN(variant_get(data, 'time_us', 'BIGINT')) / 1000 AS activity_span
SELECT variant_get(data, '$.did', 'VARCHAR') AS user_id,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this syntax now looks even worse -- maybe we can switch these to using : syntax

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this syntax now looks even worse

😿

https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.functions.variant_get.html

... a column containing the extraction path strings or a string representing the extraction path. A valid path should start with $ and is followed by zero or more segments like A column that evaluates to a string. [123], .name, [‘name’], or [“name”]. ...

maybe we can switch these to using : syntax

👍 explicit getter invocation is not necessary, just one way of doing it. : is definitely more 👁️ 🍬

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make a PR to do it after this

So we won't mess up performane

alamb added a commit that referenced this pull request Nov 13, 2026
…-variant-get

Adapt the nested getter rewrite to the Spark `$`-only path syntax (#187):
paths are now concatenated textually, and a SQL NULL path is not collapsed
as it returns SQL NULL rather than selecting the root.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
sdf-jkl added a commit that referenced this pull request Nov 18, 2026
* Document the Variant path syntax

Add a "Variant paths" page to the User Guide covering `$` paths,
quoting, the `:` operator, `variant_delete`, rootless paths, and
differences from Spark 4.2. Every claim is checked by the docs harness.

Point the `path` arguments of `variant_get`, `try_variant_get`, and
`variant_delete` at the page instead of repeating the grammar, and
link it from the cookbook's `:` example.

Closes #170.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Update the path docs for `$`-only paths

#187 rejects paths without `$`, returns SQL NULL for a SQL NULL path,
and builds `:` paths the way Spark does. Drop the rootless and
Spark-differences sections, show how `:` builds its path, and fold the
`variant_delete` rule into the syntax section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Trim the path docs

Fold the whole-value and `$.*` checks into the existing hidden query,
and state the `:` rule once with inline examples instead of a table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Explain `:` versus `.` in the path docs

Show that `:` starts a path and `.` continues it, that chaining `:`
runs one lookup per `:` (#176), and that `.` alone is struct field
access. Link JSONPath (RFC 9535) and note that quoted names have no
escapes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Reorganize and trim the path docs

Group the page into syntax, NULLs and errors, and the `:` operator.
Show the `$.http.status` trap in the main example, collect the `:`
pitfalls in one table, pretty-print the example JSON, and merge the
hidden checks into fewer table-driven queries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Drop the chained `:` pitfall from the path docs

#188 fuses nested getters, so `v:a:b` now reads the same path as
`v:a.b` in one lookup. Say so instead of listing it as slower.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Show path doc checks as examples

Hidden checks pinned outputs that readers never saw. Show the quoting,
NULL, and chained `:` results as examples and trim the prose they
replace. Only the expected-error checks stay hidden.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Scope path NULL rules to the getters in the path docs

`variant_delete` leaves the value unchanged for a missing target and
skips a NULL path, so the SQL NULL rule only covers `variant_get`,
`try_variant_get`, and `:`. Also call the syntax "based on" JSONPath,
since `$.*` and `\` differ from RFC 9535, and name the chained `:` example.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Apply suggestion from @alamb

Co-authored-by: Andrew Lamb <[email protected]>

* Address review of the path docs

Add an Escaping section that reuses the `requests` table, and keep the
JSONPath differences with the syntax. Trim NULL handling to missing
paths and link the common pitfalls page, since the function reference
already covers NULL paths and `variant_delete`. Move the failing `:`
forms to common pitfalls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Andrew Lamb <[email protected]>
sdf-jkl added a commit to sdf-jkl/datafusion-variant that referenced this pull request Nov 23, 2026
Scope the page to Spark 4.2.0, drop rows made stale by datafusion-contrib#143, datafusion-contrib#153,
datafusion-contrib#187 and datafusion-contrib#192, link tests with absolute URLs, and add the page to the
docs site and the README note.

Enable field-extraction case 04 (fixed by apache/arrow-rs#11302) and the
empty-key schema_of_variant case (apache/arrow-rs#10352), which pass on
Arrow 60.1.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alamb pushed a commit that referenced this pull request Nov 28, 2026
* Document Spark compatibility differences and their causes

* Rewrite Spark compatibility page for Spark 4.2 and enable fixed cases

Scope the page to Spark 4.2.0, drop rows made stale by #143, #153,
#187 and #192, link tests with absolute URLs, and add the page to the
docs site and the README note.

Enable field-extraction case 04 (fixed by apache/arrow-rs#11302) and the
empty-key schema_of_variant case (apache/arrow-rs#10352), which pass on
Arrow 60.1.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Drop the function list and ask readers to report differences

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify Variant path syntax with Spark, accounting for backward compatibility

2 participants