Pavel Pereslegin created CALCITE-6570:
-----------------------------------------
Summary: Assertion error when validating an UPDATE query with a
subquery expression
Key: CALCITE-6570
URL: https://issues.apache.org/jira/browse/CALCITE-6570
Project: Calcite
Issue Type: Bug
Components: core
Reporter: Pavel Pereslegin
Reproducer (for SqlToRelConverterTest)
{code:java}
@Test void testUpdateSubQuery() {
final String sql = "update emp\n"
+ "set empno = (\n"
+ " select cast(empno as BIGINT) from emp" +
")";
sql(sql).ok();
}
{code}
Produces the following assertion error
{noformat}
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)
{noformat}
The same query without casting to BIGINT works fine.
Assertion line
{code:java}
// Should keep sync with rules in SqlTypeCoercionRule.
assert SqlTypeUtil.canCastFrom(toType, fromType, mappingRule);
return true;
{code}
When assertion fails, I see that
toType = INTEGER
fromType = RecordType(BIGINT EXPR$0)
--
This message was sent by Atlassian Jira
(v8.20.10#820010)