[ 
https://issues.apache.org/jira/browse/FLINK-23614?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17394468#comment-17394468
 ] 

Caizhi Weng commented on FLINK-23614:
-------------------------------------

This is because {{FlinkSqlOperatorTable#TRUNCATE}} is using the function 
definition from Calcite's {{SqlStdOperatorTable#TRUNCATE}}. The return type 
inference of this function is {{ARG0_NULLABLE}} which causes this issue.

Flink already has a self-defined return type inference for this 
({{FlinkReturnTypes#ROUND_FUNCTION_NULLABLE}}). See its usage in 
{{FlinkSqlOperatorTable#ROUND}}. We just need to define our own truncate 
function and add some more tests.

> The resulting scale of TRUNCATE(DECIMAL, ...) is not correct
> ------------------------------------------------------------
>
>                 Key: FLINK-23614
>                 URL: https://issues.apache.org/jira/browse/FLINK-23614
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / Runtime
>    Affects Versions: 1.14.0
>            Reporter: Caizhi Weng
>            Priority: Major
>              Labels: starter
>
> Run the following SQL
> {code:sql}
> SELECT
>   TRUNCATE(123.456, 2),
>   TRUNCATE(123.456, 0),
>   TRUNCATE(123.456, -2),
>   TRUNCATE(CAST(123.456 AS DOUBLE), 2),
>   TRUNCATE(CAST(123.456 AS DOUBLE), 0),
>   TRUNCATE(CAST(123.456 AS DOUBLE), -2)
> {code}
> The result is
> {code}
> 123.450
> 123.000
> 100.000
> 123.45
> 123.0
> 100.0
> {code}
> It seems that the resulting scale of {{TRUNCATE(DECIMAL, ...)}} is the same 
> as that of the input decimal.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to