Skip to content

Commit

Permalink
Use metastore specific logic to retrieve the views
Browse files Browse the repository at this point in the history
  • Loading branch information
findinpath committed Nov 17, 2023
1 parent 49072b6 commit 511cdea
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2564,7 +2564,12 @@ public void dropView(ConnectorSession session, SchemaTableName viewName)
@Override
public List<SchemaTableName> listViews(ConnectorSession session, Optional<String> schemaName)
{
return trinoViewHiveMetastore.listViews(schemaName);
return schemaName.map(Collections::singletonList)
.orElseGet(() -> listSchemaNames(session))
.stream()
.flatMap(schema -> metastore.getAllViews(schema).stream()
.map(viewName -> new SchemaTableName(schema, viewName)))
.collect(toImmutableList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public interface DeltaLakeMetastore

List<String> getAllTables(String databaseName);

List<String> getAllViews(String databaseName);

Optional<Table> getRawMetastoreTable(String databaseName, String tableName);

Optional<DeltaMetastoreTable> getTable(String databaseName, String tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public List<String> getAllTables(String databaseName)
return delegate.getAllTables(databaseName);
}

@Override
public List<String> getAllViews(String databaseName)
{
return delegate.getAllViews(databaseName);
}

@Override
public Optional<Table> getRawMetastoreTable(String databaseName, String tableName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public void testCreateView()
TestView view = new TestView(getQueryRunner()::execute, viewName, "SELECT * FROM " + table.getName())) {
assertQuery(format("SELECT * FROM %s", view.getName()), "VALUES 'test'");
assertQuery(format("SELECT table_type FROM information_schema.tables WHERE table_name = '%s' AND table_schema='%s'", view.getName(), SCHEMA), "VALUES 'VIEW'");
// Ensure all tables are being listed
assertQuery(format("SELECT table_type FROM information_schema.tables WHERE table_name LIKE '%%%s' AND table_schema='%s'", view.getName(), SCHEMA), "VALUES 'VIEW'");
}
}

Expand Down

0 comments on commit 511cdea

Please sign in to comment.