diff --git a/presto-product-tests/src/main/java/io/prestosql/tests/iceberg/TestIcebergCreateTable.java b/presto-product-tests/src/main/java/io/prestosql/tests/iceberg/TestIcebergCreateTable.java index 67fa885bb63d..db0bc23b3516 100644 --- a/presto-product-tests/src/main/java/io/prestosql/tests/iceberg/TestIcebergCreateTable.java +++ b/presto-product-tests/src/main/java/io/prestosql/tests/iceberg/TestIcebergCreateTable.java @@ -32,7 +32,8 @@ public class TestIcebergCreateTable @BeforeTestWithContext public void setUp() { - onPresto().executeQuery("CREATE SCHEMA iceberg.iceberg"); + // Use IF NOT EXISTS because the schema can be left behind after previous test, as the tests are @Flaky + onPresto().executeQuery("CREATE SCHEMA IF NOT EXISTS iceberg.iceberg"); } @AfterTestWithContext @@ -47,16 +48,20 @@ public void testCreateTable() { String tableName = "iceberg.iceberg.test_create_table_" + randomTableSuffix(); onPresto().executeQuery("CREATE TABLE " + tableName + "(a bigint, b varchar)"); - onPresto().executeQuery("INSERT INTO " + tableName + "(a, b) VALUES " + - "(NULL, NULL), " + - "(-42, 'abc'), " + - "(9223372036854775807, 'abcdefghijklmnopqrstuvwxyz')"); - assertThat(onPresto().executeQuery("SELECT * FROM " + tableName)) - .containsOnly( - row(null, null), - row(-42, "abc"), - row(9223372036854775807L, "abcdefghijklmnopqrstuvwxyz")); - onPresto().executeQuery("DROP TABLE " + tableName); + try { + onPresto().executeQuery("INSERT INTO " + tableName + "(a, b) VALUES " + + "(NULL, NULL), " + + "(-42, 'abc'), " + + "(9223372036854775807, 'abcdefghijklmnopqrstuvwxyz')"); + assertThat(onPresto().executeQuery("SELECT * FROM " + tableName)) + .containsOnly( + row(null, null), + row(-42, "abc"), + row(9223372036854775807L, "abcdefghijklmnopqrstuvwxyz")); + } + finally { + onPresto().executeQuery("DROP TABLE " + tableName); + } } @Test(groups = {ICEBERG, STORAGE_FORMATS}) @@ -71,11 +76,15 @@ public void testCreateTableAsSelect() " (-42, 'abc'), " + " (9223372036854775807, 'abcdefghijklmnopqrstuvwxyz')" + ") t(a, b)"); - assertThat(onPresto().executeQuery("SELECT * FROM " + tableName)) - .containsOnly( - row(null, null), - row(-42, "abc"), - row(9223372036854775807L, "abcdefghijklmnopqrstuvwxyz")); - onPresto().executeQuery("DROP TABLE " + tableName); + try { + assertThat(onPresto().executeQuery("SELECT * FROM " + tableName)) + .containsOnly( + row(null, null), + row(-42, "abc"), + row(9223372036854775807L, "abcdefghijklmnopqrstuvwxyz")); + } + finally { + onPresto().executeQuery("DROP TABLE " + tableName); + } } }