From bea1ef72ef16e0a2f0c9a1d8493601e746f1b456 Mon Sep 17 00:00:00 2001 From: Marius Grama Date: Thu, 14 Apr 2022 05:46:18 +0200 Subject: [PATCH] Ignore views on information_schema.columns queries --- ...HiveMetastoreBackedDeltaLakeMetastore.java | 5 ++++ .../glue/TestDeltaLakeGlueMetastore.java | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/HiveMetastoreBackedDeltaLakeMetastore.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/HiveMetastoreBackedDeltaLakeMetastore.java index f8abe2ffb64b..75751214143a 100644 --- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/HiveMetastoreBackedDeltaLakeMetastore.java +++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/HiveMetastoreBackedDeltaLakeMetastore.java @@ -62,6 +62,7 @@ import static io.trino.plugin.deltalake.DeltaLakeMetadata.createStatisticsPredicate; import static io.trino.plugin.deltalake.DeltaLakeSessionProperties.isExtendedStatisticsEnabled; import static io.trino.plugin.deltalake.DeltaLakeSplitManager.partitionMatchesPredicate; +import static io.trino.plugin.hive.ViewReaderUtil.isHiveOrPrestoView; import static io.trino.spi.statistics.StatsUtil.toStatsRepresentation; import static java.lang.Double.NEGATIVE_INFINITY; import static java.lang.Double.NaN; @@ -118,6 +119,10 @@ public Optional getTable(String databaseName, String tableName) { Optional
candidate = delegate.getTable(databaseName, tableName); candidate.ifPresent(table -> { + if (isHiveOrPrestoView(table)) { + // this is a Hive view, hence not a table + throw new NotADeltaLakeTableException(databaseName, tableName); + } if (!TABLE_PROVIDER_VALUE.equalsIgnoreCase(table.getParameters().get(TABLE_PROVIDER_PROPERTY))) { throw new NotADeltaLakeTableException(databaseName, tableName); } diff --git a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaLakeGlueMetastore.java b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaLakeGlueMetastore.java index 5088e9a07901..7b70aef1e688 100644 --- a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaLakeGlueMetastore.java +++ b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaLakeGlueMetastore.java @@ -81,6 +81,7 @@ import static java.lang.String.format; import static java.util.Locale.ENGLISH; import static org.apache.hadoop.hive.metastore.TableType.EXTERNAL_TABLE; +import static org.apache.hadoop.hive.metastore.TableType.VIRTUAL_VIEW; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -173,6 +174,7 @@ public void testHideNonDeltaLakeTable() SchemaTableName deltaLakeTable = new SchemaTableName(databaseName, "delta_lake_table_" + randomName()); SchemaTableName nonDeltaLakeTable1 = new SchemaTableName(databaseName, "hive_table_" + randomName()); SchemaTableName nonDeltaLakeTable2 = new SchemaTableName(databaseName, "hive_table_" + randomName()); + SchemaTableName nonDeltaLakeView1 = new SchemaTableName(databaseName, "hive_view_" + randomName()); String deltaLakeTableLocation = tableLocation(deltaLakeTable); createTable(deltaLakeTable, deltaLakeTableLocation, tableBuilder -> { @@ -188,6 +190,7 @@ public void testHideNonDeltaLakeTable() createTable(nonDeltaLakeTable1, tableLocation(nonDeltaLakeTable1), tableBuilder -> {}); createTable(nonDeltaLakeTable2, tableLocation(nonDeltaLakeTable2), tableBuilder -> tableBuilder.setParameter(TABLE_PROVIDER_PROPERTY, "foo")); + createView(nonDeltaLakeView1, tableLocation(nonDeltaLakeTable1), tableBuilder -> {}); DeltaLakeMetadata metadata = metadataFactory.create(SESSION.getIdentity()); @@ -230,6 +233,8 @@ public void testHideNonDeltaLakeTable() .isEmpty(); assertThat(listTableColumns(metadata, new SchemaTablePrefix(databaseName, nonDeltaLakeTable2.getTableName()))) .isEmpty(); + assertThat(listTableColumns(metadata, new SchemaTablePrefix(databaseName, nonDeltaLakeView1.getTableName()))) + .isEmpty(); } private Set listTableColumns(DeltaLakeMetadata metadata, SchemaTablePrefix tablePrefix) @@ -287,6 +292,25 @@ private void createTable(SchemaTableName tableName, String tableLocation, Consum metastoreClient.createTable(table.build(), principalPrivileges); } + private void createView(SchemaTableName viewName, String tableLocation, Consumer tableConfiguration) + { + Table.Builder table = Table.builder() + .setDatabaseName(viewName.getSchemaName()) + .setTableName(viewName.getTableName()) + .setOwner(Optional.of(session.getUser())) + .setTableType(VIRTUAL_VIEW.name()) + .setDataColumns(List.of(new Column("a_column", HIVE_STRING, Optional.empty()))); + + table.getStorageBuilder() + .setStorageFormat(fromHiveStorageFormat(PARQUET)) + .setLocation(tableLocation); + + tableConfiguration.accept(table); + + PrincipalPrivileges principalPrivileges = new PrincipalPrivileges(ImmutableMultimap.of(), ImmutableMultimap.of()); + metastoreClient.createTable(table.build(), principalPrivileges); + } + private static String randomName() { return UUID.randomUUID().toString().toLowerCase(ENGLISH).replace("-", "");