Skip to content

Commit

Permalink
Move ThriftHiveMetastore identity from method parameters to constructor
Browse files Browse the repository at this point in the history
Remove HiveIdentity
  • Loading branch information
dain committed Jun 25, 2022
1 parent 999331d commit c9f881f
Show file tree
Hide file tree
Showing 21 changed files with 327 additions and 436 deletions.

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package io.trino.plugin.hive.metastore.thrift;

import io.trino.plugin.hive.authentication.HiveIdentity;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.HiveMetastoreFactory;
import io.trino.spi.security.ConnectorIdentity;
Expand Down Expand Up @@ -44,6 +43,6 @@ public boolean isImpersonationEnabled()
@Override
public HiveMetastore createMetastore(Optional<ConnectorIdentity> identity)
{
return new BridgingHiveMetastore(thriftMetastoreFactory.createMetastore(), identity.map(HiveIdentity::new).orElse(HiveIdentity.none()));
return new BridgingHiveMetastore(thriftMetastoreFactory.createMetastore(identity));
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
import io.airlift.units.Duration;
import io.trino.plugin.hive.HdfsEnvironment;
import io.trino.plugin.hive.HideDeltaLakeTables;
import io.trino.spi.security.ConnectorIdentity;
import org.weakref.jmx.Flatten;
import org.weakref.jmx.Managed;

import javax.inject.Inject;

import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -79,9 +82,10 @@ public boolean isImpersonationEnabled()
}

@Override
public ThriftMetastore createMetastore()
public ThriftMetastore createMetastore(Optional<ConnectorIdentity> identity)
{
return new ThriftHiveMetastore(
identity,
hdfsEnvironment,
metastoreFactory,
backoffScaleFactor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import io.trino.plugin.hive.PartitionStatistics;
import io.trino.plugin.hive.acid.AcidOperation;
import io.trino.plugin.hive.acid.AcidTransaction;
import io.trino.plugin.hive.authentication.HiveIdentity;
import io.trino.plugin.hive.metastore.AcidTransactionOwner;
import io.trino.plugin.hive.metastore.HivePrincipal;
import io.trino.plugin.hive.metastore.HivePrivilegeInfo;
Expand Down Expand Up @@ -47,81 +46,81 @@

public interface ThriftMetastore
{
void createDatabase(HiveIdentity identity, Database database);
void createDatabase(Database database);

void dropDatabase(HiveIdentity identity, String databaseName, boolean deleteData);
void dropDatabase(String databaseName, boolean deleteData);

void alterDatabase(HiveIdentity identity, String databaseName, Database database);
void alterDatabase(String databaseName, Database database);

void createTable(HiveIdentity identity, Table table);
void createTable(Table table);

void dropTable(HiveIdentity identity, String databaseName, String tableName, boolean deleteData);
void dropTable(String databaseName, String tableName, boolean deleteData);

void alterTable(HiveIdentity identity, String databaseName, String tableName, Table table);
void alterTable(String databaseName, String tableName, Table table);

void alterTransactionalTable(HiveIdentity identity, Table table, long transactionId, long writeId);
void alterTransactionalTable(Table table, long transactionId, long writeId);

List<String> getAllDatabases(HiveIdentity identity);
List<String> getAllDatabases();

List<String> getAllTables(HiveIdentity identity, String databaseName);
List<String> getAllTables(String databaseName);

List<String> getTablesWithParameter(HiveIdentity identity, String databaseName, String parameterKey, String parameterValue);
List<String> getTablesWithParameter(String databaseName, String parameterKey, String parameterValue);

List<String> getAllViews(HiveIdentity identity, String databaseName);
List<String> getAllViews(String databaseName);

Optional<Database> getDatabase(HiveIdentity identity, String databaseName);
Optional<Database> getDatabase(String databaseName);

void addPartitions(HiveIdentity identity, String databaseName, String tableName, List<PartitionWithStatistics> partitions);
void addPartitions(String databaseName, String tableName, List<PartitionWithStatistics> partitions);

void dropPartition(HiveIdentity identity, String databaseName, String tableName, List<String> parts, boolean deleteData);
void dropPartition(String databaseName, String tableName, List<String> parts, boolean deleteData);

void alterPartition(HiveIdentity identity, String databaseName, String tableName, PartitionWithStatistics partition);
void alterPartition(String databaseName, String tableName, PartitionWithStatistics partition);

Optional<List<String>> getPartitionNamesByFilter(HiveIdentity identity, String databaseName, String tableName, List<String> columnNames, TupleDomain<String> partitionKeysFilter);
Optional<List<String>> getPartitionNamesByFilter(String databaseName, String tableName, List<String> columnNames, TupleDomain<String> partitionKeysFilter);

Optional<Partition> getPartition(HiveIdentity identity, String databaseName, String tableName, List<String> partitionValues);
Optional<Partition> getPartition(String databaseName, String tableName, List<String> partitionValues);

List<Partition> getPartitionsByNames(HiveIdentity identity, String databaseName, String tableName, List<String> partitionNames);
List<Partition> getPartitionsByNames(String databaseName, String tableName, List<String> partitionNames);

Optional<Table> getTable(HiveIdentity identity, String databaseName, String tableName);
Optional<Table> getTable(String databaseName, String tableName);

Set<ColumnStatisticType> getSupportedColumnStatistics(Type type);

PartitionStatistics getTableStatistics(HiveIdentity identity, Table table);
PartitionStatistics getTableStatistics(Table table);

Map<String, PartitionStatistics> getPartitionStatistics(HiveIdentity identity, Table table, List<Partition> partitions);
Map<String, PartitionStatistics> getPartitionStatistics(Table table, List<Partition> partitions);

void updateTableStatistics(HiveIdentity identity, String databaseName, String tableName, AcidTransaction transaction, Function<PartitionStatistics, PartitionStatistics> update);
void updateTableStatistics(String databaseName, String tableName, AcidTransaction transaction, Function<PartitionStatistics, PartitionStatistics> update);

void updatePartitionStatistics(HiveIdentity identity, Table table, String partitionName, Function<PartitionStatistics, PartitionStatistics> update);
void updatePartitionStatistics(Table table, String partitionName, Function<PartitionStatistics, PartitionStatistics> update);

void createRole(HiveIdentity identity, String role, String grantor);
void createRole(String role, String grantor);

void dropRole(HiveIdentity identity, String role);
void dropRole(String role);

Set<String> listRoles(HiveIdentity identity);
Set<String> listRoles();

void grantRoles(HiveIdentity identity, Set<String> roles, Set<HivePrincipal> grantees, boolean adminOption, HivePrincipal grantor);
void grantRoles(Set<String> roles, Set<HivePrincipal> grantees, boolean adminOption, HivePrincipal grantor);

void revokeRoles(HiveIdentity identity, Set<String> roles, Set<HivePrincipal> grantees, boolean adminOption, HivePrincipal grantor);
void revokeRoles(Set<String> roles, Set<HivePrincipal> grantees, boolean adminOption, HivePrincipal grantor);

Set<RoleGrant> listGrantedPrincipals(HiveIdentity identity, String role);
Set<RoleGrant> listGrantedPrincipals(String role);

Set<RoleGrant> listRoleGrants(HiveIdentity identity, HivePrincipal principal);
Set<RoleGrant> listRoleGrants(HivePrincipal principal);

void grantTablePrivileges(HiveIdentity identity, String databaseName, String tableName, String tableOwner, HivePrincipal grantee, HivePrincipal grantor, Set<HivePrivilege> privileges, boolean grantOption);
void grantTablePrivileges(String databaseName, String tableName, String tableOwner, HivePrincipal grantee, HivePrincipal grantor, Set<HivePrivilege> privileges, boolean grantOption);

void revokeTablePrivileges(HiveIdentity identity, String databaseName, String tableName, String tableOwner, HivePrincipal grantee, HivePrincipal grantor, Set<HivePrivilege> privileges, boolean grantOption);
void revokeTablePrivileges(String databaseName, String tableName, String tableOwner, HivePrincipal grantee, HivePrincipal grantor, Set<HivePrivilege> privileges, boolean grantOption);

/**
* @param tableOwner
* @param principal when empty, all table privileges are returned
*/
Set<HivePrivilegeInfo> listTablePrivileges(HiveIdentity identity, String databaseName, String tableName, Optional<String> tableOwner, Optional<HivePrincipal> principal);
Set<HivePrivilegeInfo> listTablePrivileges(String databaseName, String tableName, Optional<String> tableOwner, Optional<HivePrincipal> principal);

default Optional<List<FieldSchema>> getFields(HiveIdentity identity, String databaseName, String tableName)
default Optional<List<FieldSchema>> getFields(String databaseName, String tableName)
{
Optional<Table> table = getTable(identity, databaseName, tableName);
Optional<Table> table = getTable(databaseName, tableName);
if (table.isEmpty()) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
}
Expand All @@ -133,28 +132,27 @@ default Optional<List<FieldSchema>> getFields(HiveIdentity identity, String data
return Optional.of(table.get().getSd().getCols());
}

default long openTransaction(HiveIdentity identity, AcidTransactionOwner transactionOwner)
default long openTransaction(AcidTransactionOwner transactionOwner)
{
throw new UnsupportedOperationException();
}

default void commitTransaction(HiveIdentity identity, long transactionId)
default void commitTransaction(long transactionId)
{
throw new UnsupportedOperationException();
}

default void abortTransaction(HiveIdentity identity, long transactionId)
default void abortTransaction(long transactionId)
{
throw new UnsupportedOperationException();
}

default void sendTransactionHeartbeat(HiveIdentity identity, long transactionId)
default void sendTransactionHeartbeat(long transactionId)
{
throw new UnsupportedOperationException();
}

default void acquireSharedReadLock(
HiveIdentity identity,
AcidTransactionOwner transactionOwner,
String queryId,
long transactionId,
Expand All @@ -164,23 +162,22 @@ default void acquireSharedReadLock(
throw new UnsupportedOperationException();
}

default String getValidWriteIds(HiveIdentity identity, List<SchemaTableName> tables, long currentTransactionId)
default String getValidWriteIds(List<SchemaTableName> tables, long currentTransactionId)
{
throw new UnsupportedOperationException();
}

default Optional<String> getConfigValue(HiveIdentity identity, String name)
default Optional<String> getConfigValue(String name)
{
return Optional.empty();
}

default long allocateWriteId(HiveIdentity identity, String dbName, String tableName, long transactionId)
default long allocateWriteId(String dbName, String tableName, long transactionId)
{
throw new UnsupportedOperationException();
}

default void acquireTableWriteLock(
HiveIdentity identity,
AcidTransactionOwner transactionOwner,
String queryId,
long transactionId,
Expand All @@ -193,7 +190,6 @@ default void acquireTableWriteLock(
}

default long acquireTableExclusiveLock(
HiveIdentity identity,
AcidTransactionOwner transactionOwner,
String queryId,
String dbName,
Expand All @@ -202,22 +198,22 @@ default long acquireTableExclusiveLock(
throw new UnsupportedOperationException();
}

default void releaseTableLock(HiveIdentity identity, long lockId)
default void releaseTableLock(long lockId)
{
throw new UnsupportedOperationException();
}

default void updateTableWriteId(HiveIdentity identity, String dbName, String tableName, long transactionId, long writeId, OptionalLong rowCountChange)
default void updateTableWriteId(String dbName, String tableName, long transactionId, long writeId, OptionalLong rowCountChange)
{
throw new UnsupportedOperationException();
}

default void alterPartitions(HiveIdentity identity, String dbName, String tableName, List<Partition> partitions, long writeId)
default void alterPartitions(String dbName, String tableName, List<Partition> partitions, long writeId)
{
throw new UnsupportedOperationException();
}

default void addDynamicPartitions(HiveIdentity identity, String dbName, String tableName, List<String> partitionNames, long transactionId, long writeId, AcidOperation operation)
default void addDynamicPartitions(String dbName, String tableName, List<String> partitionNames, long transactionId, long writeId, AcidOperation operation)
{
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
*/
package io.trino.plugin.hive.metastore.thrift;

import io.trino.spi.security.ConnectorIdentity;

import java.util.Optional;

public interface ThriftMetastoreFactory
{
boolean isImpersonationEnabled();

ThriftMetastore createMetastore();
ThriftMetastore createMetastore(Optional<ConnectorIdentity> identity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import com.google.common.util.concurrent.UncheckedExecutionException;
import io.trino.collect.cache.NonEvictableLoadingCache;
import io.trino.plugin.hive.HdfsEnvironment;
import io.trino.plugin.hive.authentication.HiveIdentity;
import io.trino.plugin.hive.metastore.thrift.ThriftMetastoreAuthenticationConfig.ThriftMetastoreAuthenticationType;
import io.trino.spi.TrinoException;
import io.trino.spi.security.ConnectorIdentity;
import org.apache.thrift.TException;

import javax.inject.Inject;
Expand Down Expand Up @@ -66,14 +66,15 @@ private ThriftMetastoreClient createMetastoreClient()
return clientProvider.createMetastoreClient(Optional.empty());
}

public ThriftMetastoreClient createMetastoreClient(HiveIdentity identity)
public ThriftMetastoreClient createMetastoreClient(Optional<ConnectorIdentity> identity)
throws TException
{
if (!impersonationEnabled) {
return createMetastoreClient();
}

String username = identity.getUsername().orElseThrow(() -> new IllegalStateException("End-user name should exist when metastore impersonation is enabled"));
String username = identity.map(ConnectorIdentity::getUser)
.orElseThrow(() -> new IllegalStateException("End-user name should exist when metastore impersonation is enabled"));
if (authenticationEnabled) {
String delegationToken;
try {
Expand Down
Loading

0 comments on commit c9f881f

Please sign in to comment.