Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
if (type == DOUBLE) {
return WriteMapping.doubleMapping("Float64", doubleWriteFunction());
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
if (type instanceof DecimalType decimalType) {
String dataType = format("Decimal(%s, %s)", decimalType.getPrecision(), decimalType.getScale());
if (decimalType.isShort()) {
return WriteMapping.longMapping(dataType, shortDecimalWriteFunction(decimalType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,19 +546,17 @@ private WriteMapping legacyToWriteMapping(Type type)
if (type == DOUBLE) {
return WriteMapping.doubleMapping("double precision", doubleWriteFunction());
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
if (type instanceof DecimalType decimalType) {
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 CharType) {
return WriteMapping.sliceMapping("char(" + ((CharType) type).getLength() + ")", charWriteFunction());
if (type instanceof CharType charType) {
return WriteMapping.sliceMapping("char(" + charType.getLength() + ")", charWriteFunction());
}
if (type instanceof VarcharType) {
VarcharType varcharType = (VarcharType) type;
if (type instanceof VarcharType varcharType) {
String dataType;
if (varcharType.isUnbounded()) {
dataType = "varchar";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,19 +390,17 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
if (type == DOUBLE) {
return WriteMapping.doubleMapping("double precision", doubleWriteFunction());
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
if (type instanceof DecimalType decimalType) {
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 CharType) {
return WriteMapping.sliceMapping("char(" + ((CharType) type).getLength() + ")", charWriteFunction());
if (type instanceof CharType charType) {
return WriteMapping.sliceMapping("char(" + charType.getLength() + ")", charWriteFunction());
}
if (type instanceof VarcharType) {
VarcharType varcharType = (VarcharType) type;
if (type instanceof VarcharType varcharType) {
String dataType;
if (varcharType.isUnbounded()) {
dataType = "longtext";
Expand All @@ -427,15 +425,13 @@ else if (varcharType.getBoundedLength() <= 16777215) {
if (type == DATE) {
return WriteMapping.longMapping("date", dateWriteFunction());
}
if (type instanceof TimeType) {
TimeType timeType = (TimeType) type;
if (type instanceof TimeType timeType) {
if (timeType.getPrecision() <= MAX_SUPPORTED_DATE_TIME_PRECISION) {
return WriteMapping.longMapping(format("time(%s)", timeType.getPrecision()), timeWriteFunction(timeType.getPrecision()));
}
return WriteMapping.longMapping(format("time(%s)", MAX_SUPPORTED_DATE_TIME_PRECISION), timeWriteFunction(MAX_SUPPORTED_DATE_TIME_PRECISION));
}
if (type instanceof TimestampType) {
TimestampType timestampType = (TimestampType) type;
if (type instanceof TimestampType timestampType) {
if (timestampType.getPrecision() <= MAX_SUPPORTED_DATE_TIME_PRECISION) {
verify(timestampType.getPrecision() <= TimestampType.MAX_SHORT_PRECISION);
return WriteMapping.longMapping(format("timestamp(%s)", timestampType.getPrecision()), timestampWriteFunction(timestampType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
return WriteMapping.doubleMapping("double precision", doubleWriteFunction());
}

if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
if (type instanceof DecimalType decimalType) {
String dataType = format("decimal(%s, %s)", decimalType.getPrecision(), decimalType.getScale());
if (decimalType.isShort()) {
return WriteMapping.longMapping(dataType, shortDecimalWriteFunction(decimalType));
Expand All @@ -516,8 +515,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
return WriteMapping.longMapping("date", dateWriteFunctionUsingLocalDate());
}

if (type instanceof TimeType) {
TimeType timeType = (TimeType) type;
if (type instanceof TimeType timeType) {
if (timeType.getPrecision() <= MAX_SUPPORTED_DATE_TIME_PRECISION) {
return WriteMapping.longMapping(format("time(%s)", timeType.getPrecision()), timeWriteFunction(timeType.getPrecision()));
}
Expand All @@ -528,8 +526,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
throw new TrinoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
}

if (type instanceof TimestampType) {
TimestampType timestampType = (TimestampType) type;
if (type instanceof TimestampType timestampType) {
if (timestampType.getPrecision() <= MAX_SUPPORTED_DATE_TIME_PRECISION) {
verify(timestampType.getPrecision() <= TimestampType.MAX_SHORT_PRECISION);
return WriteMapping.longMapping(format("datetime(%s)", timestampType.getPrecision()), timestampWriteFunction(timestampType));
Expand All @@ -541,12 +538,11 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
return WriteMapping.sliceMapping("mediumblob", varbinaryWriteFunction());
}

if (type instanceof CharType) {
return WriteMapping.sliceMapping("char(" + ((CharType) type).getLength() + ")", charWriteFunction());
if (type instanceof CharType charType) {
return WriteMapping.sliceMapping("char(" + charType.getLength() + ")", charWriteFunction());
}

if (type instanceof VarcharType) {
VarcharType varcharType = (VarcharType) type;
if (type instanceof VarcharType varcharType) {
String dataType;
if (varcharType.isUnbounded()) {
dataType = "longtext";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,8 @@ private SliceWriteFunction oracleCharWriteFunction()
@Override
public WriteMapping toWriteMapping(ConnectorSession session, Type type)
{
if (type instanceof VarcharType) {
if (type instanceof VarcharType varcharType) {
String dataType;
VarcharType varcharType = (VarcharType) type;
if (varcharType.isUnbounded() || varcharType.getBoundedLength() > ORACLE_VARCHAR2_MAX_CHARS) {
dataType = "nclob";
}
Expand All @@ -640,22 +639,22 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
}
return WriteMapping.sliceMapping(dataType, varcharWriteFunction());
}
if (type instanceof CharType) {
if (type instanceof CharType charType) {
String dataType;
if (((CharType) type).getLength() > ORACLE_CHAR_MAX_CHARS) {
if (charType.getLength() > ORACLE_CHAR_MAX_CHARS) {
dataType = "nclob";
}
else {
dataType = "char(" + ((CharType) type).getLength() + " CHAR)";
dataType = "char(" + charType.getLength() + " CHAR)";
}
return WriteMapping.sliceMapping(dataType, oracleCharWriteFunction());
}
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));
if (type instanceof DecimalType decimalType) {
String dataType = format("number(%s, %s)", decimalType.getPrecision(), decimalType.getScale());
if (decimalType.isShort()) {
return WriteMapping.longMapping(dataType, shortDecimalWriteFunction(decimalType));
}
return WriteMapping.objectMapping(dataType, longDecimalWriteFunction((DecimalType) type));
return WriteMapping.objectMapping(dataType, longDecimalWriteFunction(decimalType));
}
if (type.equals(TIMESTAMP_SECONDS)) {
// Specify 'date' instead of 'timestamp(0)' to propagate the type in case of CTAS from date columns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,20 +514,18 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
return WriteMapping.doubleMapping("double", doubleWriteFunction());
}

if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
if (type instanceof DecimalType decimalType) {
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 CharType) {
return WriteMapping.sliceMapping("char(" + ((CharType) type).getLength() + ")", charWriteFunction());
if (type instanceof CharType charType) {
return WriteMapping.sliceMapping("char(" + charType.getLength() + ")", charWriteFunction());
}
if (type instanceof VarcharType) {
VarcharType varcharType = (VarcharType) type;
if (type instanceof VarcharType varcharType) {
String dataType;
if (varcharType.isUnbounded()) {
dataType = "varchar";
Expand All @@ -551,8 +549,8 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
if (TIME_WITH_TIME_ZONE.equals(type) || TIMESTAMP_TZ_MILLIS.equals(type)) {
throw new TrinoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
}
if (type instanceof ArrayType) {
Type elementType = ((ArrayType) type).getElementType();
if (type instanceof ArrayType arrayType) {
Type elementType = arrayType.getElementType();
String elementDataType = toWriteMapping(session, elementType).getDataType().toUpperCase(ENGLISH);
String elementWriteName = getArrayElementPhoenixTypeName(session, this, elementType);
return WriteMapping.objectMapping(elementDataType + " ARRAY", arrayWriteFunction(session, elementType, elementWriteName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
return WriteMapping.doubleMapping("double precision", doubleWriteFunction());
}

if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
if (type instanceof DecimalType decimalType) {
String dataType = format("decimal(%s, %s)", decimalType.getPrecision(), decimalType.getScale());
if (decimalType.isShort()) {
return WriteMapping.longMapping(dataType, shortDecimalWriteFunction(decimalType));
Expand All @@ -680,8 +679,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
return WriteMapping.sliceMapping("char(" + ((CharType) type).getLength() + ")", charWriteFunction());
}

if (type instanceof VarcharType) {
VarcharType varcharType = (VarcharType) type;
if (type instanceof VarcharType varcharType) {
String dataType;
if (varcharType.isUnbounded()) {
dataType = "varchar";
Expand All @@ -699,25 +697,22 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
return WriteMapping.longMapping("date", dateWriteFunctionUsingLocalDate());
}

if (type instanceof TimeType) {
TimeType timeType = (TimeType) type;
if (type instanceof TimeType timeType) {
if (timeType.getPrecision() <= POSTGRESQL_MAX_SUPPORTED_TIMESTAMP_PRECISION) {
return WriteMapping.longMapping(format("time(%s)", timeType.getPrecision()), timeWriteFunction(timeType.getPrecision()));
}
return WriteMapping.longMapping(format("time(%s)", POSTGRESQL_MAX_SUPPORTED_TIMESTAMP_PRECISION), timeWriteFunction(POSTGRESQL_MAX_SUPPORTED_TIMESTAMP_PRECISION));
}

if (type instanceof TimestampType) {
TimestampType timestampType = (TimestampType) type;
if (type instanceof TimestampType timestampType) {
if (timestampType.getPrecision() <= POSTGRESQL_MAX_SUPPORTED_TIMESTAMP_PRECISION) {
verify(timestampType.getPrecision() <= TimestampType.MAX_SHORT_PRECISION);
return WriteMapping.longMapping(format("timestamp(%s)", timestampType.getPrecision()), PostgreSqlClient::shortTimestampWriteFunction);
}
verify(timestampType.getPrecision() > TimestampType.MAX_SHORT_PRECISION);
return WriteMapping.objectMapping(format("timestamp(%s)", POSTGRESQL_MAX_SUPPORTED_TIMESTAMP_PRECISION), longTimestampWriteFunction());
}
if (type instanceof TimestampWithTimeZoneType) {
TimestampWithTimeZoneType timestampWithTimeZoneType = (TimestampWithTimeZoneType) type;
if (type instanceof TimestampWithTimeZoneType timestampWithTimeZoneType) {
if (timestampWithTimeZoneType.getPrecision() <= POSTGRESQL_MAX_SUPPORTED_TIMESTAMP_PRECISION) {
String dataType = format("timestamptz(%d)", timestampWithTimeZoneType.getPrecision());
if (timestampWithTimeZoneType.getPrecision() <= TimestampWithTimeZoneType.MAX_SHORT_PRECISION) {
Expand All @@ -733,8 +728,8 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
if (type.equals(uuidType)) {
return WriteMapping.sliceMapping("uuid", uuidWriteFunction());
}
if (type instanceof ArrayType && getArrayMapping(session) == AS_ARRAY) {
Type elementType = ((ArrayType) type).getElementType();
if (type instanceof ArrayType arrayType && getArrayMapping(session) == AS_ARRAY) {
Type elementType = arrayType.getElementType();
String elementDataType = toWriteMapping(session, elementType).getDataType();
return WriteMapping.objectMapping(elementDataType + "[]", arrayWriteFunction(session, elementType, getArrayElementPgTypeName(session, this, elementType)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,19 +279,17 @@ private WriteMapping legacyToWriteMapping(Type type)
if (type == DOUBLE) {
return WriteMapping.doubleMapping("double precision", doubleWriteFunction());
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
if (type instanceof DecimalType decimalType) {
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 CharType) {
return WriteMapping.sliceMapping("char(" + ((CharType) type).getLength() + ")", charWriteFunction());
if (type instanceof CharType charType) {
return WriteMapping.sliceMapping("char(" + charType.getLength() + ")", charWriteFunction());
}
if (type instanceof VarcharType) {
VarcharType varcharType = (VarcharType) type;
if (type instanceof VarcharType varcharType) {
String dataType;
if (varcharType.isUnbounded()) {
dataType = "varchar";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
if (type == BIGINT) {
return WriteMapping.longMapping("bigint", bigintWriteFunction());
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
if (type instanceof DecimalType decimalType) {
String dataType = format("decimal(%s, %s)", decimalType.getPrecision(), decimalType.getScale());
if (decimalType.isShort()) {
return WriteMapping.longMapping(dataType, shortDecimalWriteFunction(decimalType));
Expand All @@ -393,11 +392,10 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
if (type == DOUBLE) {
return WriteMapping.doubleMapping("double precision", doubleWriteFunction());
}
if (type instanceof CharType) {
return WriteMapping.sliceMapping("char(" + ((CharType) type).getLength() + ")", charWriteFunction());
if (type instanceof CharType charType) {
return WriteMapping.sliceMapping("char(" + charType.getLength() + ")", charWriteFunction());
}
if (type instanceof VarcharType) {
VarcharType varcharType = (VarcharType) type;
if (type instanceof VarcharType varcharType) {
String dataType;
if (varcharType.isUnbounded()) {
dataType = "longtext";
Expand All @@ -422,17 +420,15 @@ else if (varcharType.getBoundedLength() <= SINGLESTORE_MEDIUMTEXT_MAX_LENGTH) {
if (type == DATE) {
return WriteMapping.longMapping("date", dateWriteFunction());
}
if (type instanceof TimeType) {
TimeType timeType = (TimeType) type;
if (type instanceof TimeType timeType) {
checkArgument(timeType.getPrecision() <= SINGLESTORE_DATE_TIME_MAX_PRECISION, "The max time precision in SingleStore is 6");
if (timeType.getPrecision() == 0) {
return WriteMapping.longMapping("time", timeWriteFunction(0));
}
return WriteMapping.longMapping("time(6)", timeWriteFunction(6));
}
// TODO implement TIME type
if (type instanceof TimestampType) {
TimestampType timestampType = (TimestampType) type;
if (type instanceof TimestampType timestampType) {
checkArgument(timestampType.getPrecision() <= SINGLESTORE_DATE_TIME_MAX_PRECISION, "The max timestamp precision in SingleStore is 6");
if (timestampType.getPrecision() == 0) {
return WriteMapping.longMapping("datetime", timestampWriteFunction(timestampType));
Expand Down