use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class SemiTransactionalHiveMetastore method finishRowLevelDelete.
public synchronized void finishRowLevelDelete(ConnectorSession session, String databaseName, String tableName, Path currentLocation, List<PartitionAndStatementId> partitionAndStatementIds) {
if (partitionAndStatementIds.isEmpty()) {
return;
}
setShared();
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
Action<TableAndMore> oldTableAction = tableActions.get(schemaTableName);
if (oldTableAction == null) {
Table table = getExistingTable(schemaTableName.getSchemaName(), schemaTableName.getTableName());
HdfsContext hdfsContext = new HdfsContext(session);
PrincipalPrivileges principalPrivileges = buildInitialPrivilegeSet(table.getOwner().orElseThrow());
tableActions.put(schemaTableName, new Action<>(ActionType.DELETE_ROWS, new TableAndAcidDirectories(table, Optional.of(principalPrivileges), Optional.of(currentLocation), partitionAndStatementIds), hdfsContext, session.getQueryId()));
return;
}
switch(oldTableAction.getType()) {
case DROP:
throw new TableNotFoundException(schemaTableName);
case ADD:
case ALTER:
case INSERT_EXISTING:
case DELETE_ROWS:
case UPDATE:
throw new UnsupportedOperationException("Inserting or deleting in an unpartitioned table that were added, altered, or inserted into in the same transaction is not supported");
case DROP_PRESERVE_DATA:
// TODO
break;
}
throw new IllegalStateException("Unknown action type");
}
use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class SemiTransactionalHiveMetastore method getTableSource.
/**
* This method can only be called when the table is known to exist
*/
@GuardedBy("this")
private TableSource getTableSource(String databaseName, String tableName) {
checkHoldsLock();
checkReadable();
Action<TableAndMore> tableAction = tableActions.get(new SchemaTableName(databaseName, tableName));
if (tableAction == null) {
return TableSource.PRE_EXISTING_TABLE;
}
switch(tableAction.getType()) {
case ADD:
return TableSource.CREATED_IN_THIS_TRANSACTION;
case DROP:
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
case ALTER:
case INSERT_EXISTING:
case DELETE_ROWS:
case UPDATE:
return TableSource.PRE_EXISTING_TABLE;
case DROP_PRESERVE_DATA:
// TODO
break;
}
throw new IllegalStateException("Unknown action type");
}
use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class SemiTransactionalHiveMetastore method listTablePrivileges.
@Override
public synchronized Set<HivePrivilegeInfo> listTablePrivileges(String databaseName, String tableName, Optional<HivePrincipal> principal) {
checkReadable();
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
Action<TableAndMore> tableAction = tableActions.get(schemaTableName);
if (tableAction == null) {
return delegate.listTablePrivileges(databaseName, tableName, getExistingTable(databaseName, tableName).getOwner(), principal);
}
switch(tableAction.getType()) {
case ADD:
case ALTER:
if (principal.isPresent() && principal.get().getType() == PrincipalType.ROLE) {
return ImmutableSet.of();
}
Optional<String> owner = tableAction.getData().getTable().getOwner();
if (owner.isEmpty()) {
// todo the existing logic below seem off. Only permissions held by the table owner are returned
return ImmutableSet.of();
}
String ownerUsername = owner.orElseThrow();
if (principal.isPresent() && !principal.get().getName().equals(ownerUsername)) {
return ImmutableSet.of();
}
Collection<HivePrivilegeInfo> privileges = tableAction.getData().getPrincipalPrivileges().getUserPrivileges().get(ownerUsername);
return ImmutableSet.<HivePrivilegeInfo>builder().addAll(privileges).add(new HivePrivilegeInfo(OWNERSHIP, true, new HivePrincipal(USER, ownerUsername), new HivePrincipal(USER, ownerUsername))).build();
case INSERT_EXISTING:
case DELETE_ROWS:
case UPDATE:
return delegate.listTablePrivileges(databaseName, tableName, getExistingTable(databaseName, tableName).getOwner(), principal);
case DROP:
throw new TableNotFoundException(schemaTableName);
case DROP_PRESERVE_DATA:
// TODO
break;
}
throw new IllegalStateException("Unknown action type");
}
use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class SemiTransactionalHiveMetastore method dropTable.
public synchronized void dropTable(ConnectorSession session, String databaseName, String tableName) {
setShared();
// Dropping table with partition actions requires cleaning up staging data, which is not implemented yet.
checkNoPartitionAction(databaseName, tableName);
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
Action<TableAndMore> oldTableAction = tableActions.get(schemaTableName);
if (oldTableAction == null || oldTableAction.getType() == ActionType.ALTER) {
HdfsContext hdfsContext = new HdfsContext(session);
tableActions.put(schemaTableName, new Action<>(ActionType.DROP, null, hdfsContext, session.getQueryId()));
return;
}
switch(oldTableAction.getType()) {
case DROP:
throw new TableNotFoundException(schemaTableName);
case ADD:
case ALTER:
case INSERT_EXISTING:
case DELETE_ROWS:
case UPDATE:
throw new UnsupportedOperationException("dropping a table added/modified in the same transaction is not supported");
case DROP_PRESERVE_DATA:
// TODO
break;
}
throw new IllegalStateException("Unknown action type");
}
use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class SemiTransactionalHiveMetastore method finishInsertIntoExistingTable.
public synchronized void finishInsertIntoExistingTable(ConnectorSession session, String databaseName, String tableName, Path currentLocation, List<String> fileNames, PartitionStatistics statisticsUpdate, boolean cleanExtraOutputFilesOnCommit) {
// Data can only be inserted into partitions and unpartitioned tables. They can never be inserted into a partitioned table.
// Therefore, this method assumes that the table is unpartitioned.
setShared();
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
Action<TableAndMore> oldTableAction = tableActions.get(schemaTableName);
if (oldTableAction == null) {
Table table = getExistingTable(schemaTableName.getSchemaName(), schemaTableName.getTableName());
if (isAcidTransactionRunning()) {
table = Table.builder(table).setWriteId(OptionalLong.of(currentHiveTransaction.orElseThrow().getTransaction().getWriteId())).build();
}
PartitionStatistics currentStatistics = getTableStatistics(databaseName, tableName);
HdfsContext hdfsContext = new HdfsContext(session);
tableActions.put(schemaTableName, new Action<>(ActionType.INSERT_EXISTING, new TableAndMore(table, Optional.empty(), Optional.of(currentLocation), Optional.of(fileNames), false, merge(currentStatistics, statisticsUpdate), statisticsUpdate, cleanExtraOutputFilesOnCommit), hdfsContext, session.getQueryId()));
return;
}
switch(oldTableAction.getType()) {
case DROP:
throw new TableNotFoundException(schemaTableName);
case ADD:
case ALTER:
case INSERT_EXISTING:
case DELETE_ROWS:
case UPDATE:
throw new UnsupportedOperationException("Inserting into an unpartitioned table that were added, altered, or inserted into in the same transaction is not supported");
case DROP_PRESERVE_DATA:
// TODO
break;
}
throw new IllegalStateException("Unknown action type");
}
Aggregations