Skip to content

Let file writers choose a shredding schema for each Variant column - #12524

Open
robert3005 wants to merge 6 commits into
rk/variant-layoutfrom
rk/variant-shredding
Open

robert3005 wants to merge 6 commits into
rk/variant-layoutfrom
rk/variant-shredding

Conversation

@robert3005

Copy link
Copy Markdown
Contributor

The Variant layout stores shredded fields as separate columns, but the file writer can only keep the shredding that the input already has. This PR adds WriteStrategyBuilder::with_variant_shredding, which takes a VariantShreddingPolicy. The writer asks the policy for a schema once per Variant column, with the column's field path. The policy can return a fixed schema, choose by path, or infer a schema from a bounded sample of rows. The sample can span input chunks, so a small first batch does not decide the schema alone. The writer then sends matching values to typed children through the new vortex.variant_shred function, and the storage encoding supplies the kernel. Parquet Variant has one kernel and an inferring policy. Input that is already shredded keeps its schema. If the edition does not allow the Variant layout, the policy is not used.

Stacked on #12247

🤖 Generated with Claude Code

Give a policy the logical field path and the first nonempty unshredded
batch. Reuse its decision for the column stream and let the encoding
move matching values into typed children. Preserve incoming shredding
and use the Variant layout to group consecutive compatible batches.

Signed-off-by: Will Manning <will@spiraldb.com>
Signed-off-by: Robert Kruszewski <github@robertk.io>
Let the policy request a bounded prefix of unshredded rows for each logical column. Replay buffered input in order so a small leading batch cannot determine the schema by itself. Fixed and path-based policies can choose a schema immediately.

Signed-off-by: Robert Kruszewski <github@robertk.io>
Signed-off-by: Robert Kruszewski <github@robertk.io>
Develop replaced SizeScope with Backpressure. Sampled Variant chunks now reserve pending bytes through it.

Signed-off-by: Robert Kruszewski <github@robertk.io>
@robert3005 robert3005 added the changelog/feature A new feature label Dec 1, 2026
@vortex-roborev-bot

vortex-roborev-bot Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

roborev: Combined Review (ae69a9f)

Verdict: Changes require fixes for 1 finding.

High

  • vortex-layout/src/layouts/variant/writer.rs:138-150: Replayed sample chunks can join the open run with sequence IDs that come after that run's run_eof. sample_eof is split from eof only after the open run has taken its run_eof (line 176), and active stays set after the continue. A data segment collapse() then waits on an EOF that the same writer still holds, so the write probably deadlocks.
InferredShredding: [ConstantArray chunk, small ParquetVariant chunk, no common fields]

Existing tests don't cover this case.

Fix: Set active = None right after stream = replay; so replayed chunks start a new run, and add a regression test (leading constant or pre-shredded chunk, then a sample that reaches EOF with the same shredding) that checks the write finishes and the values round-trip.


Reviewers: claude-code | Synthesis: claude-code, 9s, ~$0.07 | Total: 2m11s, ~$0.76

@vortex-roborev-bot vortex-roborev-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Line comments for the roborev review of 7ae2964. The roborev PR comment has the full review.

Comment on lines +151 to +156
if let Some(schema) = &schema {
variant =
VariantShred::try_new(variant.core_storage().clone(), schema.clone())?
.into_array()
.execute::<VariantArray>(&mut exec)?;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Medium: Once a schema is chosen, every unshredded chunk is passed to VariantShred::try_new, but only Parquet Variant registers a shred kernel. A constant Variant chunk canonicalizes to VariantArray(core = Constant), so VariantShred::execute fails with "has no kernel to shred it" and the whole write fails. Without a policy, the same input is written fine as an unshredded run.

// ParquetVariant chunk, then:
ConstantArray::new(Scalar::null(DType::Variant(Nullable)), n)

Fix: Skip shredding for chunks whose storage has no shred kernel and send them to the unshredded fallback run, but still return errors from supported kernels. Add a round-trip test with FixedShredding/InferredShredding on the mixed stream above.

Signed-off-by: Robert Kruszewski <github@robertk.io>
Route unshredded Variant chunks without a VariantShred kernel to the fallback writer instead of failing the write, split sample EOF pointers lazily when buffering across chunks, and avoid inferring struct schemas over mixed scalar-and-object paths.

Signed-off-by: Robert Kruszewski <github@robertk.io>

@vortex-roborev-bot vortex-roborev-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Line comments for the roborev review of ae69a9f. The roborev PR comment has the full review.

Comment on lines +138 to +150
let sample_eof = eof.split_off();
let (sample, replay) = sample_prefix(
chunk,
rows,
stream,
sample_eof,
ctx.backpressure(),
&mut exec,
)
.await?;
schema = policy.schema(column, &sample, &mut exec)?;
stream = replay;
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

High: Replayed sample chunks can join the open run with sequence IDs that come after that run's run_eof. sample_eof is split from eof only after the open run has taken its run_eof (line 176), and active stays set after the continue. A data segment collapse() then waits on an EOF that the same writer still holds, so the write probably deadlocks.

InferredShredding: [ConstantArray chunk, small ParquetVariant chunk, no common fields]

Existing tests don't cover this case.

Fix: Set active = None right after stream = replay; so replayed chunks start a new run, and add a regression test (leading constant or pre-shredded chunk, then a sample that reaches EOF with the same shredding) that checks the write finishes and the values round-trip.

@codspeed

codspeed Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 15.4%

⚡ 1 improved benchmark
❌ 10 regressed benchmarks
✅ 1834 untouched benchmarks
⏩ 478 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ append_to_varbin_builder[view/dict/nullable] 3.4 ms 4.2 ms -18.79%
❌ string_export[offset/view/dict/nullable] 3.4 ms 4.2 ms -18.7%
❌ append_to_varbin_builder[offset/dict/nullable] 3.5 ms 4.3 ms -18.34%
❌ string_export[offset/offset/dict/nullable] 3.5 ms 4.3 ms -18.24%
❌ append_to_varbin_builder[onpair/dict/nullable] 3.6 ms 4.4 ms -17.96%
❌ string_export[offset/onpair/dict/nullable] 3.6 ms 4.4 ms -17.88%
❌ append_to_varbin_builder[fsst/dict/nullable] 3.7 ms 4.4 ms -17.65%
❌ string_export[offset/fsst/dict/nullable] 3.7 ms 4.5 ms -17.57%
❌ append_to_varbin_builder[zstd/dict/nullable] 4 ms 4.8 ms -16.27%
❌ string_export[offset/zstd/dict/nullable] 4.1 ms 4.8 ms -16.22%
⚡ null_count_run_end[(32000, 256, 0.01)] 8.7 µs 7.8 µs +12.39%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing rk/variant-shredding (ae69a9f) with rk/variant-layout (bb2de4e)2

Open in CodSpeed

Footnotes

  1. 478 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. ↩

  2. No successful run was found on rk/variant-layout (621dac1) during the generation of this report, so 265388e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

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.

1 participant