[
https://issues.apache.org/jira/browse/CALCITE-6422?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Mihai Budiu resolved CALCITE-6422.
----------------------------------
Fix Version/s: 1.38.0
Resolution: Fixed
Fixed by
https://github.com/apache/calcite/commit/6b577851fbdc4cb87aca2c939cf74bfd9d5f3eb8
Thank you for the contribution [~4wei]
> Query with '<>' throws NullPointerException during materialized view matching
> -----------------------------------------------------------------------------
>
> Key: CALCITE-6422
> URL: https://issues.apache.org/jira/browse/CALCITE-6422
> Project: Calcite
> Issue Type: Bug
> Reporter: Mou Wu
> Assignee: Mou Wu
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.38.0
>
>
> 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:
> {code:java}
> @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();
> } {code}
> 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
--
This message was sent by Atlassian Jira
(v8.20.10#820010)