@Test public void convertToArray() { String[] normalFieldNames = new String[] { "id", "name" }; TypeInformation[] normalTypes = new TypeInformation[] {Types.INT(), Types.STRING()}; RowTypeInfo rowTypeInfo = new RowTypeInfo(normalTypes, normalFieldNames); TypeInformation normalAtomicType = Types.OBJECT_ARRAY(Types.STRING()); TypeInformation normalCompositeType = Types.OBJECT_ARRAY(rowTypeInfo); String atomicStrWithBlank = " ARRAY< STRING\n > "; String compositeTypeStrWithBlank = " ARRAY< ROW< id INT, name STRING > > "; TypeInformation atomicArrayTypeWithBlank = DataTypeUtils.convertToArray(atomicStrWithBlank); TypeInformation compositeTypeArrayTypeWithBlank = DataTypeUtils.convertToArray(compositeTypeStrWithBlank); Assert.assertTrue(normalAtomicType.equals(atomicArrayTypeWithBlank)); Assert.assertTrue(normalCompositeType.equals(compositeTypeArrayTypeWithBlank)); String atomicStr = "ARRAY<STRING>"; String compositeTypeStr = "ARRAY<ROW<id INT, name STRING>>"; TypeInformation atomicArrayType = DataTypeUtils.convertToArray(atomicStr); TypeInformation compositeTypeArrayType = DataTypeUtils.convertToArray(compositeTypeStr); Assert.assertTrue(normalAtomicType.equals(atomicArrayType)); Assert.assertTrue(normalCompositeType.equals(compositeTypeArrayType)); }
public static TypeInformation convertToArray(String arrayTypeString) { Matcher matcher = matchCompositeType(arrayTypeString); final String errorMsg = arrayTypeString + "convert to array type error!"; Preconditions.checkState(matcher.find(), errorMsg); String normalizedType = normalizeType(matcher.group(1)); Preconditions.checkState(ARRAY.equals(normalizedType), errorMsg); String elementTypeString = matcher.group(2); TypeInformation elementType; String normalizedElementType = normalizeType(elementTypeString); if (normalizedElementType.startsWith(ROW)) { elementType = convertToRow(elementTypeString); } else { elementType = convertToAtomicType(elementTypeString); } return Types.OBJECT_ARRAY(elementType); }
DataTypeUtils { public static TypeInformation convertToArray(String arrayTypeString) { Matcher matcher = matchCompositeType(arrayTypeString); final String errorMsg = arrayTypeString + "convert to array type error!"; Preconditions.checkState(matcher.find(), errorMsg); String normalizedType = normalizeType(matcher.group(1)); Preconditions.checkState(ARRAY.equals(normalizedType), errorMsg); String elementTypeString = matcher.group(2); TypeInformation elementType; String normalizedElementType = normalizeType(elementTypeString); if (normalizedElementType.startsWith(ROW)) { elementType = convertToRow(elementTypeString); } else { elementType = convertToAtomicType(elementTypeString); } return Types.OBJECT_ARRAY(elementType); } }
DataTypeUtils { public static TypeInformation convertToArray(String arrayTypeString) { Matcher matcher = matchCompositeType(arrayTypeString); final String errorMsg = arrayTypeString + "convert to array type error!"; Preconditions.checkState(matcher.find(), errorMsg); String normalizedType = normalizeType(matcher.group(1)); Preconditions.checkState(ARRAY.equals(normalizedType), errorMsg); String elementTypeString = matcher.group(2); TypeInformation elementType; String normalizedElementType = normalizeType(elementTypeString); if (normalizedElementType.startsWith(ROW)) { elementType = convertToRow(elementTypeString); } else { elementType = convertToAtomicType(elementTypeString); } return Types.OBJECT_ARRAY(elementType); } private  DataTypeUtils(); }
DataTypeUtils { public static TypeInformation convertToArray(String arrayTypeString) { Matcher matcher = matchCompositeType(arrayTypeString); final String errorMsg = arrayTypeString + "convert to array type error!"; Preconditions.checkState(matcher.find(), errorMsg); String normalizedType = normalizeType(matcher.group(1)); Preconditions.checkState(ARRAY.equals(normalizedType), errorMsg); String elementTypeString = matcher.group(2); TypeInformation elementType; String normalizedElementType = normalizeType(elementTypeString); if (normalizedElementType.startsWith(ROW)) { elementType = convertToRow(elementTypeString); } else { elementType = convertToAtomicType(elementTypeString); } return Types.OBJECT_ARRAY(elementType); } private  DataTypeUtils(); static TypeInformation convertToCompositeType(String compositeTypeString); static TypeInformation convertToArray(String arrayTypeString); static RowTypeInfo convertToRow(String rowTypeString); static TypeInformation convertToAtomicType(String string); }
DataTypeUtils { public static TypeInformation convertToArray(String arrayTypeString) { Matcher matcher = matchCompositeType(arrayTypeString); final String errorMsg = arrayTypeString + "convert to array type error!"; Preconditions.checkState(matcher.find(), errorMsg); String normalizedType = normalizeType(matcher.group(1)); Preconditions.checkState(ARRAY.equals(normalizedType), errorMsg); String elementTypeString = matcher.group(2); TypeInformation elementType; String normalizedElementType = normalizeType(elementTypeString); if (normalizedElementType.startsWith(ROW)) { elementType = convertToRow(elementTypeString); } else { elementType = convertToAtomicType(elementTypeString); } return Types.OBJECT_ARRAY(elementType); } private  DataTypeUtils(); static TypeInformation convertToCompositeType(String compositeTypeString); static TypeInformation convertToArray(String arrayTypeString); static RowTypeInfo convertToRow(String rowTypeString); static TypeInformation convertToAtomicType(String string);  }