Skip to content

fix(arrow/array): support zero-column tables - #988

Merged
zeroshade merged 1 commit into
apache:mainfrom
fallintoplace:fix/zero-column-table
Jul 23, 2026
Merged

fix(arrow/array): support zero-column tables#988
zeroshade merged 1 commit into
apache:mainfrom
fallintoplace:fix/zero-column-table

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

Arrow schemas and record batches may have zero fields while still carrying a logical row count. NewTableFromSlice indexed the first column unconditionally and panicked for an empty schema. NewTableFromRecords inferred 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, sum RecordBatch.NumRows to 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/array
  • go test -race -count=1 ./arrow/array

Are 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.

@fallintoplace
fallintoplace requested a review from zeroshade as a code owner July 23, 2026 00:49
@fallintoplace
fallintoplace force-pushed the fix/zero-column-table branch from f706984 to 41ab7e0 Compare July 23, 2026 00:53
@fallintoplace fallintoplace changed the title fix(arrow/array): support tables without columns fix(arrow/array): support zero-column tables Jul 23, 2026
@fallintoplace
fallintoplace force-pushed the fix/zero-column-table branch from 41ab7e0 to cf0f3a9 Compare July 23, 2026 01:00
@zeroshade

Copy link
Copy Markdown
Member

Under what scenario would we have zero-fields but a non-zero logical row count? That doesn't make sense to me

@fallintoplace

Copy link
Copy Markdown
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 zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@zeroshade
zeroshade merged commit 5327234 into apache:main Jul 23, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants