-
Notifications
You must be signed in to change notification settings - Fork 4.1k
GH-40911: [C++][Compute] Fix the decimal division kernel dispatching #47445
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -670,7 +670,6 @@ void AddDecimalBinaryKernels(const std::string& name, ScalarFunction* func) { | |
| out_type = OutputType(ResolveDecimalMultiplicationOutput); | ||
| } else if (op == "divide") { | ||
| out_type = OutputType(ResolveDecimalDivisionOutput); | ||
| constraint = BinaryDecimalScale1GeScale2(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't really need this constraint to suppress the exact matching as this is now done via overridden
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the tricky part about decimal division - there is no "exact match" at all. By definition we ALWAYS promote the dividend no matter their (p, s) are. For example, As long as we allow any exact match, the promotion won't happen.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well,
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or you mean the dividend gets promoted to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Exactly. Except that it is actually promoted to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, thanks. Perhaps the PR description can be clearer about this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this is how we obey the resulting type rule we claim - promoting the dividend. That said, there is an alternative though - as you implied in your previous comment
This is also explained in my PR description approach 2. I didn't take that approach because that would require the promotion to happen during the underlying division for each individual value in the array. Can be cumbersome in terms of both coding and performance.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, thanks for the explanation! |
||
| } else { | ||
| DCHECK(false); | ||
| } | ||
|
|
@@ -727,6 +726,17 @@ ArrayKernelExec GenerateArithmeticWithFixedIntOutType(detail::GetTypeId get_id) | |
| struct ArithmeticFunction : ScalarFunction { | ||
| using ScalarFunction::ScalarFunction; | ||
|
|
||
| Result<const Kernel*> DispatchExact( | ||
| const std::vector<TypeHolder>& types) const override { | ||
| if ((name_ == "divide" || name_ == "divide_checked") && HasDecimal(types)) { | ||
| // Decimal division ALWAYS scales up the dividend, so there will NEVER be an exact | ||
| // match. | ||
| return arrow::compute::detail::NoMatchingKernel(this, types); | ||
| } | ||
|
|
||
| return ScalarFunction::DispatchExact(types); | ||
| } | ||
|
|
||
| Result<const Kernel*> DispatchBest(std::vector<TypeHolder>* types) const override { | ||
| RETURN_NOT_OK(CheckArity(types->size())); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the test would be more interesting if those types had different precisions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not directly related to this PR though, updated by more interesting combinations of (p, s).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.