Hi! Any idea why: ```SELECT sign(CAST(0 AS INTEG...
# troubleshooting
d
Hi! Any idea why:
Copy code
SELECT sign(CAST(0 AS INTEGER))
or
Copy code
SELECT sign(CAST(0 AS BIGINT))
works, but
Copy code
SELECT sign(CAST(0 AS TINYINT))
and
Copy code
SELECT sign(CAST(0 AS SMALLINT))
error out? More specifically, using PyFlink (Python 3.10.12, PyFlink 1.17.1):
st_env.sql_query("SELECT sign(CAST(0 AS TINYINT))").to_pandas()
Error below:
Untitled
m
I think it's already mentioned in the stacktrace:
Assignment conversion not possible from type "float" to type "byte"
j
The default conversion class for
TINYINT
is
Byte
, and for
SMALLINT
is
Short
d
Sorry, I don't think I understand. Is this expected behavior, then? If I want to safely use
SIGN
with numeric types, do I need to always manually upcast to
INTEGER
or larger first?
j
Is this expected behavior, then?
Under the hood, the
SIGN
function calls
java.lang.Math#signum
,
java.lang.Integer#signum
or
java.lang.Long#signum
, according to input type, respectively. While for input type
byte
or
short
, it'll be first cast to
int
and then passed to
java.lang.Integer#signum
. While the result type
int
cannot be safely cast back to
byte
or
short
, the exception is thrown.
do I need to always manually upcast to INTEGER or larger first?
I believe so.
πŸ‘€ 1
d
Thanks for the explanation!