private String convert2DorisType()

in inlong-sort/sort-flink/sort-flink-v1.13/sort-connectors/doris/src/main/java/org/apache/inlong/sort/doris/schema/OperationHelper.java [56:161]


    private String convert2DorisType(int jdbcType, boolean isNullable, List<String> precisions) {
        String type = null;
        switch (jdbcType) {
            case Types.BOOLEAN:
            case Types.DATE:
            case Types.FLOAT:
            case Types.DOUBLE:
                type = dynamicSchemaFormat.sqlType2FlinkType(jdbcType).copy(isNullable).asSummaryString();
                break;
            case Types.TINYINT:
            case Types.SMALLINT:
            case Types.INTEGER:
            case Types.BIGINT:
                if (precisions != null && !precisions.isEmpty()) {
                    type = String.format("%s(%s)%s", dynamicSchemaFormat.sqlType2FlinkType(jdbcType).asSummaryString(),
                            StringUtils.join(precisions, ","), isNullable ? "" : " NOT NULL");
                } else {
                    type = dynamicSchemaFormat.sqlType2FlinkType(jdbcType).copy(isNullable).asSummaryString();
                }
                break;
            case Types.DECIMAL:
                DecimalType decimalType = (DecimalType) dynamicSchemaFormat.sqlType2FlinkType(jdbcType);
                if (precisions != null && !precisions.isEmpty()) {
                    Preconditions.checkState(precisions.size() < 3,
                            "The length of precisions with DECIMAL must small than 3");
                    int precision = Integer.parseInt(precisions.get(0));
                    int scale = DEFAULT_DECIMAL_SCALE;
                    if (precisions.size() == 2) {
                        scale = Integer.parseInt(precisions.get(1));
                    }
                    decimalType = new DecimalType(isNullable, precision, scale);
                } else {
                    decimalType = new DecimalType(isNullable, decimalType.getPrecision(), decimalType.getScale());
                }
                type = decimalType.asSummaryString();
                break;
            case Types.CHAR:
                LogicalType charType = dynamicSchemaFormat.sqlType2FlinkType(jdbcType);
                if (precisions != null && !precisions.isEmpty()) {
                    Preconditions.checkState(precisions.size() == 1,
                            "The length of precisions with CHAR must be 1");
                    charType = new CharType(isNullable, Integer.parseInt(precisions.get(0)));
                } else {
                    charType = charType.copy(isNullable);
                }
                type = charType.asSerializableString();
                break;
            case Types.VARCHAR:
                LogicalType varcharType = dynamicSchemaFormat.sqlType2FlinkType(jdbcType);
                if (precisions != null && !precisions.isEmpty()) {
                    Preconditions.checkState(precisions.size() == 1,
                            "The length of precisions with VARCHAR must be 1");
                    // Because the precision definition of varchar by Doris is different from that of MySQL.
                    // The precision in MySQL is the number of characters, while Doris is the number of bytes,
                    // and Chinese characters occupy 3 bytes, so the precision multiplys by 3 here.
                    int precision = Math.min(Integer.parseInt(precisions.get(0)) * 3, VARCHAR_MAX_LENGTH);
                    varcharType = new VarCharType(isNullable, precision);
                } else {
                    varcharType = varcharType.copy(isNullable);
                }
                type = varcharType.asSerializableString();
                break;
            // The following types are not directly supported in doris,
            // and can only be converted to compatible types as much as possible
            case Types.TIME:
            case Types.TIME_WITH_TIMEZONE:
            case Types.BINARY:
            case Types.VARBINARY:
            case Types.BLOB:
            case Types.CLOB:
            case Types.LONGNVARCHAR:
            case Types.LONGVARBINARY:
            case Types.LONGVARCHAR:
            case Types.ARRAY:
            case Types.NCHAR:
            case Types.NCLOB:
            case Types.OTHER:
                type = String.format("STRING%s", isNullable ? "" : " NOT NULL");
                break;
            case Types.TIMESTAMP_WITH_TIMEZONE:
            case Types.TIMESTAMP:
                type = "DATETIME";
                break;
            case Types.REAL:
            case Types.NUMERIC:
                int precision = DEFAULT_DECIMAL_PRECISION;
                int scale = DEFAULT_DECIMAL_SCALE;
                if (precisions != null && !precisions.isEmpty()) {
                    Preconditions.checkState(precisions.size() < 3,
                            "The length of precisions with NUMERIC must small than 3");
                    precision = Integer.parseInt(precisions.get(0));
                    if (precisions.size() == 2) {
                        scale = Integer.parseInt(precisions.get(1));
                    }
                }
                decimalType = new DecimalType(isNullable, precision, scale);
                type = decimalType.asSerializableString();
                break;
            case Types.BIT:
                type = String.format("BOOLEAN %s", isNullable ? "" : " NOT NULL");
                break;
            default:
                type = String.format("STRING%s", isNullable ? "" : " NOT NULL");
        }
        return type;
    }