Skip to content

Document the Variant path syntax - #186

Merged
sdf-jkl merged 12 commits into
mainfrom
sdf-jkl/path-syntax-docs
Nov 18, 2026
Merged

sdf-jkl merged 12 commits into
mainfrom
sdf-jkl/path-syntax-docs

Conversation

@sdf-jkl

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

Copy link
Copy Markdown
Collaborator

Closes #170.

As @alamb suggested on #143, this adds a "Variant paths" page (docs/paths.md) to the User Guide, after Getting started. Until now the path rules were packed into the path argument of variant_get in the SQL reference, and the : and variant_delete rules only lived in tests. The page describes the $-only paths from #187.

The page covers:

  • The Spark 4.2 syntax, which is based on JSONPath (RFC 9535): $, .name, ['name'] or ["name"], and [n]. Paths have no wildcards, slices, filters, negative indexes, or recursive descent, so $.* selects a field named *.
  • Escaping: quote names that contain . or [, such as $["http.status"]. \ inside quotes is an ordinary character.
  • Missing and invalid paths: a missing path returns NULL, with a link to the common pitfalls section on SQL NULL and Variant null. An invalid path raises an error, including paths without $, [*], .., and negative indexes. variant_delete also rejects $ alone.
  • The : operator: request:user.roles[0] reads $.user.roles[0] and request:['http.status'] reads $['http.status']. v:a:b reads the same path as v:a.b (perf: Collapse nested variant_get calls #188 fuses them), and backtick-quoted names return SQL NULL for now (Spark 4.2 Variant parity #141).

Common pitfalls gains a section on : forms that fail. v.a without : is struct field access on the Variant's storage, and v:user-agent subtracts a column named agent.

The path arguments of variant_get, try_variant_get, and variant_delete now link to the page instead of repeating the grammar, and docs/sql-reference.md is regenerated. The cookbook's : example links it too.

An untyped NULL literal path, as in variant_get(v, NULL), currently fails with expected binary scalar value, got data type: Null. A typed NULL path returns SQL NULL.

Validation
Every example on the page runs as a test with its output shown, and the error cases are hidden expected-error checks, so cargo test --test readme runs 8 blocks on the new page and checks 11 results. cargo test, cargo fmt --all -- --check, cargo clippy -- -D warnings, and sphinx-build -W --keep-going with the pinned docs/requirements.txt pass.

🤖 Generated with Claude Code

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]>
sdf-jkl added a commit to sdf-jkl/datafusion-variant that referenced this pull request Nov 12, 2026
@alamb

alamb commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

hit me up when this is ready for review

sdf-jkl and others added 3 commits November 12, 2026 17:12
# Conflicts:
#	docs/sql-reference.md
#	src/variant_get.rs
#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]>
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]>
sdf-jkl added a commit to sdf-jkl/datafusion-variant that referenced this pull request Nov 12, 2026
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]>
sdf-jkl added a commit to sdf-jkl/datafusion-variant that referenced this pull request Nov 13, 2026
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]>
sdf-jkl added a commit to sdf-jkl/datafusion-variant that referenced this pull request Nov 13, 2026
sdf-jkl and others added 2 commits November 13, 2026 15:57
#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]>
sdf-jkl added a commit to sdf-jkl/datafusion-variant that referenced this pull request Nov 13, 2026
@sdf-jkl sdf-jkl mentioned this pull request Nov 13, 2026
8 of 35 tasks
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]>
sdf-jkl added a commit to sdf-jkl/datafusion-variant that referenced this pull request Nov 14, 2026
@sdf-jkl
sdf-jkl marked this pull request as ready for review November 14, 2026 01:48
@sdf-jkl

sdf-jkl commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator Author

@alamb PTAL

@alamb

alamb commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

I am sorry I didn't get this tonight. I will try again tomorrow

@sdf-jkl

sdf-jkl commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

No worries!

`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]>

@alamb alamb left a comment

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.

Seems like a major improvement to me -- thank you @sdf-jkl ❤️ 📖

My biggest overall suggestion is to (eventually) move the path parsing documentation to the parquet-variant crate so it stays alongside the parsing logic and thus stays in sync with the code.

When that happens, we can leave a very brief intro on this page and then refer to the docs.rs page for details like escaping, nulls, etc

Comment thread docs/paths.md
steps:

| Step | Selects |
|--------------------------|--------------------------------------------------------------------------------|

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 is a really nice explanation

Comment thread docs/paths.md
+----+-------------+--------+---------------+
```

`$.http.status` looks for a field `status` inside an object `http`, so quote a

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 thought the spark JSON parsing was JSON path. If that is the case, this section may be outdated.

If we want to keep it, I found this sentence a little hard to parse on the first read

It might be clearer if we

  1. Added a new header like "Escaping"
  2. Used an example from above (that already has a field named http.status) rather than a whole new set input

Comment thread docs/paths.md Outdated

## NULLs and errors

In `variant_get`, `try_variant_get`, and `:`, a path that does not match the

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 seems like it might be better as documentation on the variant_get / varient_delete functions -- it isn't really about path syntax

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.

maybe we could just show that "accessing a variant value via a path that doesn't exist returns a Null" -- and we can then document null handling if needed

This example is also somewhat duplicative wiht https://datafusion-contrib.github.io/datafusion-variant/cookbook/common-pitfalls.html#tell-sql-null-from-variant-null so maybe we could just point readers there

Comment thread docs/paths.md
+-----------------+-------+
```

Field names are case-sensitive, so `$.User` does not match `user`, and a field

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.

👍

Comment thread docs/paths.md Resolved
Comment thread docs/paths.md Outdated
```
-->

These forms fail:

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.

maybe this would be better in the "common pitfalls" section too

@sdf-jkl

sdf-jkl commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

My biggest overall suggestion is to (eventually) move the path parsing documentation to the parquet-variant crate so it stays alongside the parsing logic and thus stays in sync with the code.

👍 let's keep it here till the next arrow-rs release that should have apache/arrow-rs#12247 (comment)

sdf-jkl and others added 2 commits November 18, 2026 14:55
Co-authored-by: Andrew Lamb <[email protected]>
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]>
@sdf-jkl

sdf-jkl commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @alamb 🙏

@sdf-jkl
sdf-jkl merged commit ae72ddb into main Nov 18, 2026
5 checks passed
@sdf-jkl
sdf-jkl deleted the sdf-jkl/path-syntax-docs branch November 18, 2026 20:03
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.

Add supported variant path to the docs

2 participants