Skip to content

Extract from Variants in bulk and push variant_get into the scan - #11505

Open
robert3005 wants to merge 16 commits into
developfrom
rk/variant-features
Open

robert3005 wants to merge 16 commits into
developfrom
rk/variant-features

Conversation

@robert3005

@robert3005 robert3005 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

This changes how Vortex extracts paths from Variant columns: the variant_get expression, the Parquet Variant encoding and the DataFusion scan. The Arrow export of Variants is unchanged.

Before, a query over a Variant column read the whole column, and DataFusion extracted each path row by row. After, vortex-datafusion converts try_variant_get(variant, '$.a.b', type) to the Vortex variant_get, so the scan extracts the path. Parquet Variant storage extracts scalars, structs and lists from unshredded values in place, and a shredded child answers its paths without reading the core storage. Only paths of plain object fields convert. Plain variant_get stays in DataFusion, because datafusion-variant raises an error when a value does not cast, and the Vortex extraction returns null.

It also adds the pieces that the Variant layout in the next PR uses: the variant_pack expression and decode_unshredded_storage. Canonical shredded storage now keeps object fields whose shell has only a value column, which it used to drop.

Behaviour change: the default BtrBlocks preset now compresses Variant storage with Zstd, so files with Variant columns are written differently.

On 1M unshredded Bluesky rows (single thread), one path extracts in 38–69 ms. A struct of all five JSONBench paths extracts in one pass in 0.71 of the time of five separate extractions. These numbers are from the 16 Nov head.

This is the bottom of a stack: #11814 adds the Variant layout on top of it, and #11390 adds JSONBench on top of that.

🤖 Generated with Claude Code

robert3005 and others added 4 commits November 19, 2026 11:08
- vortex-datafusion converts `variant_get(variant, path, type)` to the
  Vortex expression, so that the scan extracts the path, and folds
  filter equalities into the scan projection.
- `variant_get` brings chunked, masked and other lazy inputs to the
  Variant encodings before it falls back to extracting row by row.
- A shredded Variant child holds the rest of a path. The rows that the
  shredded child does not hold are extracted from the core storage on
  their own and scattered back, so that the core storage is not read when
  none of them holds a value.
- Parquet Variant storage extracts strings and integers from unshredded
  values in place, reads fixed-width integers with a single load, and
  resolves field names to ids once per metadata.
- Add `decode_unshredded_storage`, which decodes the storage of an
  unshredded Variant once for many extractions.
- Add the `variant_pack` expression, which packs core storage and a
  shredded child into a Variant. `variant_get` reads a shredded path from
  its shredded child without reading the core storage.
- `CascadingCompressor` can compress the storage of Variant arrays with
  another compressor. The default BtrBlocks preset uses one that keeps the
  binary Zstd scheme, since unshredded values are opaque binary blobs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Robert Kruszewski <github@robertk.io>
The in-place extraction turned the whole column down at the first row
whose value it could not read as is, such as a JSON null or an integer at
a string path. The general kernel then extracted every row again.

Such a value now converts with the `Variant` method that the general
kernel converts it with, `as_string` or `as_int64`, and a value that does
not convert is a null. Objects and arrays convert to neither, so they
are null without being decoded. The extraction falls back to the general
kernel only for bytes that do not decode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Robert Kruszewski <github@robertk.io>
The in-place extraction covered strings and 64-bit integers. A struct or
a list target went to the general kernel, which builds an Arrow array of
the storage and a `Variant` over every row.

The extraction is now a tree of builders, one for each node of the
target dtype. A struct reads the object at the path once and each of its
fields from the object's field of the same name, so it extracts several
paths in one pass. A list reads each element of the array at the path. A
value that is not an object or an array is a null, as it is for the
general kernel. Field names of every struct in the target resolve to
dictionary ids once per metadata, as the names of the path do.

Structs and lists are covered when their fields and elements are
nullable and covered themselves. A struct without fields is left to the
general kernel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Robert Kruszewski <github@robertk.io>
When the requested type was not the type of the shredded leaf, the
Variant kernel extracted the path from the core storage. The core storage
holds no value of a row that the shredded child holds, so all such rows
were null. An INT extraction over the I64 leaf that inferred shredding
writes, or a BIGINT extraction over an I32 leaf, returned only nulls.

The typed values now convert to the requested type, as a single value
converts in the general path: a value that does not convert is a null.
The kernel reads the core storage only for the rows that the shredded
child does not hold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Robert Kruszewski <github@robertk.io>
@robert3005 robert3005 added the changelog/feature A new feature label Nov 22, 2026
@lwwmanning

Copy link
Copy Markdown
Contributor

Posted by Claude Opus 5.5 on Will's behalf. This is from a review of the open PR backlog.

The bulk extraction and the variant_get pushdown are the point of this PR, but at 2,540 added lines it also carries code that only the next PR in the stack needs. Robert, if you agree, @devin-ai-integration can make these changes:

  1. Move variant_pack (the expression, the VariantPack scalar function, and the variant_get branch that reads through it) and decode_unshredded_storage into the Variant layout PR that produces them. In this PR, only tests call them.
  2. Move the BtrBlocks change that keeps Zstd for Variant storage into its own PR. It changes how every file with a Variant column is written, and adds a second compressor to CascadingCompressor, so it needs its own compress-bench result.

What stays is the extraction kernels and the DataFusion conversion, which is the change the description leads with.

@lwwmanning

Copy link
Copy Markdown
Contributor

Posted by Claude Opus 5.5 on Will's behalf.

@devin-ai-integration, Will withdraws my earlier request to move the BtrBlocks Zstd change for Variant storage into its own PR. Keep it in this PR, and do not open a separate PR for it. The other review points still stand.

@lwwmanning

Copy link
Copy Markdown
Contributor

Posted by Claude Opus 5.5 on Will's behalf.

@devin-ai-integration, Will withdraws my request to move variant_pack and decode_unshredded_storage to the layout PR. Keep them here, and keep the BtrBlocks Zstd change for Variant in this PR too. Please:

  1. Fix the description. It says the PR adds InferredShredding, but nothing in the diff defines it. Remove that name or add what it refers to.
  2. Mark the PR ready for review.

Will will ask Joe Isaacs to review it.

@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review November 22, 2026 23:22
devin-ai-integration[bot]

This comment was marked as resolved.

@codspeed

codspeed Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

✅ 1089 untouched benchmarks
⏩ 1069 skipped benchmarks1


Comparing rk/variant-features (984a9cf) with develop (758dde7)

Open in CodSpeed

Footnotes

  1. 1069 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Deduplicating scan projections by Vortex expression alone collapsed columns with
different planned Arrow layouts (such as Utf8 and Utf8View), causing schema
mismatches on output batches. Include the planned output DataType in the
deduplication key.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
…t_get

Defer partially shredded struct/list extraction and remaining paths through
shredded lists to scalar extraction, recursively cast Variant struct/list
scalars, normalize nullable Variant list elements, and execute filtered
shredded list/struct values before converting Parquet Variant metadata.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
devin-ai-integration[bot]

This comment was marked as resolved.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
…ariant casts

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
devin-ai-integration[bot]

This comment was marked as resolved.

…ariant nulls in casts

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
devin-ai-integration[bot]

This comment was marked as resolved.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
devin-ai-integration[bot]

This comment was marked as resolved.

@lwwmanning

Copy link
Copy Markdown
Contributor

Posted by Claude Opus 5.5 on Will's behalf.

@devin-ai-integration, please make these fixes in this PR, and nothing else:

  1. Path syntax in convert_variant_get (vortex-datafusion/src/convert/exprs/mod.rs). datafusion-variant's path parser requires a leading $ (parse_variant_path in its src/variant_path.rs). The converter does the opposite: $ fails the is_field check, so a valid $.a.b path never pushes down, and a bare a.b path, which DataFusion rejects with an error, is pushed down and returns rows. Convert only paths of the form $.field(.field)*, strip the $., and leave every other path unconverted. Update variant_get_expr and its tests to use $. paths, and add a test that a bare path is not converted.
  2. Failed casts. datafusion-variant's variant_get raises an error when a value does not convert to the requested type (CastOptions { safe: false }), and only try_variant_get returns null. The Vortex extraction returns null. Convert try_variant_get only, and leave variant_get in DataFusion. Fix the doc comment on convert_variant_get, which says both return null.
  3. VariantGet::reduce (vortex-functions/src/variant_get/mod.rs) reads only child(1) of a VariantPack. With shredded_validity, child(1) is a non-nullable struct and the row validity is child(2). For the root path with a struct output, reduce returns Cast(child(1)), so a row that child(2) marks null comes back as a valid struct of nulls. When the pack has a validity child, return None at the root path, or mask with child(2). Add a test with validity [true, false] that checks row 1 is null.

Do not act on new Devin Review findings in this PR. Leave them as comments for Will.

…hredded validity

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Applied all three fixes in 7f59b2cab:

  1. convert_variant_get now requires $-rooted paths ($.field(.field)*), strips $., leaves bare and other paths unconverted, and updates variant_get_expr + tests (including a bare-path test).
  2. convert_variant_get now converts try_variant_get only (leaving strict variant_get in DataFusion) and updates its doc comment + tests.
  3. VariantGet::reduce skips root-path reduction when VariantPack carries shredded_validity, with a [true, false] validity regression test checking row 1 is null.

Left the new Devin Review findings untouched as requested.

devin-ai-integration[bot]

This comment was marked as resolved.

Restore the Arrow export to develop's version. Exporting non-null
constant Variants and shredded overrides is a gap that develop already
has, and nothing in this PR produces such arrays, so it moves to its own
PR.

Canonicalize shredded lists from a ListArray, and give each element its
row's metadata from the list offsets, as the Variant layout PR does. This
replaces the special case for list views that share elements.

Keep object fields whose shell has only a `value` column. The shredding
spec stores such a field's value in its shell, not in the parent
residual, so dropping it lost the value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Will Manning <will@spiraldb.com>
A Vortex cast does not convert numbers to Booleans, so variant_get
returned null for a shredded number read as a Boolean, while the
unshredded path follows Arrow and reads zero as false and other numbers
as true.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Will Manning <will@spiraldb.com>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 2 new potential issues.

6 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment thread encodings/parquet-variant/src/array.rs Resolved
Comment thread encodings/parquet-variant/src/kernel.rs Resolved
The fallback that converts a shredded number to a Boolean took only a
plain number. A partially shredded field holds its values as nested
Variants, and the scalar path that converts unread values ended in a
Vortex cast, so in both cases a number read as a Boolean was null,
where Arrow's `Variant::as_boolean` returns whether it is not zero.
`number_as_bool` now unwraps a Variant, and the scalar path falls back
to it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Will Manning <will@spiraldb.com>
lwwmanning added a commit that referenced this pull request Nov 23, 2026
#11505 now converts only `try_variant_get` with a `$.` path to the Vortex
`variant_get`, as datafusion-variant parses paths from `$` and raises an
error from `variant_get` when a value does not cast. The stand-in that
datafusion-bench registers was `variant_get` with bare paths, so its
queries no longer pushed down. It is now `try_variant_get`, it takes
paths from `$.`, and the DataFusion queries call it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Will Manning <will@spiraldb.com>
… Arrow does

A canonicalized chunk of unshredded Variants pads the shredded child with
nulls, so an extraction through a nested Variant child lost the values that
only the core storage holds. Rows without the nested child now read the core
storage, as rows without a typed leaf already did.

The shredded and row-by-row paths also read strings as Booleans with the
spellings that Arrow's Variant conversion accepts, so shredding a string field
does not change what a Boolean extraction returns.

Signed-off-by: Robert Kruszewski <github@robertk.io>
Signed-off-by: Robert Kruszewski <github@robertk.io>
lwwmanning added a commit that referenced this pull request Nov 23, 2026
Develop moved the scalar functions out of vortex-array into
vortex-functions (#10762). The Variant layout was written before that
move, so this ports it: `variant_shred` and its strict and union forms
are registered by vortex-functions, the `variant_shred` expression is in
`vortex_functions::expr`, and `decode_for_repeated_extraction` moves next
to `variant_get`, because vortex-array cannot name `VariantGet`.

It also drops a second copy of `element_metadata` in the Parquet Variant
array, which the rebase onto #11505 left behind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Will Manning <will@spiraldb.com>
lwwmanning added a commit that referenced this pull request Nov 23, 2026
#11505 now converts only `try_variant_get` with a `$.` path to the Vortex
`variant_get`, as datafusion-variant parses paths from `$` and raises an
error from `variant_get` when a value does not cast. The stand-in that
datafusion-bench registers was `variant_get` with bare paths, so its
queries no longer pushed down. It is now `try_variant_get`, it takes
paths from `$.`, and the DataFusion queries call it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Will Manning <will@spiraldb.com>
@lwwmanning
lwwmanning added this pull request to stack #11820 November 23, 2026 13:13
@robert3005

Copy link
Copy Markdown
Contributor Author

extracted #11843 #11844 #11845 #11846

@robert3005

Copy link
Copy Markdown
Contributor Author

and further in #11850 #11851 #11852 #11853

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants