Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,6 +119,10 @@ public Optional<Table> getTable(String databaseName, String tableName)
{
Optional<Table> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 -> {
Expand All @@ -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());

Expand Down Expand Up @@ -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<SchemaTableName> listTableColumns(DeltaLakeMetadata metadata, SchemaTablePrefix tablePrefix)
Expand Down Expand Up @@ -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<Table.Builder> 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("-", "");
Expand Down