Consistent schema handling, zero-col projections, and shared traits for record batch builders#160
Merged
nvictus merged 2 commits intoabdenlab:mainfrom Mar 4, 2026
Merged
Conversation
Store the Arrow schema once at construction time (as SchemaRef) and use RecordBatch::try_new() with the stored schema in finish(), instead of RecordBatch::try_from_iter() which inferred a new schema from arrays. This fixes schema mismatches where nullability or metadata could diverge between the declared schema and the batch schema. Also track row_count in each builder to support zero-column batches via RecordBatch::try_new_with_options(), enabling row-counting use cases like SELECT COUNT(*) when no columns are projected. Applies to all 7 BatchBuilder implementations: sequence, alignment, bed, gxf, variant, bbi/base, and bbi/zoom.
Extract the duplicated Push<T> trait definition and the common schema()/finish() interface from all 7 BatchBuilder structs into a shared `batch` module. Each concrete BatchBuilder now implements the RecordBatchBuilder trait (for schema/finish) and crate::batch::Push<T> (for record ingestion) instead of defining its own local copies.
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.
Introduced a
batchmodule withRecordBatchBuilderandPush<T>traits, replacing 7 identical local trait definitions. All concrete builders implement these shared traits.All 7 BatchBuilder structs now compute the Arrow schema once at construction and reuse it in
finish()viaRecordBatch::try_new(). Previously,finish()usedtry_from_iter()which inferred a new schema from the arrays, causing mismatches (nullability, dictionary metadata).Zero-column batches now correctly preserve row counts via
try_new_with_options().