in paimon-format/src/main/java/org/apache/paimon/format/parquet/ParquetSchemaConverter.java [65:155]
private static Type convertToParquetType(
String name, DataType type, Type.Repetition repetition) {
switch (type.getTypeRoot()) {
case CHAR:
case VARCHAR:
return Types.primitive(PrimitiveType.PrimitiveTypeName.BINARY, repetition)
.as(OriginalType.UTF8)
.named(name);
case BOOLEAN:
return Types.primitive(PrimitiveType.PrimitiveTypeName.BOOLEAN, repetition)
.named(name);
case BINARY:
case VARBINARY:
return Types.primitive(PrimitiveType.PrimitiveTypeName.BINARY, repetition)
.named(name);
case DECIMAL:
int precision = ((DecimalType) type).getPrecision();
int scale = ((DecimalType) type).getScale();
if (is32BitDecimal(precision)) {
return Types.primitive(INT32, repetition)
.as(LogicalTypeAnnotation.decimalType(scale, precision))
.named(name);
} else if (is64BitDecimal(precision)) {
return Types.primitive(INT64, repetition)
.as(LogicalTypeAnnotation.decimalType(scale, precision))
.named(name);
} else {
return Types.primitive(FIXED_LEN_BYTE_ARRAY, repetition)
.as(LogicalTypeAnnotation.decimalType(scale, precision))
.length(computeMinBytesForDecimalPrecision(precision))
.named(name);
}
case TINYINT:
return Types.primitive(INT32, repetition).as(OriginalType.INT_8).named(name);
case SMALLINT:
return Types.primitive(INT32, repetition).as(OriginalType.INT_16).named(name);
case INTEGER:
return Types.primitive(INT32, repetition).named(name);
case BIGINT:
return Types.primitive(INT64, repetition).named(name);
case FLOAT:
return Types.primitive(PrimitiveType.PrimitiveTypeName.FLOAT, repetition)
.named(name);
case DOUBLE:
return Types.primitive(PrimitiveType.PrimitiveTypeName.DOUBLE, repetition)
.named(name);
case DATE:
return Types.primitive(INT32, repetition).as(OriginalType.DATE).named(name);
case TIME_WITHOUT_TIME_ZONE:
return Types.primitive(INT32, repetition).as(OriginalType.TIME_MILLIS).named(name);
case TIMESTAMP_WITHOUT_TIME_ZONE:
TimestampType timestampType = (TimestampType) type;
return timestampType.getPrecision() <= 6
? Types.primitive(INT64, repetition).named(name)
: Types.primitive(PrimitiveType.PrimitiveTypeName.INT96, repetition)
.named(name);
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
LocalZonedTimestampType localZonedTimestampType = (LocalZonedTimestampType) type;
return localZonedTimestampType.getPrecision() <= 6
? Types.primitive(INT64, repetition).named(name)
: Types.primitive(PrimitiveType.PrimitiveTypeName.INT96, repetition)
.named(name);
case ARRAY:
ArrayType arrayType = (ArrayType) type;
return ConversionPatterns.listOfElements(
repetition,
name,
convertToParquetType(LIST_ELEMENT_NAME, arrayType.getElementType()));
case MAP:
MapType mapType = (MapType) type;
return ConversionPatterns.mapType(
repetition,
name,
MAP_REPEATED_NAME,
convertToParquetType("key", mapType.getKeyType()),
convertToParquetType("value", mapType.getValueType()));
case MULTISET:
MultisetType multisetType = (MultisetType) type;
return ConversionPatterns.mapType(
repetition,
name,
MAP_REPEATED_NAME,
convertToParquetType("key", multisetType.getElementType()),
convertToParquetType("value", new IntType(false)));
case ROW:
RowType rowType = (RowType) type;
return new GroupType(repetition, name, convertToParquetTypes(rowType));
default:
throw new UnsupportedOperationException("Unsupported type: " + type);
}
}