GH-50752: [C++][Compute] Fix unused variable warning when ARROW_WITH_RE2 is disabled - #50754
Merged
Conversation
…_WITH_RE2 is disabled
This change fixes the following build error:
```
/arrow/cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:1753:16: error: unused variable ‘is_utf8’ [-Werror=unused-variable]
1753 | const bool is_utf8 = is_string_or_string_view(batch[0].type()->id());
| ^~~~~~~
```
The `is_utf8` variable introduced by commit 374db36 is unused when `ARROW_WITH_RE2=OFF` is specified.
```diff
static Status Exec(KernelContext* ctx, const ExecSpan& batch, ExecResult* out) {
const MatchSubstringOptions& options = MatchSubstringState::Get(ctx);
+ const bool is_utf8 = is_string_or_string_view(batch[0].type()->id());
if (options.ignore_case) {
ARROW_ASSIGN_OR_RAISE(auto matcher,
- FindSubstringRegex::Make(options, InputType::is_utf8, true));
- applicator::ScalarUnaryNotNullStateful<OffsetType, InputType, FindSubstringRegex>
+ FindSubstringRegex::Make(options, is_utf8, true));
+ applicator::ScalarUnaryNotNullStateful<OffsetType, InputPhysicalType,
+ FindSubstringRegex>
kernel{std::move(matcher)};
return kernel.Exec(ctx, batch, out);
return Status::NotImplemented("ignore_case requires RE2");
}
- applicator::ScalarUnaryNotNullStateful<OffsetType, InputType, FindSubstring> kernel{
- FindSubstring(PlainSubstringMatcher(options))};
+ applicator::ScalarUnaryNotNullStateful<OffsetType, InputPhysicalType, FindSubstring>
+ kernel{FindSubstring(PlainSubstringMatcher(options))};
return kernel.Exec(ctx, batch, out);
}
};
```
Therefore, I move the declaration of `is_utf8` inside the `#ifdef ARROW_WITH_RE2` block to prevent this error.
Yes.
This change only moves the declaration of `is_utf8` and does not change any logic.
Therefore, the existing tests introduced by 374db36 should continue to
pass. These tests are already covered by CI, and CI passes successfully
with this change.
No new tests are added because this change only moves a variable declaration and does not affect behavior.
No.
- GitHub Issue: apacheGH-50752
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a C++ build failure when compiling Arrow Compute with -Werror and ARROW_WITH_RE2=OFF by ensuring is_utf8 is only declared in the ARROW_WITH_RE2 code path where it’s used.
Changes:
- Move
is_utf8declaration into the#ifdef ARROW_WITH_RE2block withinFindSubstringExec::Execto avoid an unused-variable warning when RE2 is disabled.
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
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.
Rationale for this change
This change fixes the following build error:
The
is_utf8variable introduced by commit 374db36 is unused whenARROW_WITH_RE2=OFFis specified.static Status Exec(KernelContext* ctx, const ExecSpan& batch, ExecResult* out) { const MatchSubstringOptions& options = MatchSubstringState::Get(ctx); + const bool is_utf8 = is_string_or_string_view(batch[0].type()->id()); if (options.ignore_case) { ARROW_ASSIGN_OR_RAISE(auto matcher, - FindSubstringRegex::Make(options, InputType::is_utf8, true)); - applicator::ScalarUnaryNotNullStateful<OffsetType, InputType, FindSubstringRegex> + FindSubstringRegex::Make(options, is_utf8, true)); + applicator::ScalarUnaryNotNullStateful<OffsetType, InputPhysicalType, + FindSubstringRegex> kernel{std::move(matcher)}; return kernel.Exec(ctx, batch, out); return Status::NotImplemented("ignore_case requires RE2"); } - applicator::ScalarUnaryNotNullStateful<OffsetType, InputType, FindSubstring> kernel{ - FindSubstring(PlainSubstringMatcher(options))}; + applicator::ScalarUnaryNotNullStateful<OffsetType, InputPhysicalType, FindSubstring> + kernel{FindSubstring(PlainSubstringMatcher(options))}; return kernel.Exec(ctx, batch, out); } };Therefore, I move the declaration of
is_utf8inside the#ifdef ARROW_WITH_RE2block to prevent this error.What changes are included in this PR?
I move the declaration of
is_utf8inside the#ifdef ARROW_WITH_RE2block to prevent this error.This PR does not includes breaking changes to public APIs.
This PR does not contains a "Critical Fix".
Are these changes tested?
Yes.
This change only moves the declaration of
is_utf8and does not change any logic.Therefore, the existing tests introduced by 374db36 should continue to pass. These tests are already covered by CI, and CI passes successfully with this change.
No new tests are added because this change only moves a variable declaration and does not affect behavior.
I have confirmed that C++ CI checks pass on my fork.
See: https://github.com/komainu8/arrow/actions/runs/30619400223/job/91120073626
Are there any user-facing changes?
No.