You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "luoyuxia (Jira)" <ji...@apache.org> on 2022/04/26 02:49:00 UTC

[jira] [Commented] (FLINK-27402) Unexpected boolean expression simplification for AND expression

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

luoyuxia commented on FLINK-27402:
----------------------------------

We also encounter the some problem when working with Hive dialect [FLINK-27296|https://issues.apache.org/jira/browse/FLINK-27296].

[~godfreyhe] Cound you please have a look? Is it a problem should be fix? If it is, I would  to take it so that I can work on Hive dialect compatibility.

> Unexpected boolean expression simplification  for AND expression 
> -----------------------------------------------------------------
>
>                 Key: FLINK-27402
>                 URL: https://issues.apache.org/jira/browse/FLINK-27402
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / Planner
>            Reporter: luoyuxia
>            Priority: Major
>
> Flink supports to compare between string and boolean, so the following sql can work fine
>  
> {code:java}
> create table (c1 int, c2 string);
> select * from c2 = true;
> {code}
> But the following sql will throw excpetion 
>  
> {code:java}
> select * from c1 = 1 and c2 = true; {code}
> The reason it that Flink will try to simplify BOOLEAN expressions if possible in 
> "c1 = 1 and c2 = true".
> So "c2 = true" will be simplified to "c2" by the following code in Flink:
>  
> {code:java}
> RexSimplify#simplifyAnd2ForUnknownAsFalse
> // Simplify BOOLEAN expressions if possible
> while (term.getKind() == SqlKind.EQUALS) {
>     RexCall call = (RexCall) term;
>     if (call.getOperands().get(0).isAlwaysTrue()) {
>         term = call.getOperands().get(1);
>         terms.set(i, term);
>         continue;
>     } else if (call.getOperands().get(1).isAlwaysTrue()) {
>         term = call.getOperands().get(0);
>         terms.set(i, term);
>         continue;
>     }
>     break;
> } {code}
> So the expression will be reduced to ""c1 = 1 and c2". But AND requries both sides are boolean expression and c2 is not a boolean expression for it actually is a string.
> Then the exception "Boolean expression type expected" is thrown.
>  



--
This message was sent by Atlassian Jira
(v8.20.7#820007)