Skip to content

Commit

Permalink
Introduce <catalog>.information_schema.roles table
Browse files Browse the repository at this point in the history
Extracted-From: prestodb/presto#10904
  • Loading branch information
Andrii Rosa authored and sopel39 committed Jan 29, 2019
1 parent 745e4b8 commit 07c5496
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Expand Up @@ -74,6 +74,7 @@ public class InformationSchemaMetadata
public static final SchemaTableName TABLE_VIEWS = new SchemaTableName(INFORMATION_SCHEMA, "views");
public static final SchemaTableName TABLE_SCHEMATA = new SchemaTableName(INFORMATION_SCHEMA, "schemata");
public static final SchemaTableName TABLE_TABLE_PRIVILEGES = new SchemaTableName(INFORMATION_SCHEMA, "table_privileges");
public static final SchemaTableName TABLE_ROLES = new SchemaTableName(INFORMATION_SCHEMA, "roles");

public static final Map<SchemaTableName, ConnectorTableMetadata> TABLES = schemaMetadataBuilder()
.table(tableMetadataBuilder(TABLE_COLUMNS)
Expand Down Expand Up @@ -114,6 +115,9 @@ public class InformationSchemaMetadata
.column("is_grantable", BOOLEAN)
.column("with_hierarchy", BOOLEAN)
.build())
.table(tableMetadataBuilder(TABLE_ROLES)
.column("role_name", createUnboundedVarcharType())
.build())
.build();

private static final InformationSchemaColumnHandle CATALOG_COLUMN_HANDLE = new InformationSchemaColumnHandle("table_catalog");
Expand Down
Expand Up @@ -43,6 +43,7 @@

import static com.google.common.collect.Sets.union;
import static io.prestosql.connector.informationSchema.InformationSchemaMetadata.TABLE_COLUMNS;
import static io.prestosql.connector.informationSchema.InformationSchemaMetadata.TABLE_ROLES;
import static io.prestosql.connector.informationSchema.InformationSchemaMetadata.TABLE_SCHEMATA;
import static io.prestosql.connector.informationSchema.InformationSchemaMetadata.TABLE_TABLES;
import static io.prestosql.connector.informationSchema.InformationSchemaMetadata.TABLE_TABLE_PRIVILEGES;
Expand Down Expand Up @@ -121,6 +122,9 @@ public InternalTable getInformationSchemaTable(Session session, String catalog,
if (table.equals(TABLE_TABLE_PRIVILEGES)) {
return buildTablePrivileges(session, prefixes);
}
if (table.equals(TABLE_ROLES)) {
return buildRoles(session, catalog);
}

throw new IllegalArgumentException(format("table does not exist: %s", table));
}
Expand Down Expand Up @@ -219,4 +223,13 @@ private InternalTable buildSchemata(Session session, String catalogName)
}
return table.build();
}

private InternalTable buildRoles(Session session, String catalog)
{
InternalTable.Builder table = InternalTable.builder(informationSchemaTableColumns(TABLE_ROLES));
for (String role : metadata.listRoles(session, catalog)) {
table.add(role);
}
return table.build();
}
}
Expand Up @@ -9,6 +9,7 @@ system| information_schema| columns| is_nullable| varchar| YES| null| null|
system| information_schema| columns| data_type| varchar| YES| null| null|
system| information_schema| columns| comment| varchar| YES| null| null|
system| information_schema| columns| extra_info| varchar| YES| null| null|
system| information_schema| roles| role_name| varchar| YES| null| null|
system| information_schema| schemata| catalog_name| varchar| YES| null| null|
system| information_schema| schemata| schema_name| varchar| YES| null| null|
system| information_schema| table_privileges| grantor| varchar| YES| null| null|
Expand Down

0 comments on commit 07c5496

Please sign in to comment.