Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
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:
@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(); }
Throws exception:
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)
Attachments
Issue Links
- is related to
-
CALCITE-6870 The FilterToCalcRule/ProjectToCalcRule should not convert a Filter/Project to Calc when it contains Subquery
-
- Closed
-
- links to