fix: Preserve numRows for zero-column RecordBatch in IPC#402
Open
rustyconover wants to merge 1 commit intoapache:mainfrom
Open
fix: Preserve numRows for zero-column RecordBatch in IPC#402rustyconover wants to merge 1 commit intoapache:mainfrom
rustyconover wants to merge 1 commit intoapache:mainfrom
Conversation
Contributor
Author
|
@raulcd can you please trigger the CI? |
e6e5d97 to
a829ad9
Compare
When a zero-column RecordBatch is deserialized from IPC, ensureSameLengthData in the RecordBatch constructor recomputes length from children via chunks.reduce((max, col) => Math.max(max, col.length), 0). With zero children, this always returns 0 — discarding the original length from the IPC message header. Pass this.data.length to ensureSameLengthData as the explicit maxLength parameter, which the function already accepts as an optional third argument. For batches with columns, this.data.length already matches the max column length, so there is no behavior change. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
a829ad9 to
bc6f6eb
Compare
kou
reviewed
Mar 5, 2026
Member
There was a problem hiding this comment.
Can we create this file by our writer in test instead of adding this file to the repository?
There was a problem hiding this comment.
Pull request overview
Fixes Arrow JS RecordBatch construction so that zero-column batches preserve numRows when deserialized from IPC, matching other Arrow implementations and the IPC message header.
Changes:
- Pass
this.data.lengthas the explicitmaxLengthtoensureSameLengthData()in the[Schema, Data]RecordBatchconstructor path. - Add unit tests covering PyArrow interop, JS IPC round-trip, and direct constructor behavior for zero-column batches.
- Add a PyArrow-generated IPC stream fixture containing a zero-column
RecordBatchwith 100 rows.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/recordbatch.ts |
Preserves parent Data.length when normalizing children, fixing zero-column length loss. |
test/unit/ipc/reader/zero-column-batch-tests.ts |
Adds regression tests to ensure numRows stays correct across read/write and direct construction. |
test/data/zero_column_batch.arrow |
Adds a PyArrow-generated IPC fixture for interop/regression testing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
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
When a zero-column RecordBatch is deserialized from IPC,
ensureSameLengthDatain the
RecordBatchconstructor recomputes length from children viachunks.reduce((max, col) => Math.max(max, col.length), 0). With zero children,this always returns 0 — discarding the original length from the IPC message header.
Other Arrow implementations (PyArrow, Arrow Go, arrow-rs) correctly preserve
numRows for zero-column batches.
Fix
Pass
this.data.lengthtoensureSameLengthDataas the explicitmaxLengthparameter, which the function already accepts as an optional third argument.
For batches with columns,
this.data.lengthalready matches the max columnlength, so there is no behavior change.
Tests
Closes #401