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

Query with '<>' throws NullPointerException during materialized view matching

    XMLWordPrintableJSON

Details

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

    Description

      If a materialized view compares two nullable columns using '=', and a query on that materialized view compares the same column using '<>', SubstitutionVisitor.mayBeSatisfiable causes RexLiteral.booleanValue to throw a NullPointerException.

      Add the test case in MaterializedViewRelOptRulesTest to reproduce this bug:

      @Test public void testNpeInSplitFilterOfSubstitutionVisitor() {
        sql("select \"col1\", \"col2\""
                + " from \"nullables\""
                + " where \"col1\" <> \"col2\" and \"col3\" = 1",
            "select \"col1\", \"col2\""
                + " from \"nullables\""
                + " where \"col1\" = \"col2\" and \"col3\" = 1")
            .checkingThatResultContains(""
                + "EnumerableCalc(expr#0..2=[{inputs}], expr#3=[=($t0, $t1)], expr#4=[CAST($t2):INTEGER NOT NULL], expr#5=[1], expr#6=[=($t4, $t5)], expr#7=[AND($t3, $t6)], proj#0..1=[{exprs}], $condition=[$t7])\n"
                + "  EnumerableTableScan(table=[[hr, nullables]])")
            .ok();
      } 

      Notes: col1 and col2 of table nullables should be nullable.

      A NullPointerException will be thrown:
       
      java.lang.RuntimeException: Error while applying rule MaterializedViewJoinRule(Filter), args rel#65:LogicalFilter.NONE.[](input=RelSubset#64,condition=AND(=($0, $1), =(CAST($2):INTEGER NOT NULL, 1)))
          at org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:250)
          at org.apache.calcite.plan.volcano.IterativeRuleDriver.drive(IterativeRuleDriver.java:59)
          at org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:524)
          at org.apache.calcite.tools.Programs.lambda$standard$3(Programs.java:282)
          at org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:348)
          at org.apache.calcite.test.MaterializedViewRelOptRulesTest$1.optimize(MaterializedViewRelOptRulesTest.java:51)
          at org.apache.calcite.test.MaterializedViewTester.checkMaterialize(MaterializedViewTester.java:77)
          at org.apache.calcite.test.MaterializedViewFixture.ok(MaterializedViewFixture.java:56)
          at org.apache.calcite.test.MaterializedViewRelOptRulesTest.testNpeInSplitFilterOfSubstitutionVisitor(MaterializedViewRelOptRulesTest.java:1241)
      Caused by: java.lang.NullPointerException
          at org.apache.calcite.rex.RexLiteral.booleanValue(RexLiteral.java:1182)
          at org.apache.calcite.plan.SubstitutionVisitor.mayBeSatisfiable(SubstitutionVisitor.java:446)
          at org.apache.calcite.plan.SubstitutionVisitor.splitFilter(SubstitutionVisitor.java:310)
          at org.apache.calcite.rel.rules.materialize.MaterializedViewRule.computeCompensationPredicates(MaterializedViewRule.java:862)
          at org.apache.calcite.rel.rules.materialize.MaterializedViewRule.perform(MaterializedViewRule.java:364)
          at org.apache.calcite.rel.rules.materialize.MaterializedViewOnlyFilterRule.onMatch(MaterializedViewOnlyFilterRule.java:50)
          at org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:223)
          ... 78 more

      Attachments

        Issue Links

          Activity

            People

              4wei Mou Wu
              4wei Mou Wu
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: