Vladimir Steshin created IGNITE-25765:
-----------------------------------------

             Summary: Calcite. Insufficient description of collection type.
                 Key: IGNITE-25765
                 URL: https://issues.apache.org/jira/browse/IGNITE-25765
             Project: Ignite
          Issue Type: Bug
            Reporter: Vladimir Steshin


We convert collection types to internal types and backward. This convertation 
looses collection element types. As instance, `{_}INTEGER ARRAY`{_} in 
converted to `{_}java.lang.List{_}` and is restored as `{_}ANY ARRAY{_}`. This 
can issue a type coercion failure.

 

*Consider:*
{code:java}
public class StdSqlOperatorsTest extends AbstractBasicIntegrationTest {
 @Override protected void beforeTest() throws Exception {
    super.beforeTest();

    sql("CREATE TABLE t(val INT, arrn INTEGER ARRAY, arrnn INTEGER ARRAY NOT 
NULL, arrn2 INTEGER ARRAY)");

    // FAILS!
    sql("INSERT INTO t VALUES (1, null, ARRAY[1,2,3], ARRAY[10,11,12]), (2, 
ARRAY[4,5,6], ARRAY[7,8,9], null)");
  }

   /** FAILS! */
   @Test
   public void test0() {
       assertQuery("SELECT ARRAY_CONCAT_AGG(a) from (select arrn from t union 
all select NULL) T(a)")
           .returns(F.asList(1,2,3,4,5,6))
           .check();
   }
} {code}
 

*The errors* are similar:
{code:java}
Caused by: java.lang.UnsupportedOperationException: Unsupported type when 
convertTypeToSpec: ANY        at 
org.apache.calcite.sql.type.SqlTypeUtil.convertTypeToSpec(SqlTypeUtil.java:1174)
     at 
org.apache.calcite.sql.type.SqlTypeUtil.convertTypeToSpec(SqlTypeUtil.java:1196)
     at 
org.apache.calcite.sql.type.SqlTypeUtil.convertTypeToSpec(SqlTypeUtil.java:1153)
     at 
org.apache.calcite.sql.type.SqlTypeUtil.convertTypeToSpec(SqlTypeUtil.java:1196)
     at 
org.apache.ignite.internal.processors.query.calcite.prepare.IgniteTypeCoercion.castTo(IgniteTypeCoercion.java:283)
   at 
org.apache.ignite.internal.processors.query.calcite.prepare.IgniteTypeCoercion.coerceColumnType(IgniteTypeCoercion.java:250)
 at 
org.apache.calcite.sql.validate.implicit.TypeCoercionImpl.rowTypeCoercion(TypeCoercionImpl.java:101)
 at 
org.apache.calcite.sql.type.SetopOperandTypeChecker.checkOperandTypes(SetopOperandTypeChecker.java:121)
      at 
org.apache.calcite.sql.SqlOperator.checkOperandTypes(SqlOperator.java:784)   at 
org.apache.calcite.sql.SqlOperator.validateOperands(SqlOperator.java:526)    at 
org.apache.calcite.sql.SqlOperator.deriveType(SqlOperator.java:630)  at 
org.apache.calcite.sql.SqlBinaryOperator.deriveType(SqlBinaryOperator.java:180) 
     at 
org.apache.calcite.sql.validate.SetopNamespace.validateImpl(SetopNamespace.java:115)
 at 
org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:96)
        at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:1208)
       at 
org.apache.ignite.internal.processors.query.calcite.prepare.IgniteSqlValidator.validateNamespace(IgniteSqlValidator.java:256)
        at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:1179)
   at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:3628)
    at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:3607)
    at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:4121)
  at 
org.apache.ignite.internal.processors.query.calcite.prepare.IgniteSqlValidator.validateSelect(IgniteSqlValidator.java:242)
 {code}
`{_}INTEGER`{_} component type of the array is missing, is restored as 
`{_}ANY`{_}. Calcite cannot create a type spec.

 

*Suggestion:*

We might keep collection element types like `{_}java.jang.List:int`{_} and 
transfer them, for example, as `{_}List<Class<?>>`{_}, not as `{_}Class<?>`{_}. 
Then we just need to reassign element/component type for a collection type.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to