Skip to content
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

Merged
merged 4 commits into from
Jan 26, 2025

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Jan 24, 2025

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?

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Jan 24, 2025
arrow_typeof(decimal + 2)
from numeric_types;
----
Int64 Int64 Int64 Int64 Int64 Int64 Int64 Int64 Float32 Float64 Decimal128(23, 2)
Copy link
Contributor Author

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)

@ozankabak
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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)

@alamb
Copy link
Contributor Author

alamb commented Jan 25, 2025

I think adding tests for comparison operations will probably expose the possible issue with the linked PR. (Or give us a peace of mind)

It is a good idea -- I added tests showing what happens in comparisons

Copy link
Member

@jonahgao jonahgao left a 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.

@alamb
Copy link
Contributor Author

alamb commented Jan 26, 2025

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

@alamb
Copy link
Contributor Author

alamb commented Jan 26, 2025

Thanks again @jonahgao

@alamb alamb merged commit f510800 into apache:main Jan 26, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants