-
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
Add more tests showing coercing behavior with literals #14270
Conversation
arrow_typeof(decimal + 2) | ||
from numeric_types; | ||
---- | ||
Int64 Int64 Int64 Int64 Int64 Int64 Int64 Int64 Float32 Float64 Decimal128(23, 2) |
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 shows that adding a literal integer (2
) does not upcast to Decimal for integer types (which would be terrible for performance)
I think adding tests for comparison operations will probably expose the possible issue with the linked PR. (Or give us a peace of mind) |
---- | ||
physical_plan | ||
01)CoalesceBatchesExec: target_batch_size=8192 | ||
02)--FilterExec: int64@3 < 5 AND uint64@7 < 5 AND float64@9 < 5 AND decimal@10 < Some(500),5,2 |
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 test shows that with a positive integer comparison does not result in any casting of the column
---- | ||
physical_plan | ||
01)CoalesceBatchesExec: target_batch_size=8192 | ||
02)--FilterExec: int64@3 < -5 AND CAST(uint64@7 AS Decimal128(20, 0)) < Some(-5),20,0 AND float64@9 < -5 AND decimal@10 < Some(-500),5,2 |
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 test show that with a negative integer, the comparison to int64
does not cast.
However, a comparison with -5
does cast to Decimal128
: CAST(uint64@7 AS Decimal128(20, 0)) < Some(-5),20,0
When I reverted the changes in #14223 locally, this is the difference (cast to Int64 rather than Decimal):
[Diff] (-expected|+actual)
physical_plan
01)CoalesceBatchesExec: target_batch_size=8192
- 02)--FilterExec: int64@3 < -5 AND CAST(uint64@7 AS Decimal128(20, 0)) < Some(-5),20,0 AND float64@9 < -5 AND decimal@10 < Some(-500),5,2
+ 02)--FilterExec: int64@3 < -5 AND CAST(uint64@7 AS Int64) < -5 AND float64@9 < -5 AND decimal@10 < Some(-500),5,2
03)----MemoryExec: partitions=1, partition_sizes=[1]
at test_files/operator.slt:286
However, note that in this case the predicate will never be true anyways (a uint64
can never be less than -5 as it is by definition always greater than zero -- something @gatesn pointed out on another ticket)
It is a good idea -- I added tests showing what happens in comparisons |
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.
Thanks @alamb . I think these tests are very valuable; they reveal the problems more clearly.
As this is entirely tests and demonstrates the actual behavior I am going to merge it as is -- I am happy to add more tests if we discover additional ones to add |
Thanks again @jonahgao |
Which issue does this PR close?
Rationale for this change
I was still confused about what happens with coercion in #14223 (comment) and somewhat panic'ing that the change would impact performance. I want tests in place to show the output types of operations
What changes are included in this PR?
Add more sqllogictests showing the output types when adding literals to various column types
Are these changes tested?
Are there any user-facing changes?