[
https://issues.apache.org/jira/browse/FLINK-27402?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17551952#comment-17551952
]
godfrey he commented on FLINK-27402:
------------------------------------
[[email protected]] would you like to take this ticket ?
> 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)