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

UPDATE with sub-query that requires type cast gives AssertionError

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.37.0
    • None
    • core
    • None

    Description

      Reproducer (for SqlToRelConverterTest)

      @Test void testUpdateSubQuery() {
      final String sql = "update emp\n"
          + "set empno = (\n"
          + "  select cast(empno as BIGINT) from emp" +
          ")";
      sql(sql).ok();
      }
      

      Produces the following assertion error

      java.lang.AssertionError
          at org.apache.calcite.sql.validate.implicit.AbstractTypeCoercion.needToCast(AbstractTypeCoercion.java:307)
          at org.apache.calcite.sql.validate.implicit.AbstractTypeCoercion.needToCast(AbstractTypeCoercion.java:250)
          at org.apache.calcite.sql.validate.implicit.AbstractTypeCoercion.coerceColumnType(AbstractTypeCoercion.java:210)
          at org.apache.calcite.sql.validate.implicit.TypeCoercionImpl.coerceSourceRowType(TypeCoercionImpl.java:676)
          at org.apache.calcite.sql.validate.implicit.TypeCoercionImpl.querySourceCoercion(TypeCoercionImpl.java:646)
          at org.apache.calcite.sql.validate.SqlValidatorImpl.checkTypeAssignment(SqlValidatorImpl.java:5313)
          at org.apache.calcite.sql.validate.SqlValidatorImpl.validateUpdate(SqlValidatorImpl.java:5420)
          at org.apache.calcite.sql.SqlUpdate.validate(SqlUpdate.java:190)
          at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:1136)
          at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:841)
          at org.apache.calcite.sql.test.AbstractSqlTester.convertSqlToRel2(AbstractSqlTester.java:543)
          at org.apache.calcite.sql.test.AbstractSqlTester.assertSqlConvertsTo(AbstractSqlTester.java:486)
          at org.apache.calcite.sql.test.AbstractSqlTester.assertConvertsTo(AbstractSqlTester.java:464)
          at org.apache.calcite.test.SqlToRelFixture.convertsTo(SqlToRelFixture.java:106)
          at org.apache.calcite.test.SqlToRelFixture.ok(SqlToRelFixture.java:94)
          at org.apache.calcite.test.SqlToRelConverterTest.testUpdateSubQuery(SqlToRelConverterTest.java:3077)
      

      The same query without casting to BIGINT works fine.

      Assertion line

          // Should keep sync with rules in SqlTypeCoercionRule.
          assert SqlTypeUtil.canCastFrom(toType, fromType, mappingRule);
          return true;
      

      When assertion fails, I see that
      toType = INTEGER
      fromType = RecordType(BIGINT EXPR$0)

      Attachments

        1. debug.png
          173 kB
          Pavel Pereslegin

        Issue Links

          Activity

            People

              xtern Pavel Pereslegin
              xtern Pavel Pereslegin
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: