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

   ### Describe the bug
   
   With the Spark functions enabled and ANSI mode off (the default), 
`negative()` on a decimal column either fails or returns wrong values. It works 
correctly on a decimal literal, and on a column when ANSI mode is on.
   
   ### To Reproduce
   
   Run with `datafusion-cli --spark`:
   
   ```sql
   CREATE TABLE t AS VALUES (CAST(1.23 AS DECIMAL(10,2))), (CAST(-4.50 AS 
DECIMAL(10,2)));
   
   SELECT negative(column1) FROM t;
   -- Arrow error: Invalid argument error: column types must match schema 
types, expected Decimal128(10, 2) but found Decimal128(38, 10) at column index 0
   
   SELECT CAST(negative(column1) AS DOUBLE) AS v FROM t;
   -- returns -1.23e-8 and 4.5e-8 (expected -1.23 and 4.5)
   
   -- Literal input: correct (-1.23)
   SELECT negative(CAST(1.23 AS DECIMAL(10,2)));
   
   -- ANSI mode: correct (-1.23, 4.50)
   SET datafusion.execution.enable_ansi_mode = true;
   SELECT negative(column1) FROM t;
   ```
   
   In a debug build, both column queries instead fail with `Internal error: 
Assertion failed: result_data_type == *expected_type: Function 'negative' 
returned value of type 'Decimal128(38, 10)' while the following type was 
promised at planning time and expected: 'Decimal128(10, 2)'`.
   
   `Decimal64` and `Decimal256` columns also give wrong values. For example, 
with the table above, `SELECT CAST(negative(arrow_cast(column1, 'Decimal64(10, 
2)')) AS DOUBLE) FROM t` returns `-0.000123` and `0.00045`.
   
   ### Expected behavior
   
   `negative(column1)` returns `-1.23` and `4.50`, as it does for literals and 
in ANSI mode.
   
   ### Additional context
   
   Reproduced on `main` at commit 2b1fcae86, in both release and debug builds.
   
   *This bug report was generated by Claude.*
   


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