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());
}
Aggregations