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

Wang Yanlin commented on CALCITE-3347:
--------------------------------------

In the original case of "TestCalcite.java", when *FilterIntoJoinRule* matched 
with
{code:none}
EnumerableFilter.ENUMERABLE.[](input=RelSubset#38,condition==($1, 0))
{code}
and 
{code:none}
EnumerableHashJoin.ENUMERABLE.[](left=RelSubset#17,right=RelSubset#73,condition==($0,
 $3),joinType=semi)
{code}
The dumped plan is like this

{noformat}
EnumerableFilter.ENUMERABLE.[](input=RelSubset#38,condition==($1, 0))
  
EnumerableHashJoin.ENUMERABLE.[](left=RelSubset#17,right=RelSubset#73,condition==($0,
 $3),joinType=semi)
    EnumerableTableScan(subset=[rel#17:Subset#0.ENUMERABLE.[]], 
table=[[tblspace1, tsql]])
    LogicalAggregate(subset=[rel#23:Subset#3.NONE.[]], group=[{0}])
      LogicalProject(subset=[rel#21:Subset#2.NONE.[]], K1=[$0])
        LogicalFilter(subset=[rel#19:Subset#1.NONE.[]], condition=[=($1, 1)])
          EnumerableTableScan(subset=[rel#17:Subset#0.ENUMERABLE.[]], 
table=[[tblspace1, tsql]])
{noformat}

The rowType of join is

{noformat}
RecordType(VARCHAR NOT NULL k1, INTEGER NOT NULL n1, VARCHAR NOT NULL s1) NOT 
NULL
{noformat}

In this case, *FilterIntoJoinRule* tries to push filter condition *==($1, 0)* 
into filter's left, 
and push join condition *==($0, $3)* above join.
But the rowType of join has only 3 fields, causing the exception.

I think the cause is in here [call of 
validateJoinFilters|https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/rules/FilterJoinRule.java#L183].
 Trying to push filter condition *==($0, $3)* above EnumerableHashJoin, but 
actually should not.

> IndexOutOfBoundsException in FixNullabilityShuttle when using 
> FilterIntoJoinRule
> --------------------------------------------------------------------------------
>
>                 Key: CALCITE-3347
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3347
>             Project: Calcite
>          Issue Type: Bug
>    Affects Versions: 1.21.0
>            Reporter: Amit Chavan
>            Priority: Major
>         Attachments: TestCalcite.java
>
>
> I am reporting a bug that happens in calcite 1.21 release. I have a query as 
> below 
>  String query = "SELECT * FROM tblspace1.tsql where n1=? and k1 in (SELECT k1 
> FROM tblspace1.tsql where n1=?)";
>   
>  I am also attaching the unit test to reproduce this issue.  
>   
>  The filterJoinRule throws an exception –
>  java.lang.RuntimeException: Error while applying rule 
> FilterJoinRule:FilterJoinRule:filter, args 
> [rel#39:EnumerableFilter.ENUMERABLE.[](input=RelSubset#38,condition==($1, 
> ?0)), 
> rel#176:EnumerableHashJoin.ENUMERABLE.[](left=RelSubset#17,right=RelSubset#73,condition==($0,
>  $3),joinType=semi)]
>  at 
> org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:235)
>  at 
> org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:631)
>  at org.apache.calcite.TestCalcite.testQuery(TestCalcite.java:199)
>  at org.apache.calcite.TestCalcite.problem_with_1_21(TestCalcite.java:256)
>  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:497)
>  at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>  at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>  at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>  at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
>  at 
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
>  at 
> com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
>  at 
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
>  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
>  Caused by: java.lang.IndexOutOfBoundsException: index (3) must be less than 
> size (3)
>  at 
> com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:310)
>  at 
> com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:293)
>  at 
> com.google.common.collect.RegularImmutableList.get(RegularImmutableList.java:67)
>  at 
> com.google.common.collect.Lists$TransformingRandomAccessList.get(Lists.java:627)
>  at 
> org.apache.calcite.rex.RexUtil$FixNullabilityShuttle.visitInputRef(RexUtil.java:2529)
>  at 
> org.apache.calcite.rex.RexUtil$FixNullabilityShuttle.visitInputRef(RexUtil.java:2518)
>  at org.apache.calcite.rex.RexInputRef.accept(RexInputRef.java:112)
>  at org.apache.calcite.rex.RexShuttle.visitList(RexShuttle.java:149)
>  at org.apache.calcite.rex.RexShuttle.visitCall(RexShuttle.java:101)
>  at org.apache.calcite.rex.RexShuttle.visitCall(RexShuttle.java:34)
>  at org.apache.calcite.rex.RexCall.accept(RexCall.java:191)
>  at org.apache.calcite.rex.RexShuttle.apply(RexShuttle.java:277)
>  at org.apache.calcite.rex.RexShuttle.mutate(RexShuttle.java:239)
>  at org.apache.calcite.rex.RexShuttle.apply(RexShuttle.java:257)
>  at org.apache.calcite.rex.RexUtil.fixUp(RexUtil.java:1635)
>  at 
> org.apache.calcite.rel.rules.FilterJoinRule.perform(FilterJoinRule.java:284)
>  at 
> org.apache.calcite.rel.rules.FilterJoinRule$FilterIntoJoinRule.onMatch(FilterJoinRule.java:383)
>  at 
> org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:208)
>  ... 25 more
>   
>   



--
This message was sent by Atlassian Jira
(v8.3.2#803003)

Reply via email to