You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Ruben Q L (Jira)" <ji...@apache.org> on 2021/05/17 18:43:00 UTC

[jira] [Resolved] (CALCITE-4603) Least restrictive type considers only the last element in collections of collections

     [ https://issues.apache.org/jira/browse/CALCITE-4603?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ruben Q L resolved CALCITE-4603.
--------------------------------
    Resolution: Fixed

> Least restrictive type considers only the last element in collections of collections
> ------------------------------------------------------------------------------------
>
>                 Key: CALCITE-4603
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4603
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.26.0
>            Reporter: Sergey Nuyanzin
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.27.0
>
>          Time Spent: 3.5h
>  Remaining Estimate: 0h
>
> It seems least restrictive always returns the type of the last element from the collection.
>  For instance for
> {code:sql}
>  select array[array['hello'], array['world'], array['!']] as "array"
> {code}
> least restrictive gives {{CHAR(1) ARRAY ARRAY}} instead of {{CHAR(5) ARRAY ARRAY}}
>  for
> {code:sql}
> select map[map[1.1, 2.1], map[1.1, 2.1], map[1, 1], map[1, 1]] as "map";
> {code}
> least restrictive gives {{((INTEGER, INTEGER) MAP, (INTEGER, INTEGER) MAP) MAP}} instead of {{((DECIMAL(2, 1), DECIMAL(2, 1)) MAP, (DECIMAL(2, 1), DECIMAL(2, 1)) MAP) MAP}}
>  for
> {code:sql}
> select multiset[array['hello'], array['world'], array['!']] as "multiset";
> {code}
> least restrictive gives {{CHAR(1) ARRAY MULTISET}} instead of {{CHAR(5) ARRAY MULTISET}}
> {{+ a test to reproduce}}
> {code:java}
>  @Test
>   void testCALCITE4603() {
>     SqlTypeFixture f = new SqlTypeFixture();
>     SqlTypeFactoryImpl typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
>     int maxPrecision = 10;
>     int minPrecision = 1;
>     RelDataType leastRestrictive =
>         f.typeFactory.leastRestrictive(
>             Lists.newArrayList(typeFactory.createTypeWithNullability(
>                 typeFactory.createArrayType(typeFactory.createTypeWithNullability(
>                     typeFactory.createSqlType(SqlTypeName.CHAR, maxPrecision), false), -1), false),
>                 typeFactory.createTypeWithNullability(
>                     typeFactory.createArrayType(typeFactory.createTypeWithNullability(
>                         typeFactory.createSqlType(SqlTypeName.CHAR, minPrecision), false), -1), false)));
>     assertThat(leastRestrictive.getSqlTypeName(), is(SqlTypeName.ARRAY));
>     assertThat(leastRestrictive.getComponentType().getPrecision(), is(maxPrecision));
>   }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)