Skip to content

Spark dialect: a minus sign before a number literal should bind tighter than :: #3055

Backlog

Description

@andygrove

In Spark SQL, the sign of a number literal is part of the literal (number rule: MINUS? INTEGER_VALUE, MINUS? DECIMAL_VALUE, ...). So -128::TINYINT is CAST(-128 AS TINYINT). SparkSqlDialect parses it as -(128::TINYINT), as the generic dialect does.

With DataFusion on the Spark dialect:

SELECT -128::TINYINT;
-- Arrow error: Cast error: Can't cast value 128 to type Int8

Spark 4.2 returns -128. The same happens for -2147483648::INT and -9223372036854775808::BIGINT. A sign before anything other than a number literal is a unary minus in Spark too, so -a::INT and -(1)::INT already parse correctly as -(a::INT) and -((1)::INT).

Expected: in SparkSqlDialect, a - directly before a numeric literal is part of the literal for the :: that follows, so -128::TINYINT parses as Cast { expr: Value(-128), .. }.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions