Repository navigation
Document the Variant path syntax - #186
Conversation
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
hit me up when this is ready for review |
# 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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
#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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@alamb PTAL |
|
I am sorry I didn't get this tonight. I will try again tomorrow |
|
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
left a comment
There was a problem hiding this comment.
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
| steps: | ||
|
|
||
| | Step | Selects | | ||
| |--------------------------|--------------------------------------------------------------------------------| |
There was a problem hiding this comment.
this is a really nice explanation
| +----+-------------+--------+---------------+ | ||
| ``` | ||
|
|
||
| `$.http.status` looks for a field `status` inside an object `http`, so quote a |
There was a problem hiding this comment.
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
- Added a new header like "Escaping"
- Used an example from above (that already has a field named
http.status) rather than a whole new set input
|
|
||
| ## NULLs and errors | ||
|
|
||
| In `variant_get`, `try_variant_get`, and `:`, a path that does not match the |
There was a problem hiding this comment.
this seems like it might be better as documentation on the variant_get / varient_delete functions -- it isn't really about path syntax
There was a problem hiding this comment.
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
| +-----------------+-------+ | ||
| ``` | ||
|
|
||
| Field names are case-sensitive, so `$.User` does not match `user`, and a field |
| ``` | ||
| --> | ||
|
|
||
| These forms fail: |
There was a problem hiding this comment.
maybe this would be better in the "common pitfalls" section too
👍 let's keep it here till the next arrow-rs release that should have apache/arrow-rs#12247 (comment) |
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]>
|
Thanks @alamb 🙏 |
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 thepathargument ofvariant_getin the SQL reference, and the:andvariant_deleterules only lived in tests. The page describes the$-only paths from #187.The page covers:
$,.name,['name']or["name"], and[n]. Paths have no wildcards, slices, filters, negative indexes, or recursive descent, so$.*selects a field named*..or[, such as$["http.status"].\inside quotes is an ordinary character.$,[*],.., and negative indexes.variant_deletealso rejects$alone.:operator:request:user.roles[0]reads$.user.roles[0]andrequest:['http.status']reads$['http.status'].v:a:breads the same path asv:a.b(perf: Collapse nestedvariant_getcalls #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.awithout:is struct field access on the Variant's storage, andv:user-agentsubtracts a column namedagent.The
patharguments ofvariant_get,try_variant_get, andvariant_deletenow link to the page instead of repeating the grammar, anddocs/sql-reference.mdis regenerated. The cookbook's:example links it too.An untyped NULL literal path, as in
variant_get(v, NULL), currently fails withexpected 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 readmeruns 8 blocks on the new page and checks 11 results.cargo test,cargo fmt --all -- --check,cargo clippy -- -D warnings, andsphinx-build -W --keep-goingwith the pinneddocs/requirements.txtpass.🤖 Generated with Claude Code