in paimon-format/src/main/java/org/apache/paimon/format/parquet/writer/ParquetRowDataWriter.java [79:147]
private FieldWriter createWriter(DataType t, Type type) {
if (type.isPrimitive()) {
switch (t.getTypeRoot()) {
case CHAR:
case VARCHAR:
return new StringWriter(t.isNullable());
case BOOLEAN:
return new BooleanWriter(t.isNullable());
case BINARY:
case VARBINARY:
return new BinaryWriter(t.isNullable());
case DECIMAL:
DecimalType decimalType = (DecimalType) t;
return createDecimalWriter(
decimalType.getPrecision(), decimalType.getScale(), t.isNullable());
case TINYINT:
return new ByteWriter(t.isNullable());
case SMALLINT:
return new ShortWriter(t.isNullable());
case DATE:
case TIME_WITHOUT_TIME_ZONE:
case INTEGER:
return new IntWriter(t.isNullable());
case BIGINT:
return new LongWriter(t.isNullable());
case FLOAT:
return new FloatWriter(t.isNullable());
case DOUBLE:
return new DoubleWriter(t.isNullable());
case TIMESTAMP_WITHOUT_TIME_ZONE:
TimestampType timestampType = (TimestampType) t;
return createTimestampWriter(timestampType.getPrecision(), t.isNullable());
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
LocalZonedTimestampType localZonedTimestampType = (LocalZonedTimestampType) t;
return createTimestampWriter(
localZonedTimestampType.getPrecision(), t.isNullable());
default:
throw new UnsupportedOperationException("Unsupported type: " + type);
}
} else {
GroupType groupType = type.asGroupType();
LogicalTypeAnnotation annotation = type.getLogicalTypeAnnotation();
if (t instanceof ArrayType
&& annotation instanceof LogicalTypeAnnotation.ListLogicalTypeAnnotation) {
return new ArrayWriter(((ArrayType) t).getElementType(), groupType, t.isNullable());
} else if (t instanceof MapType
&& annotation instanceof LogicalTypeAnnotation.MapLogicalTypeAnnotation) {
return new MapWriter(
((MapType) t).getKeyType(),
((MapType) t).getValueType(),
groupType,
t.isNullable());
} else if (t instanceof MultisetType
&& annotation instanceof LogicalTypeAnnotation.MapLogicalTypeAnnotation) {
return new MapWriter(
((MultisetType) t).getElementType(),
new IntType(false),
groupType,
t.isNullable());
} else if (t instanceof RowType && type instanceof GroupType) {
return new RowWriter((RowType) t, groupType, t.isNullable());
} else if (t instanceof VariantType && type instanceof GroupType) {
return new VariantWriter(t.isNullable());
} else {
throw new UnsupportedOperationException("Unsupported type: " + type);
}
}
}