com.facebook.presto.metadata.Metadata.grantTablePrivileges()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(2.9k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中com.facebook.presto.metadata.Metadata.grantTablePrivileges()方法的一些代码示例,展示了Metadata.grantTablePrivileges()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata.grantTablePrivileges()方法的具体详情如下:
包路径:com.facebook.presto.metadata.Metadata
类名称:Metadata
方法名:grantTablePrivileges

Metadata.grantTablePrivileges介绍

[英]Grants the specified privilege to the specified user on the specified table
[中]将指定权限授予指定表上的指定用户

代码示例

代码示例来源:origin: prestodb/presto

@Override
public ListenableFuture<?> execute(Grant statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters)
{
  Session session = stateMachine.getSession();
  QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName());
  Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
  if (!tableHandle.isPresent()) {
    throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
  }
  Set<Privilege> privileges;
  if (statement.getPrivileges().isPresent()) {
    privileges = statement.getPrivileges().get().stream()
        .map(privilege -> parsePrivilege(statement, privilege))
        .collect(toImmutableSet());
  }
  else {
    // All privileges
    privileges = EnumSet.allOf(Privilege.class);
  }
  // verify current identity has permissions to grant permissions
  for (Privilege privilege : privileges) {
    accessControl.checkCanGrantTablePrivilege(session.getRequiredTransactionId(), session.getIdentity(), privilege, tableName, statement.getGrantee().getValue(), statement.isWithGrantOption());
  }
  metadata.grantTablePrivileges(session, tableName, privileges, statement.getGrantee().getValue(), statement.isWithGrantOption());
  return immediateFuture(null);
}

代码示例来源:origin: uk.co.nichesolutions.presto/presto-main

@Override
public CompletableFuture<?> execute(Grant statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
  Session session = stateMachine.getSession();
  QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName());
  Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
  if (!tableHandle.isPresent()) {
    throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
  }
  Set<Privilege> privileges;
  if (statement.getPrivileges().isPresent()) {
    privileges = statement.getPrivileges().get().stream()
        .map(privilege -> parsePrivilege(statement, privilege))
        .collect(toImmutableSet());
  }
  else {
    // All privileges
    privileges = ImmutableSet.copyOf(Privilege.values());
  }
  // verify current identity has permissions to grant permissions
  for (Privilege privilege : privileges) {
    accessControl.checkCanGrantTablePrivilege(session.getIdentity(), privilege, tableName);
  }
  metadata.grantTablePrivileges(session, tableName, privileges, statement.getGrantee(), statement.isWithGrantOption());
  return completedFuture(null);
}

相关文章