fix(arrow/array): support zero-column tables - #988
Merged
Conversation
fallintoplace
force-pushed
the
fix/zero-column-table
branch
from
July 23, 2026 00:53
f706984 to
41ab7e0
Compare
fallintoplace
force-pushed
the
fix/zero-column-table
branch
from
July 23, 2026 01:00
41ab7e0 to
cf0f3a9
Compare
Member
|
Under what scenario would we have zero-fields but a non-zero logical row count? That doesn't make sense to me |
Contributor
Author
|
The concrete case is projecting or removing all columns while retaining row cardinality. Arrow models the record batch length independently from its fields, so a zero-column batch can still represent N rows. Arrow Go already supports constructing, filtering, serializing, and reading those batches. |
zeroshade
approved these changes
Jul 23, 2026
zeroshade
left a comment
Member
There was a problem hiding this comment.
It's an odd case, but having a clear behavior instead of a panic is still an improvement. Given it's a pretty small change, I'm okay with it.
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.
Rationale for this change
Arrow schemas and record batches may have zero fields while still carrying a logical row count.
NewTableFromSliceindexed the first column unconditionally and panicked for an empty schema.NewTableFromRecordsinferred rows from columns, so zero-column record batches lost their row counts.What changes are included in this PR?
Handle the empty column slice without indexing
cols[0]. When the schema has no fields, sumRecordBatch.NumRowsto preserve the logical row count. Tables with columns keep the existing column-based row inference. Regression tests cover both constructors.Are these changes tested?
Yes:
go test ./arrow/arraygo test -race -count=1 ./arrow/arrayAre there any user-facing changes?
Zero-column table construction no longer panics, and zero-column record batches retain their logical row counts. Existing behavior for tables with columns is unchanged.