Skip to content

GH-49889: [C++][Compute] Handle logical nulls in validity kernels#50269

Open
hadrian-reppas wants to merge 9 commits into
apache:mainfrom
hadrian-reppas:logical_nulls_compute
Open

GH-49889: [C++][Compute] Handle logical nulls in validity kernels#50269
hadrian-reppas wants to merge 9 commits into
apache:mainfrom
hadrian-reppas:logical_nulls_compute

Conversation

@hadrian-reppas

@hadrian-reppas hadrian-reppas commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

I was looking into #49889 and updated the handling of logical nulls in the is_valid, is_null, and true_unless_null kernels. It turns out there is some prior work here that I didn't see before I starting implementing my fix (#35058, #35036, #37642). For some reason, that work has stalled.

What changes are included in this PR?

This PR updates the IsValidExec, IsNullExec, and TrueUnlessNullExec kernels so that they call out to a new function SetLogicalNullBits. The SetLogicalNullBits function matches the logic in ArraySpan::ComputeLogicalNullCount(). The logic is similar enough that they may be some opportunities for code deduplication in dict_util.cc and ree_util.cc.

Are these changes tested?

Yes

Are there any user-facing changes?

No

@hadrian-reppas hadrian-reppas requested a review from pitrou as a code owner June 26, 2026 11:25
@github-actions

Copy link
Copy Markdown

Thanks for opening a pull request!

If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename the pull request title in the following format?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

See also:

@hadrian-reppas hadrian-reppas changed the title [C++] Handle logical nulls in validity kernels GH-49889: [C++][Compute] Handle logical nulls in validity kernels Jun 26, 2026

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

This is looking promising @hadrian-reppas !

Comment thread cpp/src/arrow/compute/kernels/scalar_validity.cc Outdated
Comment thread cpp/src/arrow/util/dict_util.cc Outdated
Comment thread cpp/src/arrow/util/dict_util.cc Outdated

void SetLogicalNullBits(const ArraySpan& span, uint8_t* out_bitmap, int64_t out_offset,
bool set_on_null) {
if (span.dictionary().GetNullCount() == 0 || span.length == 0) {

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.

Using GetNullCount implies we're not looking up logical nulls in the dictionary values, only physical nulls, right?

This may be ok given that ArraySpan::ComputeLogicalNullCount does the same, but perhaps add a comment here?

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.

Yeah this feels kind of odd. I think we should probably be calling ComputeLogicalNullCount in both LogicalNullCount and SetLogicalNullBits.

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.

Actually, things become kind of messy if you look at logical nulls in the dictionary. Right now, it just looks at the dictionary validity bitmap. But if we wanted to properly handle logical nulls, we would need to deal with dictionaries that are dictionary, ree, and union types. So I'll keep this behavior for now and add 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.

I think you're right, also, dict_util::LogicalNullCount does not account for logical nulls in the dictionary either.

Comment thread cpp/src/arrow/util/dict_util.cc Outdated
@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Jul 7, 2026
Comment thread cpp/src/arrow/util/ree_util.h
@hadrian-reppas

Copy link
Copy Markdown
Contributor Author

I just addressed your comments. Let me know what you think, @pitrou.

Comment thread cpp/src/arrow/util/dict_util_internal.h Outdated
@pitrou

pitrou commented Jul 8, 2026

Copy link
Copy Markdown
Member

(thanks a lot for the update btw, apart from the comment above it LGTM)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants