Skip to content

fix(ArrowBuilder): correct null bit checking logic and add tests#181

Open
maltzsama wants to merge 1 commit into
apache:mainfrom
maltzsama:fix/basebufferbuilder-isnull
Open

fix(ArrowBuilder): correct null bit checking logic and add tests#181
maltzsama wants to merge 1 commit into
apache:mainfrom
maltzsama:fix/basebufferbuilder-isnull

Conversation

@maltzsama

Copy link
Copy Markdown
Contributor

What's Changed

BaseBufferBuilder.isNull(_:) was returning the inverse of the null state. When append() writes a non-null value, it calls setBit; when writing null, it calls clearBit. So a set bit means valid. The function was returning isSet(), which means it reported valid values as null and null values as valid.

This fix removes the inverted logic and aligns with ArrowData.isNull(), which correctly uses !isSet().

Removed redundant ListBufferBuilder.isNull() override that is now identical to the base implementation.

Testing

Added comprehensive unit tests covering:

  • Single null and non-null values
  • Multiple mixed nulls and values
  • All-null cases
  • All-non-null cases

All 7 new tests pass. Existing test suite continues to pass.

Impact

No code inside the library calls the builders' isNull — all internal readers go through ArrowData.isNull — so this affects external users of the public builder API only.

Closes #180

- Fix `isNull` logic in `BaseBufferBuilder`: return true when the null bit
  is *not* set, instead of checking `nulls.length == 0` or the bit being set.
  This correctly identifies null values.
- Remove redundant `isNull` override in `ListBufferBuilder`, as the base
  implementation now works correctly.
- Add comprehensive tests for `isNull` behavior across all builder types:
  - FixedBufferBuilder (Int32, Double, Int8, UInt64)
  - BoolBufferBuilder
  - VariableBufferBuilder
  - Scenarios: all nulls, no nulls, mixed, multiple nulls
- Add `.vscode/` to .gitignore.

This fixes a bug where null values could be incorrectly reported as non-null
when the nulls buffer was empty, and ensures consistent behavior across all
Arrow buffer builders.
@kou

kou commented Jul 25, 2026

Copy link
Copy Markdown
Member

@willtemperley Could you review this?

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.

BaseBufferBuilder.isNull returns the inverse of the null state

2 participants