sunchao opened a new issue, #7805:
URL: https://github.com/apache/datafusion-comet/issues/7805

   ### Describe the bug
   
   With ANSI mode enabled, Comet's native cast raises `CAST_OVERFLOW` when a 
decimal truncates to `INT_MIN` or `BIGINT_MIN`. Both values fit the destination 
type.
   
   ### Steps to reproduce
   
   In a Comet-enabled Spark session, read the decimals from Parquet so Spark 
evaluates the casts on columns. Run each `SELECT` separately.
   
   ```sql
   SET spark.sql.ansi.enabled = true;
   CREATE TABLE decimal_cast_min (i DECIMAL(10, 0), b DECIMAL(19, 0)) USING 
PARQUET;
   INSERT INTO decimal_cast_min VALUES (-2147483648, -9223372036854775808);
   
   SELECT CAST(i AS INT) FROM decimal_cast_min;
   SELECT CAST(b AS BIGINT) FROM decimal_cast_min;
   ```
   
   ### Expected behavior
   
   Spark returns `-2147483648` for the first query and `-9223372036854775808` 
for the second. Comet should return the same values and raise `CAST_OVERFLOW` 
only when the truncated integer is outside the destination range.
   
   ### Additional context
   
   The native kernel tests `abs(truncated) > MAX`. A signed integer has `MIN = 
-MAX - 1`, so this check rejects exactly one valid truncated integer for each 
type. Checking the signed bounds after truncation would accept the minimum and 
still reject the integer immediately below it. [Native overflow check on 
main](https://github.com/apache/datafusion-comet/blob/c7a048060061de41574a6e470f6b60d2dc54ba5f/native/spark-expr/src/conversion_funcs/numeric.rs#L605-L622)
   
   ### Willingness to contribute
   
   I can contribute a fix for this bug independently.
   


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