[
https://issues.apache.org/jira/browse/FLINK-33541?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17789330#comment-17789330
]
xuyang commented on FLINK-33541:
--------------------------------
Hi, [~libenchao] , I checked the code again and sorry for this mistake. It
forbids CAST from nullable to not null in `LogicalTypeCasts#defaultMethod` and
I think this is reasonable.
!image-2023-11-24-13-31-21-209.png|width=489,height=325!
{quote}In this case, the argument is literal which is not null, so the result
type is not null is ok. And I don't see many usages to pass in a nullable field
as argument.
{quote}
For example, we have a table with column "a int not null" and "b int". I think
the result type with RAND(a, 10) and RAND(b, 10) is different. The former is
int not null and the latter is int. This difference will and should also affect
the result type about its output.
{quote} Isn't this is the root cause?
{quote}
The inconsistence about the behavior for result type during validation and code
generation in RAND and RAND_INTEGER causes this bug.
Look for your thoughts : )
> RAND_INTEGER can't be existed in a IF statement
> ------------------------------------------------
>
> Key: FLINK-33541
> URL: https://issues.apache.org/jira/browse/FLINK-33541
> Project: Flink
> Issue Type: Bug
> Components: Table SQL / API
> Affects Versions: 1.17.0, 1.18.0
> Reporter: Guojun Li
> Priority: Major
> Labels: pull-request-available
> Attachments: image-2023-11-24-13-31-21-209.png
>
>
> The minimum produce steps:
> Flink SQL> select if(1=1, rand_integer(100), 0);
> [ERROR] Could not execute SQL statement. Reason:
> java.lang.Exception: Unsupported operand types: IF(boolean, INT, INT NOT NULL)
>
> But we do not see the exception reported in 1.14, not sure which version this
> bug was introduced.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)