Search in sources :

Example 66 with TableNotFoundException

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");
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) HdfsContext(io.trino.plugin.hive.HdfsEnvironment.HdfsContext) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 67 with TableNotFoundException

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");
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) SchemaTableName(io.trino.spi.connector.SchemaTableName) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 68 with TableNotFoundException

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");
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 69 with TableNotFoundException

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");
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) HdfsContext(io.trino.plugin.hive.HdfsEnvironment.HdfsContext) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 70 with TableNotFoundException

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");
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) HdfsContext(io.trino.plugin.hive.HdfsEnvironment.HdfsContext) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Aggregations

TableNotFoundException (io.trino.spi.connector.TableNotFoundException)84 SchemaTableName (io.trino.spi.connector.SchemaTableName)65 TrinoException (io.trino.spi.TrinoException)39 Table (io.trino.plugin.hive.metastore.Table)33 ImmutableMap (com.google.common.collect.ImmutableMap)27 ImmutableList (com.google.common.collect.ImmutableList)26 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)26 List (java.util.List)25 Optional (java.util.Optional)24 HdfsContext (io.trino.plugin.hive.HdfsEnvironment.HdfsContext)22 Path (org.apache.hadoop.fs.Path)22 ColumnHandle (io.trino.spi.connector.ColumnHandle)21 Map (java.util.Map)21 Objects.requireNonNull (java.util.Objects.requireNonNull)20 ConnectorSession (io.trino.spi.connector.ConnectorSession)19 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)18 TupleDomain (io.trino.spi.predicate.TupleDomain)18 Set (java.util.Set)18 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)17 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)17