fix(encoding): emit NIL control words when rep/def levels are non-empty but zero-width - #9018
Open
lichuang wants to merge 1 commit into
Open
fix(encoding): emit NIL control words when rep/def levels are non-empty but zero-width#9018lichuang wants to merge 1 commit into
lichuang wants to merge 1 commit into
Conversation
…ty but zero-width, matching the decoder and preventing full-zip stream corruption
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The zero-width guard restores the full-zip writer/parser invariant: (bits_rep, bits_def) = (0, 0) now emits the NIL representation existing readers already consume, avoiding phantom bytes while preserving the stable 2.1 layout. Centralizing this in the control-word iterator is preferable to widening redundant all-valid definition levels or adding decoder ambiguity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The structural full-zip encoder wrote one all-zero control-word byte per item for pages whose rep/def level buffers are non-empty but have a computed bit width of zero, while the decoder reads such a zero-bit layout as NIL (zero bytes per control word). The mismatch interleaves phantom bytes into the zipped value stream and corrupts every value that follows.
This adds a zero-width early return in
build_control_word_iterator: whentotal_width == 0(i.e.max_rep == 0 && max_def == 0), emitControlWordIterator::Nilaryregardless of which level buffers are present, so the writer agrees with the decoder's NIL interpretation.Root cause
encode_full_zip(rust/lance-encoding/src/encodings/logical/primitive.rs) computesmax_rep/max_deffrom the per-page sliced level buffers, not the schema. When a page's levels are all zero (e.g. a page holding only valid rows of a nullable column after page splitting),total_width == 0and the layout metadata recordsbits_rep = 0, bits_def = 0. The decoder reconstructsControlWordParser::new(0, 0)→NIL(bytes_per_word() == 0), but the writer selected its branch purely on buffer presence, producing aUnary8/Binary8writer that emits one0x00byte per item (bytes_per_word() == 1). In the full-zip layout control words and values are interleaved per item, so the decoder's 0-byte step mis-aligns the value stream by one byte per item.