Skip to content

fix: relax validation for missing validity buffer when null_count is -1 - #942

Merged
paleolimbot merged 1 commit into
apache:mainfrom
and2049:fix-855-null-count-unknown-no-validity
Sep 15, 2026
Merged

paleolimbot merged 1 commit into
apache:mainfrom
and2049:fix-855-null-count-unknown-no-validity

Conversation

@and2049

@and2049 and2049 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Allow a missing validity buffer when the null count is unknown, matching
Arrow C++’s import behavior. Arrays reporting a positive null count still
require a validity buffer.

Add regression coverage for unknown null counts with a missing validity
buffer, including sliced arrays and positive-null-count rejection.

Fixes #855

@codecov-commenter

codecov-commenter commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.19%. Comparing base (b896d19) to head (275705f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #942   +/-   ##
=======================================
  Coverage   78.19%   78.19%           
=======================================
  Files         106      106           
  Lines       16843    16843           
  Branches     1985     1985           
=======================================
  Hits        13170    13170           
  Misses       2439     2439           
  Partials     1234     1234           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paleolimbot paleolimbot 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.

Thank you!

One note on the test here...I think you're testing two things but we only need to update the null count to ensure your change is covered.

Comment thread src/nanoarrow/common/array_test.cc Outdated
Comment on lines +2484 to +2505
// Same for a string array (["a", "bb", "ccc"])
int32_t offsets[] = {0, 1, 3, 6};
const void* string_buffers[] = {nullptr, offsets, "abbccc"};
array->null_count = -1;
array->n_buffers = 3;
array->buffers = string_buffers;

nanoarrow::UniqueArrayView string_view;
ArrowArrayViewInitFromType(string_view.get(), NANOARROW_TYPE_STRING);
ASSERT_EQ(ArrowArrayViewSetArray(string_view.get(), array.get(), &error), NANOARROW_OK)
<< error.message;
EXPECT_EQ(
ArrowArrayViewValidate(string_view.get(), NANOARROW_VALIDATION_LEVEL_FULL, &error),
NANOARROW_OK)
<< error.message;
EXPECT_EQ(ArrowArrayViewGetBufferView(string_view.get(), 0).size_bytes, 0);
EXPECT_EQ(ArrowArrayViewComputeNullCount(string_view.get()), 0);
EXPECT_EQ(ArrowArrayViewGetStringUnsafe(string_view.get(), 0), "bb"_asv);
EXPECT_EQ(ArrowArrayViewGetStringUnsafe(string_view.get(), 1), "ccc"_asv);

array->null_count = 1;
EXPECT_EQ(ArrowArrayViewSetArray(string_view.get(), array.get(), &error), EINVAL);

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.

Can you to use the exact same array as above and just modify the null count? I don't think we need to use a different type here to cover the changed lines.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've removed the string-array case, and the test now uses the same int32 array and only changes the null count.

Validation currently errors if the validity buffer is missing and
null_count != 0. Arrow C++ only errors if null_count > 0,
and arrays like this show up in the wild. Relax the
check to match.

Fixes apache#855
@and2049
and2049 force-pushed the fix-855-null-count-unknown-no-validity branch from c0eb1d9 to 275705f Compare September 15, 2026 17:43

@paleolimbot paleolimbot 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.

Thank you!

@paleolimbot
paleolimbot merged commit 7bf5d3c into apache:main Sep 15, 2026
43 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.

Relax validation for null validity buffer when null_count is -1

3 participants