diff --git a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java index 842bf00f8f199..4fa63f09e5606 100644 --- a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java +++ b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java @@ -185,6 +185,7 @@ public abstract class IcebergAbstractMetadata implements ConnectorMetadata { private static final Logger log = Logger.get(IcebergAbstractMetadata.class); + protected static final String INFORMATION_SCHEMA = "information_schema"; protected final TypeManager typeManager; protected final JsonCodec commitTaskCodec; diff --git a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergHiveMetadata.java b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergHiveMetadata.java index f1f3777613a7a..19d5e531abbb8 100644 --- a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergHiveMetadata.java +++ b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergHiveMetadata.java @@ -212,6 +212,12 @@ public List listSchemaNames(ConnectorSession session) public List listTables(ConnectorSession session, Optional schemaName) { MetastoreContext metastoreContext = getMetastoreContext(session); + if (schemaName.isPresent() && INFORMATION_SCHEMA.equals(schemaName.get())) { + return metastore.getAllDatabases(metastoreContext) + .stream() + .map(table -> new SchemaTableName(INFORMATION_SCHEMA, table)) + .collect(toImmutableList()); + } // If schema name is not present, list tables from all schemas List schemaNames = schemaName .map(ImmutableList::of) @@ -219,7 +225,7 @@ public List listTables(ConnectorSession session, Optional metastore .getAllTables(metastoreContext, schema) - .orElseGet(() -> metastore.getAllDatabases(metastoreContext)) + .orElseGet(() -> ImmutableList.of()) .stream() .map(table -> new SchemaTableName(schema, table))) .collect(toImmutableList()); diff --git a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergNativeMetadata.java b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergNativeMetadata.java index 7e7ce7540e19e..a36759cd7a136 100644 --- a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergNativeMetadata.java +++ b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergNativeMetadata.java @@ -87,7 +87,6 @@ public class IcebergNativeMetadata extends IcebergAbstractMetadata { - private static final String INFORMATION_SCHEMA = "information_schema"; private static final String VIEW_DIALECT = "presto"; private final IcebergNativeCatalogFactory catalogFactory; diff --git a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedTestBase.java b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedTestBase.java index 5bdaa3db84ae4..cb341129b79df 100644 --- a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedTestBase.java +++ b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedTestBase.java @@ -2218,6 +2218,29 @@ public void testHistogramReconstruction(Type type, Object[] values) } } + @Test + public void testInformationSchemaQueries() + { + assertQuerySucceeds("CREATE SCHEMA ICEBERG.TEST_SCHEMA1"); + assertQuerySucceeds("CREATE SCHEMA ICEBERG.TEST_SCHEMA2"); + assertQuerySucceeds("CREATE TABLE ICEBERG.TEST_SCHEMA1.ICEBERG_T1(i int)"); + assertQuerySucceeds("CREATE TABLE ICEBERG.TEST_SCHEMA1.ICEBERG_T2(i int)"); + assertQuerySucceeds("CREATE TABLE ICEBERG.TEST_SCHEMA2.ICEBERG_T3(i int)"); + assertQuerySucceeds("CREATE TABLE ICEBERG.TEST_SCHEMA2.ICEBERG_T4(i int)"); + + assertQuery("SELECT table_name FROM iceberg.information_schema.tables WHERE table_schema ='test_schema1'", "VALUES 'iceberg_t1', 'iceberg_t2'"); + assertQuery("SELECT table_name FROM iceberg.information_schema.tables WHERE table_schema ='test_schema2'", "VALUES 'iceberg_t3', 'iceberg_t4'"); + //query on non-existing schema + assertQueryReturnsEmptyResult("SELECT table_name FROM iceberg.information_schema.tables WHERE table_schema = 'NON_EXISTING_SCHEMA'"); + + assertQuerySucceeds("DROP TABLE ICEBERG.TEST_SCHEMA1.ICEBERG_T1"); + assertQuerySucceeds("DROP TABLE ICEBERG.TEST_SCHEMA1.ICEBERG_T2"); + assertQuerySucceeds("DROP TABLE ICEBERG.TEST_SCHEMA2.ICEBERG_T3"); + assertQuerySucceeds("DROP TABLE ICEBERG.TEST_SCHEMA2.ICEBERG_T4"); + assertQuerySucceeds("DROP SCHEMA ICEBERG.TEST_SCHEMA1"); + assertQuerySucceeds("DROP SCHEMA ICEBERG.TEST_SCHEMA2"); + } + private void testCheckDeleteFiles(Table icebergTable, int expectedSize, List expectedFileContent) { // check delete file list