use of org.apache.flink.api.common.functions.InvalidTypesException in project flink by apache.
the class TypeStringUtils method writeTypeInfo.
public static String writeTypeInfo(TypeInformation<?> typeInfo) {
if (typeInfo.equals(Types.STRING)) {
return VARCHAR;
} else if (typeInfo.equals(Types.BOOLEAN)) {
return BOOLEAN;
} else if (typeInfo.equals(Types.BYTE)) {
return TINYINT;
} else if (typeInfo.equals(Types.SHORT)) {
return SMALLINT;
} else if (typeInfo.equals(Types.INT)) {
return INT;
} else if (typeInfo.equals(Types.LONG)) {
return BIGINT;
} else if (typeInfo.equals(Types.FLOAT)) {
return FLOAT;
} else if (typeInfo.equals(Types.DOUBLE)) {
return DOUBLE;
} else if (typeInfo.equals(Types.BIG_DEC)) {
return DECIMAL;
} else if (typeInfo.equals(Types.SQL_DATE) || typeInfo.equals(Types.LOCAL_DATE)) {
// write LOCAL_DATE as "DATE" to keep compatible when using new types
return DATE;
} else if (typeInfo.equals(Types.SQL_TIME) || typeInfo.equals(Types.LOCAL_TIME)) {
// write LOCAL_TIME as "TIME" to keep compatible when using new types
return TIME;
} else if (typeInfo.equals(Types.SQL_TIMESTAMP) || typeInfo.equals(Types.LOCAL_DATE_TIME)) {
// write LOCAL_DATE_TIME as "TIMESTAMP" to keep compatible when using new types
return TIMESTAMP;
} else if (typeInfo instanceof RowTypeInfo) {
final RowTypeInfo rt = (RowTypeInfo) typeInfo;
final String[] fieldNames = rt.getFieldNames();
final TypeInformation<?>[] fieldTypes = rt.getFieldTypes();
final StringBuilder result = new StringBuilder();
result.append(ROW);
result.append('<');
for (int i = 0; i < fieldNames.length; i++) {
// escape field name if it contains delimiters
if (containsDelimiter(fieldNames[i])) {
result.append('`');
result.append(fieldNames[i].replace("`", "``"));
result.append('`');
} else {
result.append(fieldNames[i]);
}
result.append(' ');
result.append(writeTypeInfo(fieldTypes[i]));
if (i < fieldNames.length - 1) {
result.append(", ");
}
}
result.append('>');
return result.toString();
} else if (typeInfo instanceof GenericTypeInfo) {
return ANY + '<' + typeInfo.getTypeClass().getName() + '>';
} else if (typeInfo instanceof PojoTypeInfo) {
// we only support very simple POJOs that only contain extracted fields
// (not manually specified)
TypeInformation<?> extractedPojo;
try {
extractedPojo = TypeExtractor.createTypeInfo(typeInfo.getTypeClass());
} catch (InvalidTypesException e) {
extractedPojo = null;
}
if (extractedPojo == null || !typeInfo.equals(extractedPojo)) {
throw new TableException("A string representation for custom POJO types is not supported yet.");
}
return POJO + '<' + typeInfo.getTypeClass().getName() + '>';
} else if (typeInfo instanceof PrimitiveArrayTypeInfo) {
final PrimitiveArrayTypeInfo arrayTypeInfo = (PrimitiveArrayTypeInfo) typeInfo;
return PRIMITIVE_ARRAY + '<' + writeTypeInfo(arrayTypeInfo.getComponentType()) + '>';
} else if (typeInfo instanceof ObjectArrayTypeInfo) {
final ObjectArrayTypeInfo arrayTypeInfo = (ObjectArrayTypeInfo) typeInfo;
return OBJECT_ARRAY + '<' + writeTypeInfo(arrayTypeInfo.getComponentInfo()) + '>';
} else if (typeInfo instanceof MultisetTypeInfo) {
final MultisetTypeInfo multisetTypeInfo = (MultisetTypeInfo) typeInfo;
return MULTISET + '<' + writeTypeInfo(multisetTypeInfo.getElementTypeInfo()) + '>';
} else if (typeInfo instanceof MapTypeInfo) {
final MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo;
final String keyTypeInfo = writeTypeInfo(mapTypeInfo.getKeyTypeInfo());
final String valueTypeInfo = writeTypeInfo(mapTypeInfo.getValueTypeInfo());
return MAP + '<' + keyTypeInfo + ", " + valueTypeInfo + '>';
} else {
return ANY + '<' + typeInfo.getTypeClass().getName() + ", " + EncodingUtils.encodeObjectToString(typeInfo) + '>';
}
}
Aggregations