You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Spark negative returns wrong results for decimal columns #25942
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:
CREATETABLEtASVALUES (CAST(1.23ASDECIMAL(10,2))), (CAST(-4.50ASDECIMAL(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 0SELECT 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.23ASDECIMAL(10,2)));
-- ANSI mode: correct (-1.23, 4.50)SETdatafusion.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 2b1fcae, in both release and debug builds.
Activity
mattsu2020 commentedon Oct 1, 2026
take