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

Least restrictive type considers only the last element in collections of collections

    XMLWordPrintableJSON

Details

    Description

      It seems least restrictive always returns the type of the last element from the collection.
      For instance for

       select array[array['hello'], array['world'], array['!']] as "array"
      

      least restrictive gives CHAR(1) ARRAY ARRAY instead of CHAR(5) ARRAY ARRAY
      for

      select map[map[1.1, 2.1], map[1.1, 2.1], map[1, 1], map[1, 1]] as "map";
      

      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

      select multiset[array['hello'], array['world'], array['!']] as "multiset";
      

      least restrictive gives CHAR(1) ARRAY MULTISET instead of CHAR(5) ARRAY MULTISET

      + a test to reproduce

       @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));
        }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Sergey Nuyanzin Sergey Nuyanzin
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 3.5h
                  3.5h