Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.26.0
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
- is related to
-
CALCITE-6091 Char that in array or map is truncated if CASE WHEN statement contains null
- Open
- links to