You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "neilconway (via GitHub)" <gi...@apache.org> on 2026/10/01 15:46:19 UTC

[I] Spark `negative` returns wrong results for decimal columns [datafusion]

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: github-unsubscribe@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Spark `negative` returns wrong results for decimal columns [datafusion]

Posted by "mattsu2020 (via GitHub)" <gi...@apache.org>.
mattsu2020 commented on issue #25942:
URL: https://github.com/apache/datafusion/issues/25942#issuecomment-5941607708

   take


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org