diff --git a/client/trino-jdbc/src/test/java/io/trino/jdbc/TestJdbcPreparedStatement.java b/client/trino-jdbc/src/test/java/io/trino/jdbc/TestJdbcPreparedStatement.java index cb5a308dae5e..c889011d54d9 100644 --- a/client/trino-jdbc/src/test/java/io/trino/jdbc/TestJdbcPreparedStatement.java +++ b/client/trino-jdbc/src/test/java/io/trino/jdbc/TestJdbcPreparedStatement.java @@ -62,6 +62,7 @@ import static io.trino.jdbc.BaseTestJdbcResultSet.toSqlTime; import static io.trino.jdbc.TestingJdbcUtils.list; import static io.trino.jdbc.TestingJdbcUtils.readRows; +import static io.trino.testing.TestingNames.randomNameSuffix; import static java.lang.String.format; import static java.nio.charset.StandardCharsets.UTF_8; import static java.sql.ParameterMetaData.parameterModeUnknown; @@ -160,9 +161,10 @@ public void testGetMetadata() private void testGetMetadata(boolean explicitPrepare) throws Exception { + String tableName = "test_get_metadata_" + randomNameSuffix(); try (Connection connection = createConnection("blackhole", "blackhole", explicitPrepare)) { try (Statement statement = connection.createStatement()) { - statement.execute("CREATE TABLE test_get_metadata (" + + statement.execute("CREATE TABLE " + tableName + " (" + "c_boolean boolean, " + "c_decimal decimal, " + "c_decimal_2 decimal(10,3)," + @@ -174,13 +176,13 @@ private void testGetMetadata(boolean explicitPrepare) } try (PreparedStatement statement = connection.prepareStatement( - "SELECT * FROM test_get_metadata")) { + "SELECT * FROM " + tableName)) { ResultSetMetaData metadata = statement.getMetaData(); assertEquals(metadata.getColumnCount(), 8); for (int i = 1; i <= metadata.getColumnCount(); i++) { assertEquals(metadata.getCatalogName(i), "blackhole"); assertEquals(metadata.getSchemaName(i), "blackhole"); - assertEquals(metadata.getTableName(i), "test_get_metadata"); + assertEquals(metadata.getTableName(i), tableName); } assertEquals(metadata.getColumnName(1), "c_boolean"); @@ -209,7 +211,7 @@ private void testGetMetadata(boolean explicitPrepare) } try (Statement statement = connection.createStatement()) { - statement.execute("DROP TABLE test_get_metadata"); + statement.execute("DROP TABLE " + tableName); } } } @@ -225,9 +227,10 @@ public void testGetParameterMetaData() private void testGetParameterMetaData(boolean explicitPrepare) throws Exception { + String tableName = "test_get_parameterMetaData_" + randomNameSuffix(); try (Connection connection = createConnection("blackhole", "blackhole", explicitPrepare)) { try (Statement statement = connection.createStatement()) { - statement.execute("CREATE TABLE test_get_parameterMetaData (" + + statement.execute("CREATE TABLE " + tableName + " (" + "c_boolean boolean, " + "c_decimal decimal, " + "c_decimal_2 decimal(10,3)," + @@ -245,7 +248,7 @@ private void testGetParameterMetaData(boolean explicitPrepare) } try (PreparedStatement statement = connection.prepareStatement( - "SELECT ? FROM test_get_parameterMetaData WHERE c_boolean = ? AND c_decimal = ? " + + "SELECT ? FROM " + tableName + " WHERE c_boolean = ? AND c_decimal = ? " + "AND c_decimal_2 = ? AND c_varchar = ? AND c_varchar_2 = ? AND c_row = ? " + "AND c_array = ? AND c_map = ? AND c_tinyint = ? AND c_integer = ? AND c_bigint = ? " + "AND c_smallint = ? AND c_real = ? AND c_double = ?")) { @@ -362,7 +365,7 @@ private void testGetParameterMetaData(boolean explicitPrepare) } try (Statement statement = connection.createStatement()) { - statement.execute("DROP TABLE test_get_parameterMetaData"); + statement.execute("DROP TABLE " + tableName); } } } @@ -485,9 +488,10 @@ public void testExecuteUpdate() public void testExecuteUpdate(boolean explicitPrepare) throws Exception { + String tableName = "test_execute_update_" + randomNameSuffix(); try (Connection connection = createConnection("blackhole", "blackhole", explicitPrepare)) { try (Statement statement = connection.createStatement()) { - statement.execute("CREATE TABLE test_execute_update (" + + statement.execute("CREATE TABLE " + tableName + " (" + "c_boolean boolean, " + "c_bigint bigint, " + "c_double double, " + @@ -498,7 +502,7 @@ public void testExecuteUpdate(boolean explicitPrepare) } try (PreparedStatement statement = connection.prepareStatement( - "INSERT INTO test_execute_update VALUES (?, ?, ?, ?, ?, ?, ?)")) { + "INSERT INTO " + tableName + " VALUES (?, ?, ?, ?, ?, ?, ?)")) { statement.setBoolean(1, true); statement.setLong(2, 5L); statement.setDouble(3, 7.0d); @@ -515,7 +519,7 @@ public void testExecuteUpdate(boolean explicitPrepare) } try (Statement statement = connection.createStatement()) { - statement.execute("DROP TABLE test_execute_update"); + statement.execute("DROP TABLE " + tableName); } } } @@ -531,13 +535,14 @@ public void testExecuteBatch() private void testExecuteBatch(boolean explicitPrepare) throws Exception { + String tableName = "test_execute_batch_" + randomNameSuffix(); try (Connection connection = createConnection("memory", "default", explicitPrepare)) { try (Statement statement = connection.createStatement()) { - statement.execute("CREATE TABLE test_execute_batch(c_int integer)"); + statement.execute("CREATE TABLE " + tableName + "(c_int integer)"); } try (PreparedStatement preparedStatement = connection.prepareStatement( - "INSERT INTO test_execute_batch VALUES (?)")) { + "INSERT INTO " + tableName + " VALUES (?)")) { // Run executeBatch before addBatch assertEquals(preparedStatement.executeBatch(), new int[] {}); @@ -548,7 +553,7 @@ private void testExecuteBatch(boolean explicitPrepare) assertEquals(preparedStatement.executeBatch(), new int[] {1, 1, 1}); try (Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("SELECT c_int FROM test_execute_batch"); + ResultSet resultSet = statement.executeQuery("SELECT c_int FROM " + tableName); assertThat(readRows(resultSet)) .containsExactlyInAnyOrder( list(0), @@ -569,7 +574,7 @@ private void testExecuteBatch(boolean explicitPrepare) } try (Statement statement = connection.createStatement()) { - statement.execute("DROP TABLE test_execute_batch"); + statement.execute("DROP TABLE " + tableName); } } } @@ -585,13 +590,14 @@ public void testInvalidExecuteBatch() private void testInvalidExecuteBatch(boolean explicitPrepare) throws Exception { + String tableName = "test_execute_invalid_batch_" + randomNameSuffix(); try (Connection connection = createConnection("blackhole", "blackhole", explicitPrepare)) { try (Statement statement = connection.createStatement()) { - statement.execute("CREATE TABLE test_invalid_execute_batch(c_int integer)"); + statement.execute("CREATE TABLE " + tableName + "(c_int integer)"); } try (PreparedStatement statement = connection.prepareStatement( - "INSERT INTO test_invalid_execute_batch VALUES (?)")) { + "INSERT INTO " + tableName + " VALUES (?)")) { statement.setInt(1, 1); statement.addBatch(); @@ -611,7 +617,7 @@ private void testInvalidExecuteBatch(boolean explicitPrepare) } try (Statement statement = connection.createStatement()) { - statement.execute("DROP TABLE test_invalid_execute_batch"); + statement.execute("DROP TABLE " + tableName); } } } @@ -1423,12 +1429,13 @@ private Connection createConnection(String catalog, String schema, boolean expli private void testExplicitPrepareSetting(boolean explicitPrepare, String expectedSql) throws Exception { - String selectSql = "SELECT * FROM blackhole.blackhole.test_table WHERE x = ? AND y = ? AND y <> 'Test'"; - String insertSql = "INSERT INTO blackhole.blackhole.test_table (x, y) VALUES (?, ?)"; + String tableName = "test_table_" + randomNameSuffix(); + String selectSql = "SELECT * FROM blackhole.blackhole." + tableName + " WHERE x = ? AND y = ? AND y <> 'Test'"; + String insertSql = "INSERT INTO blackhole.blackhole." + tableName + " (x, y) VALUES (?, ?)"; try (Connection connection = createConnection(explicitPrepare)) { try (Statement statement = connection.createStatement()) { - assertEquals(statement.executeUpdate("CREATE TABLE blackhole.blackhole.test_table (x bigint, y varchar)"), 0); + assertEquals(statement.executeUpdate("CREATE TABLE blackhole.blackhole." + tableName + " (x bigint, y varchar)"), 0); } try (PreparedStatement ps = connection.prepareStatement(selectSql)) { @@ -1484,7 +1491,7 @@ private void testExplicitPrepareSetting(boolean explicitPrepare, String expected } try (Statement statement = connection.createStatement()) { - assertEquals(statement.executeUpdate("DROP TABLE blackhole.blackhole.test_table"), 0); + assertEquals(statement.executeUpdate("DROP TABLE blackhole.blackhole." + tableName), 0); } } }