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 493f5352dd6c..ce46726083cf 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 @@ -140,6 +140,7 @@ import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.String.format; +import static java.util.Locale.ENGLISH; import static java.util.stream.Collectors.joining; public class MySqlClient @@ -283,13 +284,18 @@ public Optional toColumnMapping(ConnectorSession session, Connect if (mapping.isPresent()) { return mapping; } - Optional unsignedMapping = getUnsignedMapping(typeHandle); - if (unsignedMapping.isPresent()) { - return unsignedMapping; - } - if (jdbcTypeName.equalsIgnoreCase("json")) { - return Optional.of(jsonColumnMapping()); + switch (jdbcTypeName.toLowerCase(ENGLISH)) { + case "tinyint unsigned": + return Optional.of(smallintColumnMapping()); + case "smallint unsigned": + return Optional.of(integerColumnMapping()); + case "int unsigned": + return Optional.of(bigintColumnMapping()); + case "bigint unsigned": + return Optional.of(decimalColumnMapping(createDecimalType(20))); + case "json": + return Optional.of(jsonColumnMapping()); } switch (typeHandle.getJdbcType()) { @@ -663,27 +669,4 @@ private static boolean isGtidMode(Connection connection) throw new TrinoException(JDBC_ERROR, e); } } - - private static Optional getUnsignedMapping(JdbcTypeHandle typeHandle) - { - if (typeHandle.getJdbcTypeName().isEmpty()) { - return Optional.empty(); - } - - String typeName = typeHandle.getJdbcTypeName().get(); - if (typeName.equalsIgnoreCase("tinyint unsigned")) { - return Optional.of(smallintColumnMapping()); - } - if (typeName.equalsIgnoreCase("smallint unsigned")) { - return Optional.of(integerColumnMapping()); - } - if (typeName.equalsIgnoreCase("int unsigned")) { - return Optional.of(bigintColumnMapping()); - } - if (typeName.equalsIgnoreCase("bigint unsigned")) { - return Optional.of(decimalColumnMapping(createDecimalType(20))); - } - - return Optional.empty(); - } }