kumarUjjawal commented on issue #18794:
URL: https://github.com/apache/datafusion/issues/18794#issuecomment-3546648273
- Our SQL parser (via sqlparser-rs) thinks :: has higher precedence than
unary -. So -128::tinyint is parsed as “negate (cast 128 to tinyint)” instead
of “cast (-128)
to tinyint”.
- DataFusion keeps that shape: it builds NEGATE(CAST(128 AS INT8)). Arrow
runs the cast first, sees 128 doesn’t fit into INT8, and errors out before
negation happens.
- With parentheses ((-128)::tinyint) the negative literal is produced
before the cast, so we end up casting -128, which works.
Any query with -<literal>::<narrow_int_type> where the positive literal is
out of range (tinyint, smallint, etc.) will fail even though the negative value
is valid.
We have two options:
1. Change precedence in sqlparser-rs (treat unary - as higher than ::), or
2.. Keep the parser as-is but add a rewrite in DataFusion’s SQL layer so
-(<literal>::type) becomes ( -<literal>)::type
--
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]