Skip to content

Spark negative returns wrong results for decimal columns #25942

Open

Description

@neilconway

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:

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 2b1fcae, in both release and debug builds.

This bug report was generated by Claude.

Activity

  1. mattsu2020 commented on Oct 1, 2026

    @mattsu2020
    Contributor

    take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions