Source:
<code>@Test void testConvertTypeToSpec() { final SqlTypeFactoryImpl factory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT); <START> final RelDataType bigint = factory.createSqlType(SqlTypeName.BIGINT); <END> final RelDataType arraySqlType = new ArraySqlType(factory.createTypeWithNullability(bigint, true), false); final RelDataType multisetSqlType = new MultisetSqlType(factory.createTypeWithNullability(bigint, true), false); List<RelDataTypeField> fields = new ArrayList<>(); RelDataTypeField field0 = new RelDataTypeFieldImpl("f1", 0, bigint); RelDataTypeField field1 = new RelDataTypeFieldImpl("f2", 1, bigint); fields.add(field0); fields.add(field1); final RelDataType recordType = new RelRecordType(fields); SqlBasicTypeNameSpec basicSpec = (SqlBasicTypeNameSpec) convertTypeToSpec(bigint).getTypeNameSpec(); assertThat(basicSpec.getTypeName().getSimple(), is("BIGINT")); SqlCollectionTypeNameSpec arraySpec = (SqlCollectionTypeNameSpec) convertTypeToSpec(arraySqlType).getTypeNameSpec(); assertThat(arraySpec.getTypeName().getSimple(), is("ARRAY")); assertThat(arraySpec.getElementTypeName().getTypeName().getSimple(), is("BIGINT")); SqlCollectionTypeNameSpec multisetSpec = (SqlCollectionTypeNameSpec) convertTypeToSpec(multisetSqlType).getTypeNameSpec(); assertThat(multisetSpec.getTypeName().getSimple(), is("MULTISET")); assertThat(multisetSpec.getElementTypeName().getTypeName().getSimple(), is("BIGINT")); SqlRowTypeNameSpec rowSpec = (SqlRowTypeNameSpec) convertTypeToSpec(recordType).getTypeNameSpec(); List<String> fieldNames = rowSpec.getFieldNames() .stream() .map(SqlIdentifier::getSimple) .collect(Collectors.toList()); List<String> fieldTypeNames = rowSpec.getFieldTypes() .stream() .map(f -> f.getTypeName().getSimple()) .collect(Collectors.toList()); assertThat(rowSpec.getTypeName().getSimple(), is("ROW")); assertThat(fieldNames, is(Lists.newArrayList("f1", "f2"))); assertThat(fieldTypeNames, is(Lists.newArrayList("BIGINT", "BIGINT"))); System.out.println(); }</code><technical_language>Try reuse type defined in f,if is need, create there</technical_language>

Target:
@Test void testConvertTypeToSpec() { SqlBasicTypeNameSpec basicSpec = (SqlBasicTypeNameSpec) convertTypeToSpec(f.sqlBigInt).getTypeNameSpec(); assertThat(basicSpec.getTypeName().getSimple(), is("BIGINT")); SqlCollectionTypeNameSpec arraySpec = (SqlCollectionTypeNameSpec) convertTypeToSpec(f.arrayBigInt).getTypeNameSpec(); assertThat(arraySpec.getTypeName().getSimple(), is("ARRAY")); assertThat(arraySpec.getElementTypeName().getTypeName().getSimple(), is("BIGINT")); SqlCollectionTypeNameSpec multisetSpec = (SqlCollectionTypeNameSpec) convertTypeToSpec(f.multisetBigInt).getTypeNameSpec(); assertThat(multisetSpec.getTypeName().getSimple(), is("MULTISET")); assertThat(multisetSpec.getElementTypeName().getTypeName().getSimple(), is("BIGINT")); SqlRowTypeNameSpec rowSpec = (SqlRowTypeNameSpec) convertTypeToSpec(f.structOfInt).getTypeNameSpec(); List<String> fieldNames = rowSpec.getFieldNames() .stream() .map(SqlIdentifier::getSimple) .collect(Collectors.toList()); List<String> fieldTypeNames = rowSpec.getFieldTypes() .stream() .map(f -> f.getTypeName().getSimple()) .collect(Collectors.toList()); assertThat(rowSpec.getTypeName().getSimple(), is("ROW")); assertThat(fieldNames, is(Arrays.asList("i", "j"))); assertThat(fieldTypeNames, is(Arrays.asList("INTEGER", "INTEGER"))); }