diff --git a/plugin/trino-clickhouse/src/main/java/io/trino/plugin/clickhouse/ClickHouseClient.java b/plugin/trino-clickhouse/src/main/java/io/trino/plugin/clickhouse/ClickHouseClient.java index e52104c2e19f..bb3c2328ecea 100644 --- a/plugin/trino-clickhouse/src/main/java/io/trino/plugin/clickhouse/ClickHouseClient.java +++ b/plugin/trino-clickhouse/src/main/java/io/trino/plugin/clickhouse/ClickHouseClient.java @@ -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)); diff --git a/plugin/trino-druid/src/main/java/io/trino/plugin/druid/DruidJdbcClient.java b/plugin/trino-druid/src/main/java/io/trino/plugin/druid/DruidJdbcClient.java index 340e95350307..b9dbe90bab2d 100644 --- a/plugin/trino-druid/src/main/java/io/trino/plugin/druid/DruidJdbcClient.java +++ b/plugin/trino-druid/src/main/java/io/trino/plugin/druid/DruidJdbcClient.java @@ -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"; diff --git a/plugin/trino-mariadb/src/main/java/io/trino/plugin/mariadb/MariaDbClient.java b/plugin/trino-mariadb/src/main/java/io/trino/plugin/mariadb/MariaDbClient.java index 3150f80687d7..d6f352474bac 100644 --- a/plugin/trino-mariadb/src/main/java/io/trino/plugin/mariadb/MariaDbClient.java +++ b/plugin/trino-mariadb/src/main/java/io/trino/plugin/mariadb/MariaDbClient.java @@ -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"; @@ -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)); diff --git a/plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java b/plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java index 0cbe8770b65a..c498ddce2b17 100644 --- a/plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java +++ b/plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java @@ -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)); @@ -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())); } @@ -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)); @@ -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"; diff --git a/plugin/trino-oracle/src/main/java/io/trino/plugin/oracle/OracleClient.java b/plugin/trino-oracle/src/main/java/io/trino/plugin/oracle/OracleClient.java index 53c7103872a4..0dece0000e48 100644 --- a/plugin/trino-oracle/src/main/java/io/trino/plugin/oracle/OracleClient.java +++ b/plugin/trino-oracle/src/main/java/io/trino/plugin/oracle/OracleClient.java @@ -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"; } @@ -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 diff --git a/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClient.java b/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClient.java index 695eaa47be65..becb472c3cb1 100644 --- a/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClient.java +++ b/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClient.java @@ -514,8 +514,7 @@ 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)); @@ -523,11 +522,10 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type) 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"; @@ -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)); diff --git a/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlClient.java b/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlClient.java index 98aa4e9aa188..76f168f02964 100644 --- a/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlClient.java +++ b/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlClient.java @@ -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)); @@ -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"; @@ -699,16 +697,14 @@ 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); @@ -716,8 +712,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type) 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) { @@ -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))); } diff --git a/plugin/trino-redshift/src/main/java/io/trino/plugin/redshift/RedshiftClient.java b/plugin/trino-redshift/src/main/java/io/trino/plugin/redshift/RedshiftClient.java index 28a6983b792b..23eaf592ec2a 100644 --- a/plugin/trino-redshift/src/main/java/io/trino/plugin/redshift/RedshiftClient.java +++ b/plugin/trino-redshift/src/main/java/io/trino/plugin/redshift/RedshiftClient.java @@ -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"; diff --git a/plugin/trino-singlestore/src/main/java/io/trino/plugin/singlestore/SingleStoreClient.java b/plugin/trino-singlestore/src/main/java/io/trino/plugin/singlestore/SingleStoreClient.java index 5002bd268f6a..cf92cd68be6f 100644 --- a/plugin/trino-singlestore/src/main/java/io/trino/plugin/singlestore/SingleStoreClient.java +++ b/plugin/trino-singlestore/src/main/java/io/trino/plugin/singlestore/SingleStoreClient.java @@ -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)); @@ -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"; @@ -422,8 +420,7 @@ 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)); @@ -431,8 +428,7 @@ else if (varcharType.getBoundedLength() <= SINGLESTORE_MEDIUMTEXT_MAX_LENGTH) { 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));