Skip to content

GH-47447: [C++] Fix replace_with_mask for null type arrays#49950

Open
AnkitAhlawat7742 wants to merge 7 commits into
apache:mainfrom
AnkitAhlawat7742:fix/replace_with_mask_crash
Open

GH-47447: [C++] Fix replace_with_mask for null type arrays#49950
AnkitAhlawat7742 wants to merge 7 commits into
apache:mainfrom
AnkitAhlawat7742:fix/replace_with_mask_crash

Conversation

@AnkitAhlawat7742
Copy link
Copy Markdown
Contributor

@AnkitAhlawat7742 AnkitAhlawat7742 commented May 8, 2026

Rationale for this change

replace_with_mask crashes when called with null type arrays because a code path incorrectly returns Status::OK() from a function with return type Result<int64_t>.
This PR fixes the issue by ensuring the function returns a valid int64_t value instead of Status::OK() for successful execution.

What changes are included in this PR?

  1. Fixed the replace_with_mask kernel implementation for null type arrays.
  2. Replaced the invalid Status::OK() return path with a valid int64_t result.
  3. Prevented construction of Result<int64_t> with an OK Status.

Are these changes tested?

Yes, manually run the test case

Are there any user-facing changes?

No

This PR contains a "Critical Fix".

This change fixes a crash in replace_with_mask when operating on null type arrays. The crash occurs due to an invalid successful return path internally constructing Result with Status::OK().

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

⚠️ GitHub issue #47447 has been automatically assigned in GitHub to PR creator.

@AnkitAhlawat7742
Copy link
Copy Markdown
Contributor Author

Hi @raulcd ,
Could you please re-run the failed job? i see download build timed out while downloading the ORC dependency (orc-2.2.1.tar.gz)

 --- LOG END ---
          error: downloading 'https://dlcdn.apache.org/orc/orc-2.2.1/orc-2.2.1.tar.gz' failed
          status_code: 22
          status_string: "HTTP response code said error"
          log:
          --- LOG BEGIN ---
            Trying 151.101.2.132:443...

@AnkitAhlawat7742
Copy link
Copy Markdown
Contributor Author

Hi @raulcd ,
Please review the changes ,let me know if any modification needed

Copy link
Copy Markdown
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

Thanks @AnkitAhlawat7742 for this PR.

Can you add some C++ tests in the existing file vector_replace_test.cc?
You can get some inspiration from the existing TestReplaceBoolean.

Comment thread python/pyarrow/tests/test_compute.py
@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels May 13, 2026
…p and updated the python test with null type
@AnkitAhlawat7742
Copy link
Copy Markdown
Contributor Author

Thanks @AnkitAhlawat7742 for this PR.

Can you add some C++ tests in the existing file vector_replace_test.cc? You can get some inspiration from the existing TestReplaceBoolean.

HI @pitrou ,
Thanks for the review ..!!
I have updated the python Test case and added the new test case in vector_replace_test file .and thanks for the reference of existing class

@AnkitAhlawat7742
Copy link
Copy Markdown
Contributor Author

AnkitAhlawat7742 commented May 15, 2026

Hi @pitrou and @raulcd ,
Please review the changes, when you get a chance. I noticed a CI failure in the Windows build but confirmed it is unrelated to my changes.

@AnkitAhlawat7742
Copy link
Copy Markdown
Contributor Author

Hi @pitrou and @raulcd,
just a gentle ping on this PR when you get a chance. please review it once again ...happy to make any changes if needed!

cc @AlenkaF @rok @jorisvandenbossche

@AnkitAhlawat7742
Copy link
Copy Markdown
Contributor Author

Hi @kou ,
Please review the PR as well

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a crash in the C++ replace_with_mask kernel when operating on NullType arrays (GH-47447), where a Result<int64_t> path incorrectly attempted to return Status::OK(). The fix ensures the kernel returns a valid int64_t and produces a valid output for null arrays, and adds regression tests in both C++ and Python.

Changes:

  • Fix NullType replace_with_mask implementation to return a valid int64_t (and set output as ArrayData) instead of returning Status::OK() from a Result<int64_t> function.
  • Add C++ regression tests covering replace_with_mask on NullType.
  • Add Python regression test reproducing the original crash scenario.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
cpp/src/arrow/compute/kernels/vector_replace.cc Fixes NullType ReplaceMaskImpl to return a valid int64_t and sets output as ArrayData, preventing the invalid Result<T>(Status::OK()) construction.
cpp/src/arrow/compute/kernels/vector_replace_test.cc Adds a dedicated NullType test fixture and ReplaceWithMask test cases to prevent regressions in the C++ kernel.
python/pyarrow/tests/test_compute.py Adds a Python regression test for pc.replace_with_mask with pa.null() arrays to ensure the crash is fixed end-to-end.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Member

@kou kou left a comment

Choose a reason for hiding this comment

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

+1

Comment thread python/pyarrow/tests/test_compute.py Outdated
@github-actions github-actions Bot added awaiting merge Awaiting merge and removed awaiting committer review Awaiting committer review labels May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants