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

Vladimir Sitnikov commented on CALCITE-2438:
--------------------------------------------

Note: I have added NOT to the equations above, and it identified one more bug 
like {{simplify.simplify(isNull(not(arg)))}}.
The suggested changes so far are:
org.apache.calcite.rex.RexCall
{code:java}  @Override public boolean isAlwaysTrue() {
    // "c IS NOT NULL" occurs when we expand EXISTS.
    // This reduction allows us to convert it to a semi-join.
    switch (getKind()) {
    case IS_NOT_NULL:
      return !operands.get(0).getType().isNullable();
    case IS_TRUE:
    case IS_NOT_FALSE:
      return operands.get(0).isAlwaysTrue();
    case NOT:
      return operands.get(0).isAlwaysFalse();
    case IS_NOT_TRUE:
    case IS_FALSE:
      return operands.get(0).isAlwaysFalse();
    case CAST:
      return operands.get(0).isAlwaysTrue();
    default:
      return false;
    }
  }

  @Override public boolean isAlwaysFalse() {
    switch (getKind()) {
    case IS_NULL:
      return !operands.get(0).getType().isNullable();
    case IS_FALSE:
    case IS_NOT_TRUE:
    case NOT:
      return operands.get(0).isAlwaysTrue();
    case IS_NOT_FALSE:
    case IS_TRUE:
    case CAST:
      return operands.get(0).isAlwaysFalse();
    default:
      return false;
    }
  }
{code}
and org.apache.calcite.sql.SqlKind
{code:java}  public SqlKind negateNullSafe() {
...
    case IS_NULL:
    case IS_NOT_NULL:
      return this; // :)
...
}{code}

> RexCall#isAlwaysTrue  return incorrect result
> ---------------------------------------------
>
>                 Key: CALCITE-2438
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2438
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.17.0
>            Reporter: pengzhiwei
>            Assignee: Julian Hyde
>            Priority: Critical
>         Attachments: 屏幕快照 2018-08-02 下午7.26.20.png, 屏幕快照 2018-08-02 
> 下午7.34.26.png
>
>
> In the expression as followed:
> {code:java}
> ((sal IS NULL) IS NOT NULL) IS FALSE
> {code}
> The RexCall#isAlwaysTrue return true,however the correct answer is false.
> I find the reason is that there is a wrong logic in the  isAlwaysTrue,when 
> getKind() is IS_NOT_FALSE、IS_FALSE and IS_NOT_FALSE :
> !屏幕快照 2018-08-02 下午7.34.26.png!
> Can you have a check for me,thanks!



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to