Search in sources :

Example 71 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.

the class GlueHiveMetastore method setTableOwner.

@Override
public void setTableOwner(String databaseName, String tableName, HivePrincipal principal) {
    // TODO Add role support https://github.com/trinodb/trino/issues/5706
    if (principal.getType() != USER) {
        throw new TrinoException(NOT_SUPPORTED, "Setting table owner type as a role is not supported");
    }
    try {
        Table table = getExistingTable(databaseName, tableName);
        TableInput newTableInput = GlueInputConverter.convertTable(table);
        newTableInput.setOwner(principal.getName());
        stats.getUpdateTable().call(() -> glueClient.updateTable(new UpdateTableRequest().withCatalogId(catalogId).withDatabaseName(databaseName).withTableInput(newTableInput)));
    } catch (EntityNotFoundException e) {
        throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
    } catch (AmazonServiceException e) {
        throw new TrinoException(HIVE_METASTORE_ERROR, e);
    }
}
Also used : TableInput(com.amazonaws.services.glue.model.TableInput) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Table(io.trino.plugin.hive.metastore.Table) UpdateTableRequest(com.amazonaws.services.glue.model.UpdateTableRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) TrinoException(io.trino.spi.TrinoException) EntityNotFoundException(com.amazonaws.services.glue.model.EntityNotFoundException) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 72 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.

the class FileHiveMetastore method alterTable.

private void alterTable(String databaseName, String tableName, Function<TableMetadata, TableMetadata> alterFunction) {
    requireNonNull(databaseName, "databaseName is null");
    requireNonNull(tableName, "tableName is null");
    Path tableMetadataDirectory = getTableMetadataDirectory(databaseName, tableName);
    TableMetadata oldTableSchema = readSchemaFile(TABLE, tableMetadataDirectory, tableCodec).orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName)));
    checkVersion(oldTableSchema.getWriterVersion());
    TableMetadata newTableSchema = alterFunction.apply(oldTableSchema);
    if (oldTableSchema == newTableSchema) {
        return;
    }
    writeSchemaFile(TABLE, tableMetadataDirectory, tableCodec, newTableSchema, true);
}
Also used : Path(org.apache.hadoop.fs.Path) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 73 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.

the class FileHiveMetastore method updateTableStatistics.

@Override
public synchronized void updateTableStatistics(String databaseName, String tableName, AcidTransaction transaction, Function<PartitionStatistics, PartitionStatistics> update) {
    PartitionStatistics originalStatistics = getTableStatistics(databaseName, tableName);
    PartitionStatistics updatedStatistics = update.apply(originalStatistics);
    Path tableMetadataDirectory = getTableMetadataDirectory(databaseName, tableName);
    TableMetadata tableMetadata = readSchemaFile(TABLE, tableMetadataDirectory, tableCodec).orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName)));
    checkVersion(tableMetadata.getWriterVersion());
    TableMetadata updatedMetadata = tableMetadata.withParameters(currentVersion, updateStatisticsParameters(tableMetadata.getParameters(), updatedStatistics.getBasicStatistics())).withColumnStatistics(currentVersion, updatedStatistics.getColumnStatistics());
    writeSchemaFile(TABLE, tableMetadataDirectory, tableCodec, updatedMetadata, true);
}
Also used : Path(org.apache.hadoop.fs.Path) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 74 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.

the class AbstractMetastoreTableOperations method getRefreshedLocation.

@Override
protected final String getRefreshedLocation() {
    Table table = getTable();
    if (isPrestoView(table) && isHiveOrPrestoView(table)) {
        // this is a Hive view, hence not a table
        throw new TableNotFoundException(getSchemaTableName());
    }
    if (!isIcebergTable(table)) {
        throw new UnknownTableTypeException(getSchemaTableName());
    }
    String metadataLocation = table.getParameters().get(METADATA_LOCATION_PROP);
    if (metadataLocation == null) {
        throw new TrinoException(ICEBERG_INVALID_METADATA, format("Table is missing [%s] property: %s", METADATA_LOCATION_PROP, getSchemaTableName()));
    }
    return metadataLocation;
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) IcebergUtil.isIcebergTable(io.trino.plugin.iceberg.IcebergUtil.isIcebergTable) Table(io.trino.plugin.hive.metastore.Table) TrinoException(io.trino.spi.TrinoException) UnknownTableTypeException(io.trino.plugin.iceberg.UnknownTableTypeException)

Example 75 with TableNotFoundException

use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.

the class HiveMetastoreTableOperations method commitToExistingTable.

@Override
protected void commitToExistingTable(TableMetadata base, TableMetadata metadata) {
    String newMetadataLocation = writeNewMetadata(metadata, version + 1);
    HiveIdentity identity = new HiveIdentity(session.getIdentity());
    long lockId = thriftMetastore.acquireTableExclusiveLock(identity, new AcidTransactionOwner(session.getUser()), session.getQueryId(), database, tableName);
    try {
        Table table;
        try {
            Table currentTable = fromMetastoreApiTable(thriftMetastore.getTable(identity, database, tableName).orElseThrow(() -> new TableNotFoundException(getSchemaTableName())));
            checkState(currentMetadataLocation != null, "No current metadata location for existing table");
            String metadataLocation = currentTable.getParameters().get(METADATA_LOCATION_PROP);
            if (!currentMetadataLocation.equals(metadataLocation)) {
                throw new CommitFailedException("Metadata location [%s] is not same as table metadata location [%s] for %s", currentMetadataLocation, metadataLocation, getSchemaTableName());
            }
            table = Table.builder(currentTable).setDataColumns(toHiveColumns(metadata.schema().columns())).withStorage(storage -> storage.setLocation(metadata.location())).setParameter(METADATA_LOCATION_PROP, newMetadataLocation).setParameter(PREVIOUS_METADATA_LOCATION_PROP, currentMetadataLocation).build();
        } catch (RuntimeException e) {
            try {
                io().deleteFile(newMetadataLocation);
            } catch (RuntimeException ex) {
                e.addSuppressed(ex);
            }
            throw new TrinoException(ICEBERG_COMMIT_ERROR, format("Failed to commit to table %s.%s", database, tableName), e);
        }
        // todo privileges should not be replaced for an alter
        PrincipalPrivileges privileges = table.getOwner().map(MetastoreUtil::buildInitialPrivilegeSet).orElse(NO_PRIVILEGES);
        metastore.replaceTable(database, tableName, table, privileges);
    } finally {
        thriftMetastore.releaseTableLock(identity, lockId);
    }
    shouldRefresh = true;
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Table(io.trino.plugin.hive.metastore.Table) ThriftMetastoreUtil.fromMetastoreApiTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromMetastoreApiTable) PrincipalPrivileges(io.trino.plugin.hive.metastore.PrincipalPrivileges) AcidTransactionOwner(io.trino.plugin.hive.metastore.AcidTransactionOwner) TrinoException(io.trino.spi.TrinoException) CommitFailedException(org.apache.iceberg.exceptions.CommitFailedException) HiveIdentity(io.trino.plugin.hive.authentication.HiveIdentity)

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