[ https://issues.apache.org/jira/browse/FLINK-31003?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17687674#comment-17687674 ]
luoyuxia commented on FLINK-31003: ---------------------------------- Hi, everyone. For me, it seems the same issue of FLINK-30559. Is that right? > Flink SQL IF / CASE WHEN Funcation incorrect > -------------------------------------------- > > Key: FLINK-31003 > URL: https://issues.apache.org/jira/browse/FLINK-31003 > Project: Flink > Issue Type: Bug > Components: Table SQL / API > Affects Versions: 1.15.0, 1.15.1, 1.16.0, 1.15.2, 1.15.3, 1.16.1 > Reporter: weiqinpan > Priority: Major > > When I execute the below sql using sql-client,i found something wrong. > > {code:java} > CREATE TEMPORARY TABLE source ( > mktgmsg_biz_type STRING, > marketing_flow_id STRING, > mktgmsg_campaign_id STRING > ) > WITH > ( > 'connector' = 'filesystem', > 'path' = 'file:///Users/xxx/Desktop/demo.json', > 'format' = 'json' > ); > -- return correct value('marketing_flow_id') > SELECT IF(`marketing_flow_id` IS NOT NULL, `marketing_flow_id`, '') FROM > source; > -- return incorrect value('') > SELECT IF(`marketing_flow_id` IS NULL, '', `marketing_flow_id`) FROM > source;{code} > The demo.json data is > > {code:java} > {"mktgmsg_biz_type": "marketing_flow", "marketing_flow_id": > "marketing_flow_id", "mktgmsg_campaign_id": "mktgmsg_campaign_id"} {code} > > > BTW, use case when + if / ifnull also have something wrong. > > {code:java} > -- return wrong value(''), expect return marketing_flow_id > select CASE > WHEN `mktgmsg_biz_type` = 'marketing_flow' THEN IF(`marketing_flow_id` > IS NULL, `marketing_flow_id`, '') > WHEN `mktgmsg_biz_type` = 'mktgmsg_campaign' THEN > IF(`mktgmsg_campaign_id` IS NULL, '', `mktgmsg_campaign_id`) > ELSE '' > END AS `message_campaign_instance_id` FROM source; > -- return wrong value('') > select CASE > WHEN `mktgmsg_biz_type` = 'marketing_flow' THEN > IFNULL(`marketing_flow_id`, '') > WHEN `mktgmsg_biz_type` = 'mktgmsg_campaign' THEN > IFNULL(`mktgmsg_campaign_id`, '') > ELSE '' > END AS `message_campaign_instance_id` FROM source; > -- return correct value, the difference is [else return ' '] > select CASE > WHEN `mktgmsg_biz_type` = 'marketing_flow' THEN > IFNULL(`marketing_flow_id`, '') > WHEN `mktgmsg_biz_type` = 'mktgmsg_campaign' THEN > IFNULL(`mktgmsg_campaign_id`, '') > ELSE ' ' > END AS `message_campaign_instance_id` FROM source; > {code} > > > -- This message was sent by Atlassian Jira (v8.20.10#820010)