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 @@ -54,6 +54,7 @@
import static io.trino.connector.informationschema.InformationSchemaMetadata.defaultPrefixes;
import static io.trino.connector.informationschema.InformationSchemaMetadata.isTablesEnumeratingTable;
import static io.trino.metadata.MetadataListing.getViews;
import static io.trino.metadata.MetadataListing.listMaterializedViews;
import static io.trino.metadata.MetadataListing.listSchemas;
import static io.trino.metadata.MetadataListing.listTableColumns;
import static io.trino.metadata.MetadataListing.listTablePrivileges;
Expand Down Expand Up @@ -271,12 +272,18 @@ private void addColumnsRecords(QualifiedTablePrefix prefix)
private void addTablesRecords(QualifiedTablePrefix prefix)
{
Set<SchemaTableName> tables = listTables(session, metadata, accessControl, prefix);
Set<SchemaTableName> materializedViews = listMaterializedViews(session, metadata, accessControl, prefix);
Comment thread
jklamer marked this conversation as resolved.
Outdated
Set<SchemaTableName> views = listViews(session, metadata, accessControl, prefix);
// TODO (https://github.com/trinodb/trino/issues/8207) define a type for materialized views

for (SchemaTableName name : union(tables, views)) {
for (SchemaTableName name : union(union(tables, materializedViews), views)) {
// if table and view names overlap, the view wins
String type = views.contains(name) ? "VIEW" : "BASE TABLE";
String type = "BASE TABLE";
if (materializedViews.contains(name)) {
type = "MATERIALIZED VIEW";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martint Could you confirm whether returning MATERIALIZED VIEW as a table type is okay?

Copy link
Copy Markdown
Member

@martint martint Jan 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, as it is incompatible with the SQL specification. It may affect tools or clients that expect this table to have return specific values.

}
else if (views.contains(name)) {
type = "VIEW";
}
addRecord(
prefix.getCatalogName(),
name.getSchemaName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1017,12 +1017,12 @@ public void testMaterializedView()
"SELECT table_name, table_type FROM information_schema.tables " +
"WHERE table_schema = '" + view.getSchemaName() + "'"))
.skippingTypesCheck()
.containsAll("VALUES ('" + view.getObjectName() + "', 'BASE TABLE')"); // TODO table_type should probably be "* VIEW"
.containsAll("VALUES ('" + view.getObjectName() + "', 'MATERIALIZED VIEW')");
// information_schema.tables with table_name filter
assertQuery(
"SELECT table_name, table_type FROM information_schema.tables " +
"WHERE table_schema = '" + view.getSchemaName() + "' and table_name = '" + view.getObjectName() + "'",
"VALUES ('" + view.getObjectName() + "', 'BASE TABLE')");
"VALUES ('" + view.getObjectName() + "', 'MATERIALIZED VIEW')");

// system.jdbc.tables without filter
assertThat(query("SELECT table_schem, table_name, table_type FROM system.jdbc.tables"))
Expand Down