-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix(expr-common): Coerce to Decimal(20, 0) when combining UInt64 with signed integers #14223
Changes from 1 commit
5f0bd17
d632d7a
c21610c
befdc43
bb2c5c0
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 |
---|---|---|
|
@@ -413,23 +413,23 @@ explain SELECT c1, c9 FROM aggregate_test_100 UNION ALL SELECT c1, c3 FROM aggre | |
logical_plan | ||
01)Sort: aggregate_test_100.c9 DESC NULLS FIRST, fetch=5 | ||
02)--Union | ||
03)----Projection: aggregate_test_100.c1, CAST(aggregate_test_100.c9 AS Int64) AS c9 | ||
03)----Projection: aggregate_test_100.c1, CAST(aggregate_test_100.c9 AS Decimal128(20, 0)) AS c9 | ||
04)------TableScan: aggregate_test_100 projection=[c1, c9] | ||
05)----Projection: aggregate_test_100.c1, CAST(aggregate_test_100.c3 AS Int64) AS c9 | ||
05)----Projection: aggregate_test_100.c1, CAST(aggregate_test_100.c3 AS Decimal128(20, 0)) AS c9 | ||
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. this seems like a regression to me (there is now 2x the space needed) 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. This query unions create table t1(a smallint) as values(1);
create table t2(a bigint unsigned) as values(10000000000000000000);
select * from t1 union select * from t2; |
||
06)------TableScan: aggregate_test_100 projection=[c1, c3] | ||
physical_plan | ||
01)SortPreservingMergeExec: [c9@1 DESC], fetch=5 | ||
02)--UnionExec | ||
03)----SortExec: TopK(fetch=5), expr=[c9@1 DESC], preserve_partitioning=[true] | ||
04)------ProjectionExec: expr=[c1@0 as c1, CAST(c9@1 AS Int64) as c9] | ||
04)------ProjectionExec: expr=[c1@0 as c1, CAST(c9@1 AS Decimal128(20, 0)) as c9] | ||
05)--------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1 | ||
06)----------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100.csv]]}, projection=[c1, c9], has_header=true | ||
07)----SortExec: TopK(fetch=5), expr=[c9@1 DESC], preserve_partitioning=[true] | ||
08)------ProjectionExec: expr=[c1@0 as c1, CAST(c3@1 AS Int64) as c9] | ||
08)------ProjectionExec: expr=[c1@0 as c1, CAST(c3@1 AS Decimal128(20, 0)) as c9] | ||
09)--------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1 | ||
10)----------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100.csv]]}, projection=[c1, c3], has_header=true | ||
|
||
query TI | ||
query TR | ||
SELECT c1, c9 FROM aggregate_test_100 UNION ALL SELECT c1, c3 FROM aggregate_test_100 ORDER BY c9 DESC LIMIT 5 | ||
---- | ||
c 4268716378 | ||
|
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 looks not correct. For example, combining
Decimal128(20, 0)
withDecimal128(30, 0)
should not result inDecimal128(20, 0)
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.
I think when both types are decimal they are handled above before this match, when calling the
decimal_coercion
function.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.
I rechecked it, and
decimal_coercion
already covers them indatafusion/datafusion/expr-common/src/type_coercion/binary.rs
Lines 932 to 940 in 2f28327
Although it doesn't handle unsigned integer types, we can supplement it there, maybe as a follow-up PR.
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.
So I think we shouldn't combine decimal with integer types here because
decimal_coercion
has already handled it.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.
I tried that initially but then it would not handle
UInt64
andDecimal128(20, 0)
:So maybe it would be best to add new arms to the
coerce_numeric_type_to_decimal
to include unsigned integers as well?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.
I think so.
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.
Done.