Java Code Examples for io.prestosql.spi.connector.SchemaTableName#equals()

The following examples show how to use io.prestosql.spi.connector.SchemaTableName#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlStandardAccessControl.java    From presto with Apache License 2.0 6 votes vote down vote up
private boolean hasAnyTablePermission(ConnectorSecurityContext context, SchemaTableName tableName)
{
    if (isAdmin(context)) {
        return true;
    }

    if (tableName.equals(ROLES)) {
        return false;
    }

    if (INFORMATION_SCHEMA_NAME.equals(tableName.getSchemaName())) {
        return true;
    }

    SemiTransactionalHiveMetastore metastore = metastoreProvider.apply(((HiveTransactionHandle) context.getTransactionHandle()));
    Set<HivePrincipal> allowedPrincipals = metastore.listTablePrivileges(new HiveIdentity(context.getIdentity()), tableName.getSchemaName(), tableName.getTableName(), Optional.empty()).stream()
            .map(HivePrivilegeInfo::getGrantee)
            .collect(toImmutableSet());

    return listEnabledPrincipals(metastore, context.getIdentity())
            .anyMatch(allowedPrincipals::contains);
}
 
Example 2
Source File: InMemoryThriftMetastore.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void alterTable(HiveIdentity identity, String databaseName, String tableName, Table newTable)
{
    SchemaTableName oldName = new SchemaTableName(databaseName, tableName);
    SchemaTableName newName = new SchemaTableName(newTable.getDbName(), newTable.getTableName());

    // if the name did not change, this is a simple schema change
    if (oldName.equals(newName)) {
        if (relations.replace(oldName, newTable) == null) {
            throw new TableNotFoundException(oldName);
        }
        return;
    }

    // remove old table definition and add the new one
    Table table = relations.get(oldName);
    if (table == null) {
        throw new TableNotFoundException(oldName);
    }

    if (relations.putIfAbsent(newName, newTable) != null) {
        throw new TableAlreadyExistsException(newName);
    }
    relations.remove(oldName);
}
 
Example 3
Source File: SqlStandardAccessControl.java    From presto with Apache License 2.0 5 votes vote down vote up
private boolean checkTablePermission(
        ConnectorSecurityContext context,
        SchemaTableName tableName,
        HivePrivilege requiredPrivilege,
        boolean grantOptionRequired)
{
    if (isAdmin(context)) {
        return true;
    }

    if (tableName.equals(ROLES) || tableName.equals(ROLE_AUHTORIZATION_DESCRIPTORS)) {
        return false;
    }

    if (INFORMATION_SCHEMA_NAME.equals(tableName.getSchemaName())) {
        return true;
    }

    SemiTransactionalHiveMetastore metastore = metastoreProvider.apply(((HiveTransactionHandle) context.getTransactionHandle()));

    Set<HivePrincipal> allowedPrincipals = metastore.listTablePrivileges(new HiveIdentity(context.getIdentity()), tableName.getSchemaName(), tableName.getTableName(), Optional.empty()).stream()
            .filter(privilegeInfo -> privilegeInfo.getHivePrivilege() == requiredPrivilege)
            .filter(privilegeInfo -> !grantOptionRequired || privilegeInfo.isGrantOption())
            .map(HivePrivilegeInfo::getGrantee)
            .collect(toImmutableSet());

    return listEnabledPrincipals(metastore, context.getIdentity())
            .anyMatch(allowedPrincipals::contains);
}