andygrove opened a new issue, #27185:
URL: https://github.com/apache/datafusion/issues/27185

   ### Describe the bug
   
   With the Spark dialect, DataFusion types an integer literal as `Int64` and a 
literal such as `1.5` as `Float64` 
([value.rs#L87-L101](https://github.com/apache/datafusion/blob/a616831122aa525ed843ee3c5e11f4803f557c98/datafusion/sql/src/expr/value.rs#L87-L101)).
 Spark types an integer literal as `INT` when it fits and as `BIGINT` otherwise 
([AstBuilder.scala#L4151-L4159](https://github.com/apache/spark/blob/v4.2.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala#L4151-L4159)),
 and `1.5` as `DECIMAL(2, 1)` 
([#L4164-L4166](https://github.com/apache/spark/blob/v4.2.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala#L4164-L4166)).
 The same query can then return a different value or type.
   
   ### To Reproduce
   
   Spark 4.2.0, and the expected results in DataFusion's `.slt` files:
   
   ```sql
   SELECT xxhash64(1)
   -- Spark: -6698625589789238999, the hash of the INT 1
   -- DataFusion: -7001672635703045582, the hash of the BIGINT 1
   SELECT try_sum(x) FROM VALUES (1.5), (2.5), (3.0) AS tab(x)
   -- Spark: 7.0
   -- DataFusion: 7
   SELECT if(true, 10, 20.5)
   -- Spark: 10.0
   -- DataFusion: 10
   ```
   
   `xxhash64` itself is correct: DataFusion's results are exactly Spark's 
hashes of a `BIGINT`.
   
   ### Spark versions
   
   Spark types literals the same way in every version from 3.4 to 4.2, so this 
does not depend on the Spark version.
   
   ### Expected behavior
   
   Type literals as Spark does when the Spark dialect is used. 
`datafusion.sql_parser.parse_float_as_decimal = true` already parses `1.5` as a 
decimal, so the Spark dialect or `datafusion-cli --spark` could enable it. 
Integer literals have no such option.
   
   ### Additional context
   
   Found with the runner in #27165. This explains all 10 differences in 
`xxhash64.slt`, 3 in `try_sum.slt` and 2 in `if.slt`, as well as 61 queries in 
`format_string.slt` where Spark raises `f != 
org.apache.spark.sql.types.Decimal` because its argument is a `DECIMAL`. Fixing 
it will change many expected results in `test_files/spark`, which were written 
with DataFusion's types.
   


-- 
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]

Reply via email to