Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-8107

UNNEST causes cyclic type checking exception

    XMLWordPrintableJSON

Details

    Description

      The following query causes an assertion error:

        def main(args: Array[String]): Unit = {
          val env = ExecutionEnvironment.getExecutionEnvironment
          val tEnv = TableEnvironment.getTableEnvironment(env)
      
          val input2 = env.fromElements(
            WC("hello", 1, Array(1, 2, 3)),
            WC("hello", 1, Array(1, 2, 3)),
            WC("ciao", 1, Array(1, 2, 3))
          )
      
          tEnv.registerDataSet("entity", input2)
          tEnv.registerDataSet("product", input2, 'product)
      
          val table = tEnv.sqlQuery("SELECT t.item.* FROM product, UNNEST(entity.myarr) AS t (item)")
      
          table.toDataSet[Row].print()
        }
      
        case class WC(word: String, frequency: Long, myarr: Array[Int])
      

      It leads to:

      Exception in thread "main" java.lang.AssertionError: Cycle detected during type-checking
      	at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:93)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:945)
      	at org.apache.calcite.sql.validate.AbstractNamespace.getRowType(AbstractNamespace.java:115)
      	at org.apache.calcite.sql.validate.AbstractNamespace.getRowTypeSansSystemColumns(AbstractNamespace.java:122)
      	at org.apache.calcite.sql.validate.AliasNamespace.validateImpl(AliasNamespace.java:71)
      	at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:945)
      	at org.apache.calcite.sql.validate.AbstractNamespace.getRowType(AbstractNamespace.java:115)
      	at org.apache.calcite.sql.validate.AliasNamespace.getRowType(AliasNamespace.java:41)
      	at org.apache.calcite.sql.validate.DelegatingScope.resolveInNamespace(DelegatingScope.java:101)
      	at org.apache.calcite.sql.validate.ListScope.resolve(ListScope.java:191)
      	at org.apache.calcite.sql.validate.ListScope.findQualifyingTableNames(ListScope.java:156)
      	at org.apache.calcite.sql.validate.DelegatingScope.fullyQualify(DelegatingScope.java:326)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateIdentifier(SqlValidatorImpl.java:2785)
      	at org.apache.calcite.sql.SqlIdentifier.validateExpr(SqlIdentifier.java:324)
      	at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5084)
      	at org.apache.calcite.sql.validate.UnnestNamespace.validateImpl(UnnestNamespace.java:52)
      	at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:945)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:926)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:2961)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:2946)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateJoin(SqlValidatorImpl.java:2998)
      	at org.apache.flink.table.calcite.FlinkCalciteSqlValidator.validateJoin(FlinkCalciteSqlValidator.scala:67)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:2955)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3206)
      	at org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
      	at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:945)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:926)
      	at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:226)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:901)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:611)
      	at org.apache.flink.table.calcite.FlinkPlannerImpl.validate(FlinkPlannerImpl.scala:89)
      	at org.apache.flink.table.api.TableEnvironment.sqlQuery(TableEnvironment.scala:561)
      	at org.apache.flink.table.examples.scala.WordCountSQL$.main(WordCountSQL.scala:57)
      	at org.apache.flink.table.examples.scala.WordCountSQL.main(WordCountSQL.scala)
      

      I think this is a Calcite bug but we have to check that first.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              twalthr Timo Walther
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: