-
Notifications
You must be signed in to change notification settings - Fork 4.1k
GH-41011: [C++][Compute] Fix the issue that comparison function could not handle decimal arguments with different scales #47459
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
62eab1d
d3aee89
f2c4c91
530b929
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 |
|---|---|---|
|
|
@@ -648,6 +648,10 @@ TEST(Expression, BindWithDecimalArithmeticOps) { | |
| } | ||
|
|
||
| TEST(Expression, BindWithImplicitCasts) { | ||
| auto exciting_schema = schema( | ||
| {field("i64", int64()), field("dec128_3_2", decimal128(3, 2)), | ||
| field("dec128_5_3", decimal128(5, 3)), field("dec256_3_2", decimal256(3, 2)), | ||
| field("dec256_5_3", decimal256(5, 3))}); | ||
| for (auto cmp : {equal, not_equal, less, less_equal, greater, greater_equal}) { | ||
| // cast arguments to common numeric type | ||
| ExpectBindsTo(cmp(field_ref("i64"), field_ref("i32")), | ||
|
|
@@ -708,6 +712,42 @@ TEST(Expression, BindWithImplicitCasts) { | |
| ExpectBindsTo(cmp(field_ref("i32"), literal(std::make_shared<DoubleScalar>(10.0))), | ||
| cmp(cast(field_ref("i32"), float32()), | ||
| literal(std::make_shared<FloatScalar>(10.0f)))); | ||
|
|
||
| // decimal int | ||
| ExpectBindsTo(cmp(field_ref("dec128_3_2"), field_ref("i64")), | ||
| cmp(field_ref("dec128_3_2"), cast(field_ref("i64"), decimal128(21, 2))), | ||
| /*bound_out=*/nullptr, *exciting_schema); | ||
| ExpectBindsTo(cmp(field_ref("i64"), field_ref("dec128_3_2")), | ||
| cmp(cast(field_ref("i64"), decimal128(21, 2)), field_ref("dec128_3_2")), | ||
| /*bound_out=*/nullptr, *exciting_schema); | ||
|
|
||
| // decimal128 decimal256 with different scales | ||
|
||
| ExpectBindsTo( | ||
| cmp(field_ref("dec128_3_2"), field_ref("dec256_5_3")), | ||
| cmp(cast(field_ref("dec128_3_2"), decimal256(4, 3)), field_ref("dec256_5_3")), | ||
| /*bound_out=*/nullptr, *exciting_schema); | ||
| ExpectBindsTo( | ||
| cmp(field_ref("dec256_5_3"), field_ref("dec128_3_2")), | ||
| cmp(field_ref("dec256_5_3"), cast(field_ref("dec128_3_2"), decimal256(4, 3))), | ||
| /*bound_out=*/nullptr, *exciting_schema); | ||
| ExpectBindsTo(cmp(field_ref("dec128_5_3"), field_ref("dec256_3_2")), | ||
| cmp(cast(field_ref("dec128_5_3"), decimal256(5, 3)), | ||
| cast(field_ref("dec256_3_2"), decimal256(4, 3))), | ||
| /*bound_out=*/nullptr, *exciting_schema); | ||
| ExpectBindsTo(cmp(field_ref("dec256_3_2"), field_ref("dec128_5_3")), | ||
| cmp(cast(field_ref("dec256_3_2"), decimal256(4, 3)), | ||
| cast(field_ref("dec128_5_3"), decimal256(5, 3))), | ||
| /*bound_out=*/nullptr, *exciting_schema); | ||
|
Comment on lines
+716
to
+851
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. These cases will actually pass w/o this fix. Just added them for intact coverage of all decimal casting paths. |
||
|
|
||
| // decimal decimal with different scales | ||
zanmato1984 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ExpectBindsTo( | ||
| cmp(field_ref("dec128_3_2"), field_ref("dec128_5_3")), | ||
| cmp(cast(field_ref("dec128_3_2"), decimal128(4, 3)), field_ref("dec128_5_3")), | ||
| /*bound_out=*/nullptr, *exciting_schema); | ||
| ExpectBindsTo( | ||
| cmp(field_ref("dec128_5_3"), field_ref("dec128_3_2")), | ||
| cmp(field_ref("dec128_5_3"), cast(field_ref("dec128_3_2"), decimal128(4, 3))), | ||
| /*bound_out=*/nullptr, *exciting_schema); | ||
|
||
| } | ||
|
|
||
| compute::SetLookupOptions in_a{ArrayFromJSON(utf8(), R"(["a"])")}; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -436,8 +436,8 @@ std::shared_ptr<ScalarFunction> MakeCompareFunction(std::string name, FunctionDo | |
|
|
||
| for (const auto id : {Type::DECIMAL128, Type::DECIMAL256}) { | ||
| auto exec = GenerateDecimal<applicator::ScalarBinaryEqualTypes, BooleanType, Op>(id); | ||
| DCHECK_OK( | ||
| func->AddKernel({InputType(id), InputType(id)}, boolean(), std::move(exec))); | ||
| DCHECK_OK(func->AddKernel({InputType(id), InputType(id)}, boolean(), std::move(exec), | ||
|
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. Yep, the fix is as simple as this. Thanks to #47297. |
||
| /*init=*/nullptr, DecimalsHaveSameScale())); | ||
| } | ||
|
|
||
| { | ||
|
|
||
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.
Get excited one more time! @pitrou
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.
My head spins.