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 b12517ce8460..c1eae8e38b59 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 @@ -46,6 +46,7 @@ import javax.inject.Inject; import java.math.RoundingMode; +import java.security.SecureRandom; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -107,8 +108,10 @@ import static io.trino.spi.type.VarbinaryType.VARBINARY; import static io.trino.spi.type.VarcharType.createUnboundedVarcharType; import static io.trino.spi.type.VarcharType.createVarcharType; +import static java.lang.Character.MAX_RADIX; import static java.lang.Float.floatToRawIntBits; import static java.lang.Float.intBitsToFloat; +import static java.lang.Math.abs; import static java.lang.Math.floorDiv; import static java.lang.Math.floorMod; import static java.lang.Math.max; @@ -124,6 +127,10 @@ public class OracleClient { public static final int ORACLE_MAX_LIST_EXPRESSIONS = 1000; + // Oracle before 12.2 doesn't allow identifiers over 30 characters + private static final int ORACLE_MAX_IDENTIFIER_LENGTH = 30; + private static final SecureRandom RANDOM = new SecureRandom(); + private static final int MAX_BYTES_PER_CHAR = 4; private static final int ORACLE_VARCHAR2_MAX_BYTES = 4000; @@ -213,7 +220,8 @@ public PreparedStatement getPreparedStatement(Connection connection, String sql) @Override protected String generateTemporaryTableName() { - return "tmp_trino_" + System.nanoTime(); + String tableName = "tmp_trino_" + System.nanoTime() + Long.toString(abs(RANDOM.nextLong()), MAX_RADIX); + return tableName.substring(0, min(ORACLE_MAX_IDENTIFIER_LENGTH, tableName.length())); } @Override