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

xiong duan commented on CALCITE-1794:
-------------------------------------

[~julianhyde] Looks the CSV example is very special. 

This code can run in JdbcTest directly will reproduce this issue:
{code:java}
@Test void testEqualsAndNotEquals1() {
  CalciteAssert.hr()
          .query("select * from \"hr\".\"emps\" where \"emps\".\"empid\" <> 140 
and \"emps\".\"empid\" = 20")
          .explainContains(""
                  + "EnumerableCalc(expr#0..4=[{inputs}], 
expr#5=[CAST($t0):INTEGER NOT NULL], expr#6=[140], expr#7=[<>($t5, $t6)], 
expr#8=[20], expr#9=[=($t5, $t8)], expr#10=[AND($t7, $t9)], 
proj#0..4=[{exprs}], $condition=[$t10])\n"
                  + "  EnumerableTableScan(table=[[hr, emps]])\n\n");
} {code}
This issue only addresses "Equals AND Not-Equals numeric comparisons".

Maybe understanding CALCITE-4993 together is helpful.

Why CAST?

Because EQUALS operator will make the left RexNode become *[CAST($t0): INTEGER 
NOT NULL]* when the left node and right node have a least restrictive type.

> Simplify AND numeric comparisons when overlapping
> -------------------------------------------------
>
>                 Key: CALCITE-1794
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1794
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.29.0
>            Reporter: Remus Rusanu
>            Assignee: xiong duan
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Expressions such as {{$1<>1 and $1=2}} can be simplified to {{$1=2}}. Similar 
> {{$1>10 AND $1>20}} can be simplified to {{$1>20}}. Such expressions are 
> produced by the proposed solution for CALCITE-1790 (simplify boolean CASE to 
> complex AND/OR).



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to