use of io.trino.spi.type.TimeType in project trino by trinodb.
the class SqlServerClient method toWriteMapping.
@Override
public WriteMapping toWriteMapping(ConnectorSession session, Type type) {
if (type == BOOLEAN) {
return WriteMapping.booleanMapping("bit", booleanWriteFunction());
}
if (type == TINYINT) {
return WriteMapping.longMapping("tinyint", tinyintWriteFunction());
}
if (type == SMALLINT) {
return WriteMapping.longMapping("smallint", smallintWriteFunction());
}
if (type == INTEGER) {
return WriteMapping.longMapping("integer", integerWriteFunction());
}
if (type == BIGINT) {
return WriteMapping.longMapping("bigint", bigintWriteFunction());
}
if (type == REAL) {
return WriteMapping.longMapping("real", realWriteFunction());
}
if (type == DOUBLE) {
return WriteMapping.doubleMapping("double precision", doubleWriteFunction());
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
String dataType = format("decimal(%s, %s)", decimalType.getPrecision(), decimalType.getScale());
if (decimalType.isShort()) {
return WriteMapping.longMapping(dataType, shortDecimalWriteFunction(decimalType));
}
return WriteMapping.objectMapping(dataType, longDecimalWriteFunction(decimalType));
}
if (type instanceof VarcharType) {
VarcharType varcharType = (VarcharType) type;
String dataType;
if (varcharType.isUnbounded() || varcharType.getBoundedLength() > 4000) {
dataType = "nvarchar(max)";
} else {
dataType = "nvarchar(" + varcharType.getBoundedLength() + ")";
}
return WriteMapping.sliceMapping(dataType, varcharWriteFunction());
}
if (type instanceof CharType) {
CharType charType = (CharType) type;
String dataType;
if (charType.getLength() > 4000) {
dataType = "nvarchar(max)";
} else {
dataType = "nchar(" + charType.getLength() + ")";
}
return WriteMapping.sliceMapping(dataType, charWriteFunction());
}
if (type instanceof VarbinaryType) {
return WriteMapping.sliceMapping("varbinary(max)", varbinaryWriteFunction());
}
if (type == DATE) {
return WriteMapping.longMapping("date", sqlServerDateWriteFunction());
}
if (type instanceof TimeType) {
TimeType timeType = (TimeType) type;
int precision = min(timeType.getPrecision(), MAX_SUPPORTED_TEMPORAL_PRECISION);
String dataType = format("time(%d)", precision);
return WriteMapping.longMapping(dataType, sqlServerTimeWriteFunction(precision));
}
if (type instanceof TimestampType) {
TimestampType timestampType = (TimestampType) type;
int precision = min(timestampType.getPrecision(), MAX_SUPPORTED_TEMPORAL_PRECISION);
String dataType = format("datetime2(%d)", precision);
if (timestampType.getPrecision() <= MAX_SHORT_PRECISION) {
return WriteMapping.longMapping(dataType, timestampWriteFunction(timestampType));
}
return WriteMapping.objectMapping(dataType, longTimestampWriteFunction(timestampType, precision));
}
throw new TrinoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
}
Aggregations