use of io.delta.standalone.types.ArrayType in project presto by prestodb.
the class DeltaTypeUtils method convertDeltaDataTypePrestoDataType.
/**
* Convert given Delta data type to Presto data type signature.
*
* @param tableName Used in error messages when an unsupported data type is encountered.
* @param columnName Used in error messages when an unsupported data type is encountered.
* @param deltaType Data type to convert
* @return
*/
public static TypeSignature convertDeltaDataTypePrestoDataType(SchemaTableName tableName, String columnName, DataType deltaType) {
checkArgument(deltaType != null);
if (deltaType instanceof StructType) {
StructType deltaStructType = (StructType) deltaType;
ImmutableList.Builder<TypeSignatureParameter> typeSignatureBuilder = ImmutableList.builder();
Arrays.stream(deltaStructType.getFields()).forEach(field -> {
String rowFieldName = field.getName().toLowerCase(Locale.US);
TypeSignature rowFieldType = convertDeltaDataTypePrestoDataType(tableName, columnName + "." + field.getName(), field.getDataType());
typeSignatureBuilder.add(TypeSignatureParameter.of(new NamedTypeSignature(Optional.of(new RowFieldName(rowFieldName, false)), rowFieldType)));
});
return new TypeSignature(StandardTypes.ROW, typeSignatureBuilder.build());
} else if (deltaType instanceof ArrayType) {
ArrayType deltaArrayType = (ArrayType) deltaType;
TypeSignature elementType = convertDeltaDataTypePrestoDataType(tableName, columnName, deltaArrayType.getElementType());
return new TypeSignature(ARRAY, ImmutableList.of(TypeSignatureParameter.of(elementType)));
} else if (deltaType instanceof MapType) {
MapType deltaMapType = (MapType) deltaType;
TypeSignature keyType = convertDeltaDataTypePrestoDataType(tableName, columnName, deltaMapType.getKeyType());
TypeSignature valueType = convertDeltaDataTypePrestoDataType(tableName, columnName, deltaMapType.getValueType());
return new TypeSignature(MAP, ImmutableList.of(TypeSignatureParameter.of(keyType), TypeSignatureParameter.of(valueType)));
}
return convertDeltaPrimitiveTypeToPrestoPrimitiveType(tableName, columnName, deltaType).getTypeSignature();
}
Aggregations