public static DataType toPaimonType()

in paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoTypeUtils.java [167:233]


    public static DataType toPaimonType(Type prestoType) {
        if (prestoType instanceof com.facebook.presto.common.type.CharType) {
            return DataTypes.CHAR(
                    ((com.facebook.presto.common.type.CharType) prestoType).getLength());
        } else if (prestoType instanceof VarcharType) {
            return DataTypes.VARCHAR(
                    Math.min(Integer.MAX_VALUE, ((VarcharType) prestoType).getLength()));
        } else if (prestoType instanceof com.facebook.presto.common.type.BooleanType) {
            return DataTypes.BOOLEAN();
        } else if (prestoType instanceof VarbinaryType) {
            // The varbinary in Presto currently does not accept the maximum length parameter, it is
            // unbounded
            return DataTypes.VARBINARY(Integer.MAX_VALUE);
        } else if (prestoType instanceof com.facebook.presto.common.type.DecimalType) {
            return DataTypes.DECIMAL(
                    ((com.facebook.presto.common.type.DecimalType) prestoType).getPrecision(),
                    ((com.facebook.presto.common.type.DecimalType) prestoType).getScale());
        } else if (prestoType instanceof TinyintType) {
            return DataTypes.TINYINT();
        } else if (prestoType instanceof SmallintType) {
            return DataTypes.SMALLINT();
        } else if (prestoType instanceof IntegerType) {
            return DataTypes.INT();
        } else if (prestoType instanceof BigintType) {
            return DataTypes.BIGINT();
        } else if (prestoType instanceof RealType) {
            return DataTypes.FLOAT();
        } else if (prestoType instanceof com.facebook.presto.common.type.DoubleType) {
            return DataTypes.DOUBLE();
        } else if (prestoType instanceof com.facebook.presto.common.type.DateType) {
            return DataTypes.DATE();
        } else if (prestoType instanceof com.facebook.presto.common.type.TimeType) {
            return new TimeType();
        } else if (prestoType instanceof com.facebook.presto.common.type.TimestampType) {
            return DataTypes.TIMESTAMP();
        } else if (prestoType instanceof TimestampWithTimeZoneType) {
            return DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE();
        } else if (prestoType instanceof com.facebook.presto.common.type.ArrayType) {
            return DataTypes.ARRAY(
                    toPaimonType(
                            ((com.facebook.presto.common.type.ArrayType) prestoType)
                                    .getElementType()));
        } else if (prestoType instanceof com.facebook.presto.common.type.MapType) {
            return DataTypes.MAP(
                    toPaimonType(
                            ((com.facebook.presto.common.type.MapType) prestoType).getKeyType()),
                    toPaimonType(
                            ((com.facebook.presto.common.type.MapType) prestoType).getValueType()));
        } else if (prestoType instanceof com.facebook.presto.common.type.RowType) {
            com.facebook.presto.common.type.RowType rowType =
                    (com.facebook.presto.common.type.RowType) prestoType;
            AtomicInteger id = new AtomicInteger(0);
            List<DataField> dataFields =
                    rowType.getFields().stream()
                            .map(
                                    field ->
                                            new DataField(
                                                    id.getAndIncrement(),
                                                    field.getName().get(),
                                                    toPaimonType(field.getType())))
                            .collect(Collectors.toList());
            return new RowType(true, dataFields);
        } else {
            throw new UnsupportedOperationException(
                    format("Cannot convert from Presto type '%s' to Paimon type", prestoType));
        }
    }