[
https://issues.apache.org/jira/browse/FLINK-41786?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18154421#comment-18154421
]
yongfu.gao commented on FLINK-41786:
------------------------------------
I reproduced this with SIGN and TRUNCATE over TINYINT and SMALLINT values. The
planner selected the INTEGER runtime methods, so the generated code failed with
CompileException: Assignment conversion not possible from type "int" to type
"byte"/"short". I added dedicated type-preserving overloads and registered them
for SIGN plus one- and two-argument TRUNCATE. MathFunctionsITCase now covers
both types through the Table API and SQL. PR:
https://github.com/apache/flink/pull/30251
Could a committer please assign this issue to me (linkgoal)?
Release note: Fixes a CompileException when SIGN or TRUNCATE is evaluated on a
TINYINT or SMALLINT value; both functions now return the argument type.
> SIGN and TRUNCATE fail to compile for TINYINT and SMALLINT
> ----------------------------------------------------------
>
> Key: FLINK-41786
> URL: https://issues.apache.org/jira/browse/FLINK-41786
> Project: Flink
> Issue Type: Bug
> Components: Table SQL / Planner
> Affects Versions: 2.3.0
> Reporter: Ramin Gharib
> Priority: Major
> Labels: pull-request-available
>
> SIGN and TRUNCATE fail with a compile error when the argument is a TINYINT or
> a SMALLINT. ROUND works for the same types.
> {code:sql}
> SELECT n, SIGN(n) AS s FROM (VALUES (CAST(-5 AS TINYINT)), (CAST(3 AS
> TINYINT))) AS t(n);
> SELECT n, TRUNCATE(n, -1) AS r FROM (VALUES (CAST(1259 AS SMALLINT)),
> (CAST(-1259 AS SMALLINT))) AS t(n);
> {code}
> ||Call||Expected||Actual||
> |{{SIGN(CAST(-5 AS TINYINT))}}|-1|Table program cannot be compiled|
> |{{SIGN(CAST(-5 AS SMALLINT))}}|-1|Table program cannot be compiled|
> |{{TRUNCATE(CAST(125 AS TINYINT), -1)}}|120|Table program cannot be compiled|
> |{{TRUNCATE(CAST(1259 AS SMALLINT), -1)}}|1250|Table program cannot be
> compiled|
> |{{ROUND(CAST(1259 AS SMALLINT), -1)}}|1260|1260|
> The root cause is a {{CompileException}}, such as {{Assignment conversion not
> possible from type "int" to type "short"}} for TRUNCATE. For SIGN, the source
> type in the message changes between runs, {{"int"}} or {{"float"}}. The same
> in batch and streaming mode.
> h3. Cause
> {{FunctionGenerator}} registers ROUND for TINYINT and SMALLINT
> ({{ROUND_BYTE}}, {{ROUND_SHORT}}), but SIGN only for INTEGER, BIGINT, DOUBLE
> and DECIMAL (lines 123-130), and TRUNCATE only for INTEGER, BIGINT, DECIMAL,
> FLOAT and DOUBLE (lines 411-427). For a TINYINT or SMALLINT, the lookup picks
> a method of a wider type, and the generated code assigns its result to a
> {{byte}} or {{short}} without a cast.
> h3. Proposal
> Register TINYINT and SMALLINT for SIGN and TRUNCATE, as for ROUND, so the
> result keeps the type of the argument.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)