namanjain24-sudo opened a new pull request, #27124: URL: https://github.com/apache/datafusion/pull/27124
## Which issue does this PR close? - Closes #27095. ## Rationale for this change Comparing an integer with a decimal that has a large scale fails at execution: ```sql SELECT * FROM t WHERE a != CAST(0.9 AS DECIMAL(38,38)); -- Failed to cast field 'a' from Int32 to Decimal128(38, 38) ``` The common type of the two sides is `max(s1, s2) + max(p1 - s1, p2 - s2)` digits, 48 here. `Decimal128` holds 38, and the precision was capped there while the scale stayed at 38, so the result had no room for integer digits at all and the integer side could not be cast into it. PostgreSQL returns the rows. ## What changes are included in this PR? When the other side is an integer, the common type is now the narrowest decimal variant that holds the required precision instead of a capped one. How many integer digits an integer needs is known exactly, so a type without room for them fails every value that uses them. A float keeps the previous behaviour. The scale a float coerces to is an approximation of its own (`Float64` becomes `Decimal128(30, 15)`), and widening on that basis would move ordinary comparisons like `WHERE price = 4.00` onto `Decimal256`. ## What is the testing strategy for this PR? A unit test in `type_coercion/binary/tests/comparison.rs` pins the coerced types: an integer against `Decimal128(38, 38)` and against `Decimal128(38, 30)`, one that still fits `Decimal128`, and a float against the same wide decimal so the unchanged path stays covered. The three queries from the issue are in `decimal.slt`, with the results checked against PostgreSQL 17. ## Are there any user-facing changes? Comparisons of an integer with a wide decimal return rows instead of failing. No API changes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
