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

Window function does not work in LATERAL

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0.0-incubating
    • 1.17.0
    • None
    • None

    Description

        @Test public void testLateralWithOver() {
          CalciteAssert.that()
              .with(CalciteAssert.Config.REGULAR)
              .query("select * from \"hr\".\"emps\",\n"
                  + " LATERAL (select \"depts\".*, max(\"deptno\" + \"emps\".\"empid\") over (partition by \"emps\".\"deptno\") from \"hr\".\"depts\" where \"emps\".\"deptno\" = \"depts\".\"deptno\")")
              .returnsUnordered(
                  "not_yet_sure");
        }
      
      java.lang.RuntimeException: exception while executing [select * from "hr"."emps",
       LATERAL (select "depts".*, max("deptno" + "emps"."empid") over (partition by "emps"."deptno") from "hr"."depts" where "emps"."deptno" = "depts"."deptno")]
      	at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1081)
      	at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1071)
      	at org.apache.calcite.test.CalciteAssert$AssertQuery.returnsUnordered(CalciteAssert.java:1087)
      	at org.apache.calcite.test.JdbcTest.testLateralWithOver(JdbcTest.java:2030)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
      	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
      Caused by: java.lang.RuntimeException: With materializationsEnabled=false, limit=0
      	at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:440)
      	at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1077)
      	... 29 more
      Caused by: java.lang.AssertionError: Internal error: todo: Cycle detected during type-checking
      	at org.apache.calcite.util.Util.newInternal(Util.java:727)
      	at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:105)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:821)
      	at org.apache.calcite.sql.validate.AbstractNamespace.getRowType(AbstractNamespace.java:124)
      	at org.apache.calcite.sql.validate.SelectNamespace.getRowType(SelectNamespace.java:30)
      	at org.apache.calcite.sql.validate.ListScope.findQualifyingTableName(ListScope.java:101)
      	at org.apache.calcite.sql.validate.ListScope.findQualifyingTableName(ListScope.java:109)
      	at org.apache.calcite.sql.validate.DelegatingScope.fullyQualify(DelegatingScope.java:154)
      	at org.apache.calcite.sql.SqlIdentifier.getMonotonicity(SqlIdentifier.java:264)
      	at org.apache.calcite.sql.validate.SelectScope.getMonotonicity(SelectScope.java:154)
      	at org.apache.calcite.sql.SqlWindow.isTableSorted(SqlWindow.java:346)
      	at org.apache.calcite.sql.SqlWindow.validate(SqlWindow.java:567)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateWindow(SqlValidatorImpl.java:3754)
      	at org.apache.calcite.sql.SqlOverOperator.validateCall(SqlOverOperator.java:70)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:3794)
      	at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:106)
      	at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:229)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateExpr(SqlValidatorImpl.java:3226)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList(SqlValidatorImpl.java:3211)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:2904)
      	at org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
      	at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:86)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:821)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:810)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:2691)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:2676)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateJoin(SqlValidatorImpl.java:2713)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:2685)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:2894)
      	at org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
      	at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:86)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:821)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:810)
      	at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:207)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:784)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:500)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:522)
      	at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:226)
      	at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:192)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:486)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:383)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:352)
      	at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:174)
      	at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:471)
      	at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:434)
      	at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:117)
      	at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:415)
      	... 30 more
      

      Attachments

        Issue Links

          Activity

            People

              julianhyde Julian Hyde
              vladimirsitnikov Vladimir Sitnikov
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: