From f5c1a0b387ae9917991e34563a8b9b34f86d2a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Kokosi=C5=84ski?= Date: Mon, 21 Aug 2023 13:41:04 +0200 Subject: [PATCH] Use random table names in tests --- .../plugin/hive/BaseHiveConnectorTest.java | 70 ++++++++++--------- .../iceberg/BaseIcebergConnectorTest.java | 29 ++++---- 2 files changed, 51 insertions(+), 48 deletions(-) diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/BaseHiveConnectorTest.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/BaseHiveConnectorTest.java index 8369cb1dde80..48d449665e01 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/BaseHiveConnectorTest.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/BaseHiveConnectorTest.java @@ -5528,43 +5528,44 @@ private void testSchemaMismatchesWithDereferenceProjections(Session session, Hiv { // Verify reordering of subfields between a partition column and a table column is not supported // eg. table column: a row(c varchar, b bigint), partition column: a row(b bigint, c varchar) + String tableName = "evolve_test_" + randomNameSuffix(); try { - assertUpdate(session, "CREATE TABLE evolve_test (dummy bigint, a row(b bigint, c varchar), d bigint) with (format = '" + format + "', partitioned_by=array['d'])"); - assertUpdate(session, "INSERT INTO evolve_test values (10, row(1, 'abc'), 1)", 1); - assertUpdate(session, "ALTER TABLE evolve_test DROP COLUMN a"); - assertUpdate(session, "ALTER TABLE evolve_test ADD COLUMN a row(c varchar, b bigint)"); - assertUpdate(session, "INSERT INTO evolve_test values (20, row('def', 2), 2)", 1); - assertQueryFails(session, "SELECT a.b FROM evolve_test where d = 1", ".*There is a mismatch between the table and partition schemas.*"); + assertUpdate(session, "CREATE TABLE " + tableName + " (dummy bigint, a row(b bigint, c varchar), d bigint) with (format = '" + format + "', partitioned_by=array['d'])"); + assertUpdate(session, "INSERT INTO " + tableName + " values (10, row(1, 'abc'), 1)", 1); + assertUpdate(session, "ALTER TABLE " + tableName + " DROP COLUMN a"); + assertUpdate(session, "ALTER TABLE " + tableName + " ADD COLUMN a row(c varchar, b bigint)"); + assertUpdate(session, "INSERT INTO " + tableName + " values (20, row('def', 2), 2)", 1); + assertQueryFails(session, "SELECT a.b FROM " + tableName + " where d = 1", ".*There is a mismatch between the table and partition schemas.*"); } finally { - assertUpdate(session, "DROP TABLE IF EXISTS evolve_test"); + assertUpdate(session, "DROP TABLE IF EXISTS " + tableName); } // Subfield absent in partition schema is reported as null // i.e. "a.c" produces null for rows that were inserted before type of "a" was changed try { - assertUpdate(session, "CREATE TABLE evolve_test (dummy bigint, a row(b bigint), d bigint) with (format = '" + format + "', partitioned_by=array['d'])"); - assertUpdate(session, "INSERT INTO evolve_test values (10, row(1), 1)", 1); - assertUpdate(session, "ALTER TABLE evolve_test DROP COLUMN a"); - assertUpdate(session, "ALTER TABLE evolve_test ADD COLUMN a row(b bigint, c varchar)"); - assertUpdate(session, "INSERT INTO evolve_test values (20, row(2, 'def'), 2)", 1); - assertQuery(session, "SELECT a.c FROM evolve_test", "SELECT 'def' UNION SELECT null"); + assertUpdate(session, "CREATE TABLE " + tableName + " (dummy bigint, a row(b bigint), d bigint) with (format = '" + format + "', partitioned_by=array['d'])"); + assertUpdate(session, "INSERT INTO " + tableName + " values (10, row(1), 1)", 1); + assertUpdate(session, "ALTER TABLE " + tableName + " DROP COLUMN a"); + assertUpdate(session, "ALTER TABLE " + tableName + " ADD COLUMN a row(b bigint, c varchar)"); + assertUpdate(session, "INSERT INTO " + tableName + " values (20, row(2, 'def'), 2)", 1); + assertQuery(session, "SELECT a.c FROM " + tableName, "SELECT 'def' UNION SELECT null"); } finally { - assertUpdate(session, "DROP TABLE IF EXISTS evolve_test"); + assertUpdate(session, "DROP TABLE IF EXISTS " + tableName); } // Verify field access when the row evolves without changes to field type try { - assertUpdate(session, "CREATE TABLE evolve_test (dummy bigint, a row(b bigint, c varchar), d bigint) with (format = '" + format + "', partitioned_by=array['d'])"); - assertUpdate(session, "INSERT INTO evolve_test values (10, row(1, 'abc'), 1)", 1); - assertUpdate(session, "ALTER TABLE evolve_test DROP COLUMN a"); - assertUpdate(session, "ALTER TABLE evolve_test ADD COLUMN a row(b bigint, c varchar, e int)"); - assertUpdate(session, "INSERT INTO evolve_test values (20, row(2, 'def', 2), 2)", 1); - assertQuery(session, "SELECT a.b FROM evolve_test", "VALUES 1, 2"); + assertUpdate(session, "CREATE TABLE " + tableName + " (dummy bigint, a row(b bigint, c varchar), d bigint) with (format = '" + format + "', partitioned_by=array['d'])"); + assertUpdate(session, "INSERT INTO " + tableName + " values (10, row(1, 'abc'), 1)", 1); + assertUpdate(session, "ALTER TABLE " + tableName + " DROP COLUMN a"); + assertUpdate(session, "ALTER TABLE " + tableName + " ADD COLUMN a row(b bigint, c varchar, e int)"); + assertUpdate(session, "INSERT INTO " + tableName + " values (20, row(2, 'def', 2), 2)", 1); + assertQuery(session, "SELECT a.b FROM " + tableName, "VALUES 1, 2"); } finally { - assertUpdate(session, "DROP TABLE IF EXISTS evolve_test"); + assertUpdate(session, "DROP TABLE IF EXISTS " + tableName); } } @@ -5573,33 +5574,34 @@ public void testSubfieldReordering() { // Validate for formats for which subfield access is name based List formats = ImmutableList.of(HiveStorageFormat.ORC, HiveStorageFormat.PARQUET, HiveStorageFormat.AVRO); + String tableName = "evolve_test_" + randomNameSuffix(); for (HiveStorageFormat format : formats) { // Subfields reordered in the file are read correctly. e.g. if partition column type is row(b bigint, c varchar) but the file // column type is row(c varchar, b bigint), "a.b" should read the correct field from the file. try { - assertUpdate("CREATE TABLE evolve_test (dummy bigint, a row(b bigint, c varchar)) with (format = '" + format + "')"); - assertUpdate("INSERT INTO evolve_test values (1, row(1, 'abc'))", 1); - assertUpdate("ALTER TABLE evolve_test DROP COLUMN a"); - assertUpdate("ALTER TABLE evolve_test ADD COLUMN a row(c varchar, b bigint)"); - assertQuery("SELECT a.b FROM evolve_test", "VALUES 1"); + assertUpdate("CREATE TABLE " + tableName + " (dummy bigint, a row(b bigint, c varchar)) with (format = '" + format + "')"); + assertUpdate("INSERT INTO " + tableName + " values (1, row(1, 'abc'))", 1); + assertUpdate("ALTER TABLE " + tableName + " DROP COLUMN a"); + assertUpdate("ALTER TABLE " + tableName + " ADD COLUMN a row(c varchar, b bigint)"); + assertQuery("SELECT a.b FROM " + tableName, "VALUES 1"); } finally { - assertUpdate("DROP TABLE IF EXISTS evolve_test"); + assertUpdate("DROP TABLE IF EXISTS " + tableName); } // Assert that reordered subfields are read correctly for a two-level nesting. This is useful for asserting correct adaptation // of residue projections in HivePageSourceProvider try { - assertUpdate("CREATE TABLE evolve_test (dummy bigint, a row(b bigint, c row(x bigint, y varchar))) with (format = '" + format + "')"); - assertUpdate("INSERT INTO evolve_test values (1, row(1, row(3, 'abc')))", 1); - assertUpdate("ALTER TABLE evolve_test DROP COLUMN a"); - assertUpdate("ALTER TABLE evolve_test ADD COLUMN a row(c row(y varchar, x bigint), b bigint)"); + assertUpdate("CREATE TABLE " + tableName + " (dummy bigint, a row(b bigint, c row(x bigint, y varchar))) with (format = '" + format + "')"); + assertUpdate("INSERT INTO " + tableName + " values (1, row(1, row(3, 'abc')))", 1); + assertUpdate("ALTER TABLE " + tableName + " DROP COLUMN a"); + assertUpdate("ALTER TABLE " + tableName + " ADD COLUMN a row(c row(y varchar, x bigint), b bigint)"); // TODO: replace the following assertion with assertQuery once h2QueryRunner starts supporting row types - assertQuerySucceeds("SELECT a.c.y, a.c FROM evolve_test"); + assertQuerySucceeds("SELECT a.c.y, a.c FROM " + tableName); } finally { - assertUpdate("DROP TABLE IF EXISTS evolve_test"); + assertUpdate("DROP TABLE IF EXISTS " + tableName); } } } @@ -7888,7 +7890,7 @@ protected boolean isColumnNameRejected(Exception exception, String columnName, b private void testColumnPruning(Session session, HiveStorageFormat storageFormat) { - String tableName = "test_schema_evolution_column_pruning_" + storageFormat.name().toLowerCase(ENGLISH); + String tableName = "test_schema_evolution_column_pruning_" + storageFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix(); String evolvedTableName = tableName + "_evolved"; assertUpdate(session, "DROP TABLE IF EXISTS " + tableName); diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java index 532a6285533f..0a19c9b8b5c8 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java @@ -4870,22 +4870,23 @@ public void testAmbiguousColumnsWithDots() public void testSchemaEvolutionWithDereferenceProjections() { // Fields are identified uniquely based on unique id's. If a column is dropped and recreated with the same name it should not return dropped data. - assertUpdate("CREATE TABLE evolve_test (dummy BIGINT, a row(b BIGINT, c VARCHAR))"); - assertUpdate("INSERT INTO evolve_test VALUES (1, ROW(1, 'abc'))", 1); - assertUpdate("ALTER TABLE evolve_test DROP COLUMN a"); - assertUpdate("ALTER TABLE evolve_test ADD COLUMN a ROW(b VARCHAR, c BIGINT)"); - assertQuery("SELECT a.b FROM evolve_test", "VALUES NULL"); - assertUpdate("DROP TABLE evolve_test"); + String tableName = "evolve_test_" + randomNameSuffix(); + assertUpdate("CREATE TABLE " + tableName + " (dummy BIGINT, a row(b BIGINT, c VARCHAR))"); + assertUpdate("INSERT INTO " + tableName + " VALUES (1, ROW(1, 'abc'))", 1); + assertUpdate("ALTER TABLE " + tableName + " DROP COLUMN a"); + assertUpdate("ALTER TABLE " + tableName + " ADD COLUMN a ROW(b VARCHAR, c BIGINT)"); + assertQuery("SELECT a.b FROM " + tableName, "VALUES NULL"); + assertUpdate("DROP TABLE " + tableName); // Very changing subfield ordering does not revive dropped data - assertUpdate("CREATE TABLE evolve_test (dummy BIGINT, a ROW(b BIGINT, c VARCHAR), d BIGINT) with (partitioning = ARRAY['d'])"); - assertUpdate("INSERT INTO evolve_test VALUES (1, ROW(2, 'abc'), 3)", 1); - assertUpdate("ALTER TABLE evolve_test DROP COLUMN a"); - assertUpdate("ALTER TABLE evolve_test ADD COLUMN a ROW(c VARCHAR, b BIGINT)"); - assertUpdate("INSERT INTO evolve_test VALUES (4, 5, ROW('def', 6))", 1); - assertQuery("SELECT a.b FROM evolve_test WHERE d = 3", "VALUES NULL"); - assertQuery("SELECT a.b FROM evolve_test WHERE d = 5", "VALUES 6"); - assertUpdate("DROP TABLE evolve_test"); + assertUpdate("CREATE TABLE " + tableName + " (dummy BIGINT, a ROW(b BIGINT, c VARCHAR), d BIGINT) with (partitioning = ARRAY['d'])"); + assertUpdate("INSERT INTO " + tableName + " VALUES (1, ROW(2, 'abc'), 3)", 1); + assertUpdate("ALTER TABLE " + tableName + " DROP COLUMN a"); + assertUpdate("ALTER TABLE " + tableName + " ADD COLUMN a ROW(c VARCHAR, b BIGINT)"); + assertUpdate("INSERT INTO " + tableName + " VALUES (4, 5, ROW('def', 6))", 1); + assertQuery("SELECT a.b FROM " + tableName + " WHERE d = 3", "VALUES NULL"); + assertQuery("SELECT a.b FROM " + tableName + " WHERE d = 5", "VALUES 6"); + assertUpdate("DROP TABLE " + tableName); } @Test