Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-1524

Add a project to the planner root so that rules know which output fields are used

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.11.0
    • Component/s: None
    • Labels:
      None

      Description

      Add a project to the planner root so that rules know which output fields are used.

      One such rule is SemiJoinRule; it can only apply if it knows that no fields are used from the right-hand input, so it has to match a Project at the root of its pattern.

        Activity

        Hide
        julianhyde Julian Hyde added a comment -

        Resolved in release 1.11.0 (2017-01-11).

        Show
        julianhyde Julian Hyde added a comment - Resolved in release 1.11.0 (2017-01-11).
        Hide
        julianhyde Julian Hyde added a comment -

        OK, I'll take a look.

        Show
        julianhyde Julian Hyde added a comment - OK, I'll take a look.
        Hide
        maryannxue Maryann Xue added a comment -

        Julian Hyde, your fix has broken something:
        Try:

          @Test public void testOrderByQueryOnProjectView() {
            checkMaterialize(
                "select \"deptno\", \"empid\" from \"emps\"",
                "select \"empid\" from \"emps\" order by \"deptno\"");
          }
        

        You will get an exception like:

        java.lang.AssertionError: Type mismatch:
        rowtype of new rel:
        RecordType(JavaType(int) NOT NULL empid) NOT NULL
        rowtype of set:
        RecordType(JavaType(int) NOT NULL empid, JavaType(int) NOT NULL deptno) NOT NULL
        	at org.apache.calcite.util.Litmus$1.fail(Litmus.java:31)
        	at org.apache.calcite.plan.RelOptUtil.equal(RelOptUtil.java:1820)
        	at org.apache.calcite.plan.volcano.RelSubset.add(RelSubset.java:273)
        	at org.apache.calcite.plan.volcano.RelSet.add(RelSet.java:148)
        	at org.apache.calcite.plan.volcano.VolcanoPlanner.addRelToSet(VolcanoPlanner.java:1804)
        	at org.apache.calcite.plan.volcano.VolcanoPlanner.registerImpl(VolcanoPlanner.java:1750)
        	at org.apache.calcite.plan.volcano.VolcanoPlanner.useMaterialization(VolcanoPlanner.java:380)
        	at org.apache.calcite.plan.volcano.VolcanoPlanner.useMaterializations(VolcanoPlanner.java:438)
        	at org.apache.calcite.plan.volcano.VolcanoPlanner.useApplicableMaterializations(VolcanoPlanner.java:460)
        	at org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:745)
        	at org.apache.calcite.tools.Programs$5.run(Programs.java:300)
        	at org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:351)
        	at org.apache.calcite.prepare.Prepare.optimize(Prepare.java:158)
        	at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:285)
        	at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:200)
        	at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:748)
        	at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:610)
        	at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:580)
        	at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:215)
        	at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:594)
        	at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:615)
        	at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:148)
        	at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
        	at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:482)
        	at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1229)
        	at org.apache.calcite.test.CalciteAssert$AssertQuery.explainMatches(CalciteAssert.java:1315)
        	at org.apache.calcite.test.MaterializationTest.checkMaterialize(MaterializationTest.java:195)
        	at org.apache.calcite.test.MaterializationTest.checkMaterialize(MaterializationTest.java:154)
        	at org.apache.calcite.test.MaterializationTest.testOrderByQueryOnProjectView(MaterializationTest.java:539)
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        	at java.lang.reflect.Method.invoke(Method.java:606)
        	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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
        	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
        	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
        	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
        	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
        

        This test case is marked as @Ignore currently, but is good enough to show the problem.

        Show
        maryannxue Maryann Xue added a comment - Julian Hyde , your fix has broken something: Try: @Test public void testOrderByQueryOnProjectView() { checkMaterialize( "select \" deptno\ ", \" empid\ " from \" emps\"", "select \" empid\ " from \" emps\ " order by \" deptno\""); } You will get an exception like: java.lang.AssertionError: Type mismatch: rowtype of new rel: RecordType(JavaType( int ) NOT NULL empid) NOT NULL rowtype of set: RecordType(JavaType( int ) NOT NULL empid, JavaType( int ) NOT NULL deptno) NOT NULL at org.apache.calcite.util.Litmus$1.fail(Litmus.java:31) at org.apache.calcite.plan.RelOptUtil.equal(RelOptUtil.java:1820) at org.apache.calcite.plan.volcano.RelSubset.add(RelSubset.java:273) at org.apache.calcite.plan.volcano.RelSet.add(RelSet.java:148) at org.apache.calcite.plan.volcano.VolcanoPlanner.addRelToSet(VolcanoPlanner.java:1804) at org.apache.calcite.plan.volcano.VolcanoPlanner.registerImpl(VolcanoPlanner.java:1750) at org.apache.calcite.plan.volcano.VolcanoPlanner.useMaterialization(VolcanoPlanner.java:380) at org.apache.calcite.plan.volcano.VolcanoPlanner.useMaterializations(VolcanoPlanner.java:438) at org.apache.calcite.plan.volcano.VolcanoPlanner.useApplicableMaterializations(VolcanoPlanner.java:460) at org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:745) at org.apache.calcite.tools.Programs$5.run(Programs.java:300) at org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:351) at org.apache.calcite.prepare.Prepare.optimize(Prepare.java:158) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:285) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:200) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:748) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:610) at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:580) at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:215) at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:594) at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:615) at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:148) at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218) at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:482) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1229) at org.apache.calcite.test.CalciteAssert$AssertQuery.explainMatches(CalciteAssert.java:1315) at org.apache.calcite.test.MaterializationTest.checkMaterialize(MaterializationTest.java:195) at org.apache.calcite.test.MaterializationTest.checkMaterialize(MaterializationTest.java:154) at org.apache.calcite.test.MaterializationTest.testOrderByQueryOnProjectView(MaterializationTest.java:539) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) 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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) This test case is marked as @Ignore currently, but is good enough to show the problem.
        Show
        julianhyde Julian Hyde added a comment - Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/751e2b0c .

          People

          • Assignee:
            julianhyde Julian Hyde
            Reporter:
            julianhyde Julian Hyde
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development