Search in sources :

Example 1 with WriteMapping

use of io.trino.plugin.jdbc.WriteMapping in project trino by trinodb.

the class OracleClient method toWriteMapping.

@Override
public WriteMapping toWriteMapping(ConnectorSession session, Type type) {
    if (type instanceof VarcharType) {
        String dataType;
        VarcharType varcharType = (VarcharType) type;
        if (varcharType.isUnbounded() || varcharType.getBoundedLength() > ORACLE_VARCHAR2_MAX_CHARS) {
            dataType = "nclob";
        } else {
            dataType = "varchar2(" + varcharType.getBoundedLength() + " CHAR)";
        }
        return WriteMapping.sliceMapping(dataType, varcharWriteFunction());
    }
    if (type instanceof CharType) {
        String dataType;
        if (((CharType) type).getLength() > ORACLE_CHAR_MAX_CHARS) {
            dataType = "nclob";
        } else {
            dataType = "char(" + ((CharType) type).getLength() + " CHAR)";
        }
        return WriteMapping.sliceMapping(dataType, charWriteFunction());
    }
    if (type instanceof DecimalType) {
        String dataType = format("number(%s, %s)", ((DecimalType) type).getPrecision(), ((DecimalType) type).getScale());
        if (((DecimalType) type).isShort()) {
            return WriteMapping.longMapping(dataType, shortDecimalWriteFunction((DecimalType) type));
        }
        return WriteMapping.objectMapping(dataType, longDecimalWriteFunction((DecimalType) type));
    }
    if (type.equals(TIMESTAMP_SECONDS)) {
        // Oracle date stores year, month, day, hour, minute, seconds, but not second fraction
        return WriteMapping.longMapping("date", trinoTimestampToOracleDateWriteFunction());
    }
    if (type.equals(TIMESTAMP_MILLIS)) {
        return WriteMapping.longMapping("timestamp(3)", trinoTimestampToOracleTimestampWriteFunction());
    }
    WriteMapping writeMapping = WRITE_MAPPINGS.get(type);
    if (writeMapping != null) {
        return writeMapping;
    }
    throw new TrinoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
}
Also used : VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) VarcharType(io.trino.spi.type.VarcharType) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) DecimalType(io.trino.spi.type.DecimalType) TrinoException(io.trino.spi.TrinoException) CharType.createCharType(io.trino.spi.type.CharType.createCharType) CharType(io.trino.spi.type.CharType) WriteMapping(io.trino.plugin.jdbc.WriteMapping)

Aggregations

WriteMapping (io.trino.plugin.jdbc.WriteMapping)1 TrinoException (io.trino.spi.TrinoException)1 CharType (io.trino.spi.type.CharType)1 CharType.createCharType (io.trino.spi.type.CharType.createCharType)1 DecimalType (io.trino.spi.type.DecimalType)1 DecimalType.createDecimalType (io.trino.spi.type.DecimalType.createDecimalType)1 VarcharType (io.trino.spi.type.VarcharType)1 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)1 VarcharType.createVarcharType (io.trino.spi.type.VarcharType.createVarcharType)1