Skip to content

GH-41336: [C++][Compute] Fix case_when kernel dispatch for decimals with different precisions and scales#47479

Merged
zanmato1984 merged 3 commits intoapache:mainfrom
zanmato1984:fix/gh-41336
Sep 3, 2025
Merged

GH-41336: [C++][Compute] Fix case_when kernel dispatch for decimals with different precisions and scales#47479
zanmato1984 merged 3 commits intoapache:mainfrom
zanmato1984:fix/gh-41336

Conversation

@zanmato1984
Copy link
Copy Markdown
Contributor

@zanmato1984 zanmato1984 commented Sep 3, 2025

Rationale for this change

Another case of decimal kernels not able to suppress exact matching when precisions and scales of the arguments differ, causing wrong result type. After #47297, we have a systematic way to do that and guide the matching to go to the "best match" (applying implicit casts).

What changes are included in this PR?

Simply added a constraint match that checks if the precisions and scales of the decimal arguments are the same. Also added corresponding tests in forms of both expression (exact match first, then best match) and function call (best match only).

Are these changes tested?

Yes.

Are there any user-facing changes?

None.

@zanmato1984
Copy link
Copy Markdown
Contributor Author

Hopefully this will be the last one of this tide of fixing decimal kernel dispatching (#47297 #47445 #47459).

ARROW_EXPORT std::shared_ptr<MatchConstraint> MakeConstraint(
std::function<bool(const std::vector<TypeHolder>&)> matches);
/// \brief Convenience function to create a MatchConstraint from a match function.
static std::shared_ptr<MatchConstraint> Make(
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.

Not really related to the issue. Just a small refinement.

@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Sep 3, 2025
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

@github-actions github-actions bot added awaiting merge Awaiting merge and removed awaiting committer review Awaiting committer review labels Sep 3, 2025
}

TEST(Expression, BindWithImplicitCastsForCaseWhenOnDecimal) {
auto exciting_schema = schema(
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'm excited 🤩

DCHECK(std::all_of(types.begin() + 1, types.end(), [](const TypeHolder& type) {
return is_decimal(type.id());
}));
const auto& ty1 = checked_cast<const DecimalType&>(*types[1].type);
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.

Is the cast actually needed? The Equals method should work as well without it.

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.

Oh, good catch! I was casting then comparing precisions and scales. Then I found the Equals() method should work and forgot to remove the cast. Updated to use TypeHolder's operator ==. Thanks.

@conbench-apache-arrow
Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 8ccdbe7.

There weren't enough matching historic benchmark results to make a call on whether there were regressions.

The full Conbench report has more details.

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.

3 participants