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 @@ -43,6 +43,7 @@
import io.trino.spi.TrinoException;
import io.trino.spi.connector.CatalogSchemaName;
import io.trino.spi.connector.ConnectorTableMetadata;
import io.trino.spi.connector.ConnectorViewDefinition;
import io.trino.spi.connector.SchemaTableName;
import io.trino.spi.security.PrincipalType;
import io.trino.spi.security.TrinoPrincipal;
Expand Down Expand Up @@ -297,17 +298,21 @@ protected Node visitShowTables(ShowTables showTables, Void context)
@Override
protected Node visitShowGrants(ShowGrants showGrants, Void context)
{
// TODO: make this method redirection aware
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@phd3 there is also a TODO comment here:

// TODO support table redirection
@Override
public List<GrantInfo> listTablePrivileges(Session session, QualifiedTablePrefix prefix)

Am I correct in assuming that handling the MetadataManager#listTablePrivileges is not in the scope of this PR ?

String catalogName = session.getCatalog().orElse(null);
Optional<Expression> predicate = Optional.empty();

Optional<QualifiedName> tableName = showGrants.getTableName();
if (tableName.isPresent()) {
QualifiedObjectName qualifiedTableName = createQualifiedObjectName(session, showGrants, tableName.get());

if (!metadata.isView(session, qualifiedTableName) &&
metadata.getTableHandle(session, qualifiedTableName).isEmpty()) {
throw semanticException(TABLE_NOT_FOUND, showGrants, "Table '%s' does not exist", tableName);
if (!metadata.isView(session, qualifiedTableName)) {
RedirectionAwareTableHandle redirection = metadata.getRedirectionAwareTableHandle(session, qualifiedTableName);
Optional<TableHandle> tableHandle = redirection.getTableHandle();
if (tableHandle.isEmpty()) {
throw semanticException(TABLE_NOT_FOUND, showGrants, "Table '%s' does not exist", tableName);
}
if (redirection.getRedirectedTableName().isPresent()) {
throw semanticException(NOT_SUPPORTED, showGrants, "Table %s is redirected to %s and SHOW GRANTS is not supported with table redirections", tableName.get(), redirection.getRedirectedTableName().get());
}
}

catalogName = qualifiedTableName.getCatalogName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,20 @@ public void testCommentColumn()
onTrino().executeQuery("DROP TABLE " + icebergTableName);
}

@Test(groups = {HIVE_ICEBERG_REDIRECTIONS, PROFILE_SPECIFIC_TESTS})
Comment thread
findinpath marked this conversation as resolved.
Outdated
public void testShowGrants()
{
String tableName = "iceberg_show_grants_" + randomTableSuffix();
String hiveTableName = "hive.default." + tableName;
String icebergTableName = "iceberg.default." + tableName;
createIcebergTable(icebergTableName, false);

assertQueryFailure(() -> onTrino().executeQuery(format("SHOW GRANTS ON %s", hiveTableName)))
.hasMessageMatching("\\QQuery failed (#\\E\\S+\\Q): line 1:1: Table " + hiveTableName + " is redirected to " + icebergTableName + " and SHOW GRANTS is not supported with table redirections");

onTrino().executeQuery("DROP TABLE " + icebergTableName);
}

@Test(groups = {HIVE_ICEBERG_REDIRECTIONS, PROFILE_SPECIFIC_TESTS})
public void testInformationSchemaColumns()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,23 @@ public void testCommentTable()
onTrino().executeQuery("DROP TABLE " + hiveTableName);
}

@Test(groups = {HIVE_ICEBERG_REDIRECTIONS, PROFILE_SPECIFIC_TESTS})
public void testShowGrants()
{
String tableName = "hive_show_grants_" + randomTableSuffix();
String hiveTableName = "hive.default." + tableName;
String icebergTableName = "iceberg.default." + tableName;

createHiveTable(hiveTableName, true);

// TODO: support redirects from Iceberg to Hive
assertQueryFailure(() -> onTrino().executeQuery("SHOW GRANTS ON " + icebergTableName))
.hasMessageMatching("\\QQuery failed (#\\E\\S+\\Q): Not an Iceberg table: default." + tableName);

onTrino().executeQuery("DROP TABLE " + hiveTableName);
}


@Test(groups = {HIVE_ICEBERG_REDIRECTIONS, PROFILE_SPECIFIC_TESTS})
public void testInformationSchemaColumns()
{
Expand Down