felipecrv commented on code in PR #34408:
URL: https://github.com/apache/arrow/pull/34408#discussion_r1126496560
##########
cpp/src/arrow/array/data.h:
##########
@@ -363,14 +475,73 @@ struct ARROW_EXPORT ArraySpan {
}
}
- /// \brief Return null count, or compute and set it if it's not known
+ /// \brief Return physical null count, or compute and set it if it's not
known
int64_t GetNullCount() const;
+ /// \brief Return true if the array has a validity bitmap and the physical
null
+ /// count is known to be non-zero or not yet known
+ ///
+ /// Note that this is not the same as MayHaveLogicalNulls, which also checks
+ /// for the presence of nulls in child data for types like unions and run-end
+ /// encoded types.
+ ///
+ /// \see HasValidityBitmap
+ /// \see MayHaveLogicalNulls
bool MayHaveNulls() const {
// If an ArrayData is slightly malformed it may have kUnknownNullCount set
// but no buffer
return null_count != 0 && buffers[0].data != NULLPTR;
}
+
+ /// \brief Return true if the array has a validity bitmap
+ bool HasValidityBitmap() const { return buffers[0].data != NULLPTR; }
+
+ /// \brief Return true if the validity bitmap may have 0's in it, or if the
+ /// child arrays (in the case of types without a validity bitmap) may have
+ /// nulls
+ ///
+ /// \see ArrayData::MayHaveLogicalNulls
+ bool MayHaveLogicalNulls() const {
+ if (buffers[0].data != NULLPTR) {
+ return null_count != 0;
+ }
+ const auto t = type->id();
+ if (t == Type::SPARSE_UNION || t == Type::DENSE_UNION) {
+ return UnionMayHaveLogicalNulls();
+ }
+ if (t == Type::RUN_END_ENCODED) {
+ return RunEndEncodedMayHaveLogicalNulls();
+ }
+ return false;
Review Comment:
Good catch! But the fix is `null_count_ != 0` because when `length` is `0`
we also want to return false here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]