[
https://issues.apache.org/jira/browse/CALCITE-6874?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
xiong duan updated CALCITE-6874:
--------------------------------
Description:
Currently, if a Project or a Filter contains a Subquery, it may be merged into
Calc. However, Calc is currently unable to handle subqueries.
The unit test in RelOptRulesTest:
{code:java}
@Test void testProjectCalcMergeRule() {
final String sql = "select exists (select deptno from sales.emp)\n"
+ "from (select deptno from sales.emp where empno < 20)\n";
HepProgram program = new HepProgramBuilder()
.addRuleInstance(CoreRules.PROJECT_FILTER_TRANSPOSE)
.addRuleInstance(CoreRules.FILTER_TO_CALC)
.build();
sql(sql)
.withPre(program)
.withRule(CoreRules.PROJECT_CALC_MERGE)
.checkUnchanged();
} {code}
Throws exception:
{code:java}
org.apache.calcite.rex.RexSubQuery cannot be cast to
org.apache.calcite.rex.RexLocalRef
java.lang.ClassCastException: org.apache.calcite.rex.RexSubQuery cannot be cast
to org.apache.calcite.rex.RexLocalRef
at
org.apache.calcite.rex.RexProgramBuilder.registerInput(RexProgramBuilder.java:301)
at
org.apache.calcite.rex.RexProgramBuilder.addProject(RexProgramBuilder.java:210)
at org.apache.calcite.rex.RexProgram.create(RexProgram.java:234)
at org.apache.calcite.rex.RexProgram.create(RexProgram.java:203)
at
org.apache.calcite.rel.rules.ProjectCalcMergeRule.onMatch(ProjectCalcMergeRule.java:77)
at
org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:350)
at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:556)
at org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:420)
at
org.apache.calcite.plan.hep.HepPlanner.executeRuleInstance(HepPlanner.java:243)
at
org.apache.calcite.plan.hep.HepInstruction$RuleInstance$State.execute(HepInstruction.java:178)
at
org.apache.calcite.plan.hep.HepPlanner.lambda$executeProgram$0(HepPlanner.java:211)
at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:423)
at
org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:210)
at org.apache.calcite.plan.hep.HepProgram$State.execute(HepProgram.java:118)
at
org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:205)
at org.apache.calcite.plan.hep.HepPlanner.findBestExp(HepPlanner.java:191)
at
org.apache.calcite.test.RelOptFixture.checkPlanning(RelOptFixture.java:383)
at org.apache.calcite.test.RelOptFixture.check(RelOptFixture.java:334)
at
org.apache.calcite.test.RelOptFixture.checkUnchanged(RelOptFixture.java:326)
at
org.apache.calcite.test.RelOptRulesTest.testProjectCalcMergeRule(RelOptRulesTest.java:9742)
{code}
was:Currently, if a Project or a Filter contains a Subquery, it may be merged
into Calc. However, Calc is currently unable to handle subqueries.
> FilterCalcMergeRule/ProjectCalcMergeRule should not merge a Filter/Project to
> Calc when it contains Subquery
> ------------------------------------------------------------------------------------------------------------
>
> Key: CALCITE-6874
> URL: https://issues.apache.org/jira/browse/CALCITE-6874
> Project: Calcite
> Issue Type: Bug
> Reporter: xiong duan
> Priority: Major
> Labels: pull-request-available
>
> Currently, if a Project or a Filter contains a Subquery, it may be merged
> into Calc. However, Calc is currently unable to handle subqueries.
> The unit test in RelOptRulesTest:
> {code:java}
> @Test void testProjectCalcMergeRule() {
> final String sql = "select exists (select deptno from sales.emp)\n"
> + "from (select deptno from sales.emp where empno < 20)\n";
> HepProgram program = new HepProgramBuilder()
> .addRuleInstance(CoreRules.PROJECT_FILTER_TRANSPOSE)
> .addRuleInstance(CoreRules.FILTER_TO_CALC)
> .build();
> sql(sql)
> .withPre(program)
> .withRule(CoreRules.PROJECT_CALC_MERGE)
> .checkUnchanged();
> } {code}
> Throws exception:
> {code:java}
> org.apache.calcite.rex.RexSubQuery cannot be cast to
> org.apache.calcite.rex.RexLocalRef
> java.lang.ClassCastException: org.apache.calcite.rex.RexSubQuery cannot be
> cast to org.apache.calcite.rex.RexLocalRef
> at
> org.apache.calcite.rex.RexProgramBuilder.registerInput(RexProgramBuilder.java:301)
> at
> org.apache.calcite.rex.RexProgramBuilder.addProject(RexProgramBuilder.java:210)
> at org.apache.calcite.rex.RexProgram.create(RexProgram.java:234)
> at org.apache.calcite.rex.RexProgram.create(RexProgram.java:203)
> at
> org.apache.calcite.rel.rules.ProjectCalcMergeRule.onMatch(ProjectCalcMergeRule.java:77)
> at
> org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:350)
> at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:556)
> at org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:420)
> at
> org.apache.calcite.plan.hep.HepPlanner.executeRuleInstance(HepPlanner.java:243)
> at
> org.apache.calcite.plan.hep.HepInstruction$RuleInstance$State.execute(HepInstruction.java:178)
> at
> org.apache.calcite.plan.hep.HepPlanner.lambda$executeProgram$0(HepPlanner.java:211)
> at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:423)
> at
> org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:210)
> at
> org.apache.calcite.plan.hep.HepProgram$State.execute(HepProgram.java:118)
> at
> org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:205)
> at org.apache.calcite.plan.hep.HepPlanner.findBestExp(HepPlanner.java:191)
> at
> org.apache.calcite.test.RelOptFixture.checkPlanning(RelOptFixture.java:383)
> at org.apache.calcite.test.RelOptFixture.check(RelOptFixture.java:334)
> at
> org.apache.calcite.test.RelOptFixture.checkUnchanged(RelOptFixture.java:326)
> at
> org.apache.calcite.test.RelOptRulesTest.testProjectCalcMergeRule(RelOptRulesTest.java:9742)
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)