Skip to content

perf: Collapse nested variant_get calls - #188

Merged
sdf-jkl merged 8 commits into
mainfrom
alamb/collapse-nested-variant-get
Nov 13, 2026
Merged

sdf-jkl merged 8 commits into
mainfrom
alamb/collapse-nested-variant-get

Conversation

@alamb

@alamb alamb commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Chained : access such as

SELECT data:commit:collection ...

Is planned as nested calls like

variant_get(variant_get(data, 'commit'), 'collection')`

This is inefficient as it rebuilds an intermediate Variant instead of reading the shredded column directly

Changes

  1. simplify variant_get / try_variant_get that merges an untyped inner getter into the outer one when possible
v:a:b:c[1]:d  =>  variant_get(v, '$.a.b.c[1].d')

I verified this locally from the issue using the repro from #176:

before after
unshredded 0.57s 0.47s
shredded 2.08s 0.34s
> SELECT data:commit.collection AS event, count() AS count FROM bluesky_shredded GROUP BY event ORDER BY count DESC;
+----------------------------+--------+
| event                      | count  |
+----------------------------+--------+
| "app.bsky.feed.like"       | 444523 |
...
+----------------------------+--------+
511 row(s) fetched. (First 40 displayed. Use --maxrows to adjust)
Elapsed 0.375 seconds.

> SELECT data:commit.collection AS event, count() AS count FROM bluesky GROUP BY event ORDER BY count DESC;
+----------------------------+--------+
| event                      | count  |
+----------------------------+--------+
| "app.bsky.feed.like"       | 444523 |
...
+----------------------------+--------+
511 row(s) fetched. (First 40 displayed. Use --maxrows to adjust)
Elapsed 0.486 seconds.

alamb and others added 6 commits November 12, 2026 18:31
Chained `:` access such as `data:commit:collection` plans to nested
`variant_get` calls, which rebuild the intermediate Variant row by row
instead of reading shredded columns. Add `simplify` to `variant_get` and
`try_variant_get` to merge an untyped inner getter with literal paths
into one getter over the combined path.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…-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]>
@alamb alamb changed the title Collapse nested variant_get calls into a single path perf: Collapse nested variant_get calls into a single path Nov 13, 2026
@alamb alamb changed the title perf: Collapse nested variant_get calls into a single path perf: Collapse nested variant_get calls Nov 13, 2026
@alamb
alamb marked this pull request as ready for review November 13, 2026 02:00
@alamb
alamb requested a review from sdf-jkl November 13, 2026 02:01
Comment thread src/variant_get.rs
///
/// # Background
///
/// A single call is more efficient as it can read shredded columns directly,

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 is the key writeup / function -- I tried to document it as well as I could

Comment thread src/variant_get.rs
}

fn simplify(&self, args: Vec<Expr>, _info: &SimplifyContext) -> Result<ExprSimplifyResult> {
simplify_getter(self, args)

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.

I am quite pleased with how nicely this API works

Comment thread src/variant_path.rs
parse_variant_path(outer, true)?;
// Each element of a valid path starts with `.` or `[`, so the elements of
// `outer` can directly follow those of `inner`.
Ok(format!("{inner}{}", &outer[1..]))

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.

@sdf-jkl , your change to only support spark style made this function quite a bit simpler

@sdf-jkl sdf-jkl 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.

Thanks @alamb. This will be helpful to avoid unnecessary perf degradation.

@sdf-jkl
sdf-jkl merged commit 3dbb436 into main Nov 13, 2026
6 checks passed
@sdf-jkl
sdf-jkl deleted the alamb/collapse-nested-variant-get branch November 13, 2026 04:50
sdf-jkl added a commit that referenced this pull request Nov 13, 2026
Follow-up to #188. Move getter tests into variant_get.slt and path
tests into variant_path.slt, dropping cases that repeat each other or
existing coverage. Restore the usable-Variant check that #188's
collapsing hollowed out, and pin the shredded missing-field and
out-of-bounds behavior chained `:` now shares with single paths
(apache/arrow-rs#11191, apache/arrow-rs#11050).

Co-authored-by: Claude Opus 5.5 <[email protected]>
sdf-jkl added a commit that referenced this pull request Nov 13, 2026
#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 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]>
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.

Reading Shredded variant is slower than unshredded variant

2 participants