Skip to content

feat(parquet): add GenericColumnWriter::write_batch_with_uniform_def_level - #12507

Open
eliduvid wants to merge 2 commits into
apache:mainfrom
eliduvid:uniform-def-level-writes
Open

eliduvid wants to merge 2 commits into
apache:mainfrom
eliduvid:uniform-def-level-writes

Conversation

@eliduvid

@eliduvid eliduvid commented Nov 29, 2026 •

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

We write Parquet using the low-level column writer API (GenericColumnWriter), not ArrowWriter. A lot of our columns are mostly empty, with long runs of nulls and runs of values.

With the public API we have to pass a &[i16] of def levels for every row, even when it's 10k zeros in a row. So for a while we've kept a small fork that adds a method for "the next N rows all have def level X".

While looking at upgrading to 60 I noticed #9831 added LevelDataRef::Uniform, which is pretty much the same thing, but it's pub(crate) and only ArrowWriter can use it. This PR adds a small public wrapper on top of it.

If you'd rather make LevelDataRef itself public instead, that works for us too.

What changes are included in this PR?

Adds GenericColumnWriter::write_batch_with_uniform_def_level(values, def_level, num_levels, min, max, distinct_count). It works like write_batch_with_statistics with num_levels copies of def_level and no rep levels, and calls write_batch_internal with LevelDataRef::Uniform.

It returns an error for repeated (list) columns and for def levels outside 0..=max_def_level.

Are these changes tested?

Yes, new tests in column/writer/mod.rs:

  • writing the same runs with the new method and with write_batch_with_statistics gives the same values, def levels, row count and stats (v1 and v2, with runs that split across pages)
  • required column (max_def_level = 0)
  • num_levels = 0
  • errors: repeated column, out-of-range def level, not enough values

Are there any significant user-facing changes?

No. It only adds a new method, nothing existing changes.

AI usage disclosure

I used Claude Code to find the existing LevelDataRef::Uniform path, and it drafted the method, the tests and this description. I reviewed all of it, and the method matches what we've been running in our fork.

cc @HippoBaro since you did #9831

🤖 Generated with Claude Code

@boring-cyborg boring-cyborg Bot added the parquet parquet crate label Nov 29, 2026
@eliduvid
eliduvid force-pushed the uniform-def-level-writes branch from ae6b397 to 20f984a Compare November 29, 2026 15:55

@yonipeleg33 yonipeleg33 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.

nice work, thanks!
(for the maintainers - i'm a colleague of the author)

i'm mainly concerned about future-proofing this new api

max: Option<&E::T>,
distinct_count: Option<u64>,
) -> Result<usize> {
if self.descr.max_rep_level() > 0 {

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.

i wonder if we should add support for repetition level now as part of this pr. repeated columns need repetition level data as well as def levels, so the current method signature can't support them.
adding support for it later would mean either a breaking change (changing the signature of this api), or exposing a separate api just for that - neither seem like a good solution to me.

or at least let's decide on the method signature now and we can keep rejecting repeated columns at runtime, just to leave place for future support without a breaking change?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

  1. I don't think we can support lists with more than one element here. Their first element has rep_level 0 and the rest have 1, so it's never a uniform run.
  2. Splitting it into two calls (first element, then the rest) doesn't work either, because the second call would start in the middle of a row. write_batch_internal() disallows that for a reason: a page can be closed between calls, and pages must start at a row boundary.
  3. What we can and I think should support is rows that are a single slot: null, [[[]]], [[null]], or single-element lists like [42]. That only needs passing rep_level 0 for every slot internally, no API change. If multi-element lists are ever needed, that would be a separate new method, so nothing here would need a breaking change.

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.

good points. let's wait for the maintainers to weigh in on this

Comment thread parquet/src/column/writer/mod.rs Resolved
Comment thread parquet/src/column/writer/mod.rs Resolved
Comment thread parquet/src/column/writer/mod.rs Resolved
eliduvid and others added 2 commits December 2, 2026 00:46
…level

Lets callers of the low-level column writer write a run of levels that
all share one definition level without materializing a `&[i16]` buffer,
using the existing `LevelDataRef::Uniform` path that `ArrowWriter`
already uses.

Errors on repeated columns and on out-of-range definition levels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…evel tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eliduvid
eliduvid force-pushed the uniform-def-level-writes branch from eef39d4 to c2f4ba6 Compare December 1, 2026 22:46

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

parquet parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants