From 2210920c995c623e23db05f081ee06bafb6028a4 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Fri, 14 Jul 2023 17:06:31 +0200 Subject: [PATCH] Test Iceberg operations for information_schema.columns --- .../TestIcebergMetadataFileOperations.java | 20 ++++++++++++++++ .../TestIcebergMetastoreAccessOperations.java | 24 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetadataFileOperations.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetadataFileOperations.java index a96a58dc7cff..d09f3106d3e0 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetadataFileOperations.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetadataFileOperations.java @@ -496,6 +496,26 @@ public void testRemoveOrphanFiles() assertUpdate("DROP TABLE " + tableName); } + @Test + public void testInformationSchemaColumns() + { + int tables = 3; + for (int i = 0; i < tables; i++) { + assertUpdate("CREATE TABLE test_select_i_s_columns" + i + "(id VARCHAR, age INT)"); + assertUpdate("CREATE TABLE test_other_select_i_s_columns" + i + "(id VARCHAR, age INT)"); // won't match the filter + } + + assertFileSystemAccesses("SELECT * FROM information_schema.columns WHERE table_name LIKE 'test_select_i_s_columns%'", + ImmutableMultiset.builder() + .addCopies(new FileOperation(METADATA_JSON, INPUT_FILE_NEW_STREAM), 3) + .build()); + + for (int i = 0; i < tables; i++) { + assertUpdate("DROP TABLE test_select_i_s_columns" + i); + assertUpdate("DROP TABLE test_other_select_i_s_columns" + i); + } + } + private void assertFileSystemAccesses(@Language("SQL") String query, Multiset expectedAccesses) { assertFileSystemAccesses(getSession(), query, expectedAccesses); diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java index 4799280c5844..e92335dba968 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java @@ -30,6 +30,8 @@ import static com.google.inject.util.Modules.EMPTY_MODULE; import static io.trino.plugin.hive.metastore.CountingAccessHiveMetastore.Method.CREATE_TABLE; import static io.trino.plugin.hive.metastore.CountingAccessHiveMetastore.Method.DROP_TABLE; +import static io.trino.plugin.hive.metastore.CountingAccessHiveMetastore.Method.GET_ALL_DATABASES; +import static io.trino.plugin.hive.metastore.CountingAccessHiveMetastore.Method.GET_ALL_TABLES_FROM_DATABASE; import static io.trino.plugin.hive.metastore.CountingAccessHiveMetastore.Method.GET_DATABASE; import static io.trino.plugin.hive.metastore.CountingAccessHiveMetastore.Method.GET_TABLE; import static io.trino.plugin.hive.metastore.CountingAccessHiveMetastore.Method.REPLACE_TABLE; @@ -319,6 +321,28 @@ public void testUnregisterTable() .build()); } + @Test + public void testInformationSchemaColumns() + { + int tables = 3; + for (int i = 0; i < tables; i++) { + assertUpdate("CREATE TABLE test_select_i_s_columns" + i + "(id VARCHAR, age INT)"); + assertUpdate("CREATE TABLE test_other_select_i_s_columns" + i + "(id VARCHAR, age INT)"); // won't match the filter + } + + assertMetastoreInvocations("SELECT * FROM information_schema.columns WHERE table_name LIKE 'test_select_i_s_columns%'", + ImmutableMultiset.builder() + .add(GET_ALL_DATABASES) + .add(GET_ALL_TABLES_FROM_DATABASE) + .addCopies(GET_TABLE, 3) + .build()); + + for (int i = 0; i < tables; i++) { + assertUpdate("DROP TABLE test_select_i_s_columns" + i); + assertUpdate("DROP TABLE test_other_select_i_s_columns" + i); + } + } + private void assertMetastoreInvocations(@Language("SQL") String query, Multiset expectedInvocations) { assertMetastoreInvocations(getSession(), query, expectedInvocations);