Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-3457

RexSimplify incorrectly simplifies IS NOT NULL operator with ITEM call

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.22.0
    • 1.22.0
    • None

    Description

      In CALCITE-3390 ITEM was marked with Policy.ANY strong policy, but according to its JavaDoc, the result may be null if and only if at least one of its arguments is null. This statement was used in RexSimplify.simplifyIsNotNull() method, so t1.c_nationkey[0] is not null will be simplified to IS NOT NULL($0) which is wrong, since array may be empty, or index may be less than the size of the array.

      Unit test which helps to reproduce this issue:

        @Test public void testSimplifyItemIsNotNull() {
          String query = "select * from sales.customer as t1 where t1.c_nationkey[0] is not null";
      
          sql(query)
              .withTester(t -> createDynamicTester())
              .withRule(ReduceExpressionsRule.FILTER_INSTANCE)
              .check();
        }
      

      Returns plan with incorrectly simplified ITEM expression:

      LogicalProject(**=[$1])
        LogicalFilter(condition=[IS NOT NULL($0)])
          LogicalTableScan(table=[[CATALOG, SALES, CUSTOMER]])
      

      But the initial intention of CALCITE-3390 was to allow pushing ITEM expression to the right input of left-outer-join.

      I propose to add a new element to the Policy which will have a relaxed condition - expression is null if at least one of its arguments is null.

      Attachments

        Issue Links

          Activity

            People

              danny0405 Danny Chen
              volodymyr Vova Vysotskyi
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 20m
                  1h 20m