-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-48802: [C++] Replace redundant nullptr assignment to DCHECK_EQ in FixedSizeBinary to String/Binary cast #48803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HyukjinKwon
wants to merge
1
commit into
apache:main
from
HyukjinKwon:remove-redundant-nullptr-check
Open
GH-48802: [C++] Replace redundant nullptr assignment to DCHECK_EQ in FixedSizeBinary to String/Binary cast #48803
HyukjinKwon
wants to merge
1
commit into
apache:main
from
HyukjinKwon:remove-redundant-nullptr-check
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
...g/Binary cast The output->buffers vector is already resized with nullptr-initialized elements by PrepareOutput() in exec.cc before the kernel executes, so explicitly setting buffers[2] to nullptr when input_data is nullptr is redundant. Added a DCHECK to verify this invariant in debug builds.
@github-actions
github-actions
bot
added
Component: C++
awaiting review
Awaiting review
labels
Jan 9, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
Rationale for this change
The TODO comment saying explicitly setting
output->buffers[2] = nullptrin the else branch was redundant.The output
ArrayDatais allocated byPrepareOutput()before the kernel executes:arrow/cpp/src/arrow/compute/exec.cc
Lines 907 to 908 in 7be5a89
PrepareOutput()resizes the buffers vector to the required size for the output type (3 for String/Binary: validity, offsets, data):arrow/cpp/src/arrow/compute/exec.cc
Lines 729 to 731 in 7be5a89
For String/Binary output types,
ComputeDataPreallocate()only preallocates the offsets buffer (not the data buffer):arrow/cpp/src/arrow/compute/exec.cc
Lines 294 to 298 in 7be5a89
PrepareOutput()only allocates buffers that are in thedata_preallocated_vector. For String/Binary, this means onlybuffers[1](offsets) is allocated:arrow/cpp/src/arrow/compute/exec.cc
Lines 739 to 747 in 7be5a89
Since
std::vector::resize()constructs all elements,buffers[2]is alreadynullptrfrom the resize call. Therefore, explicitly assigningnullptrin the else branch is redundant.What changes are included in this PR?
Converted the redundant else clause to
DCHECK_EQ.Are these changes tested?
Yes, I locally ran
Cast.FixedSizeBinaryToBinaryOrStringandCast.FixedSizeBinaryToBinaryOrStringWithSlice.Are there any user-facing changes?
No.