[
https://issues.apache.org/jira/browse/CALCITE-6422?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Mou Wu updated CALCITE-6422:
----------------------------
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:
{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.
was:
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 NPE will be thrown:
{code:java}
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)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
at
org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at
org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at
org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
at
org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
at
org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
at
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
at
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
at
org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at
org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at
org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at
org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
at
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
at
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
at
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
at
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
at
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
at
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
at
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at
org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at
org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at
org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.util.ArrayList.forEach(ArrayList.java:1259) at
org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at
org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at
org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at
org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.util.ArrayList.forEach(ArrayList.java:1259) at
org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at
org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at
org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at
org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at
org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at
org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at
org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at
org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
at
org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
at
org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
at
org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
at
org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
at
org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
at
org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at
org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at
org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at
org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
at
com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
at
com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at
com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at
com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at
com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)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{code}
> 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
>
> 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.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)