Search in sources :

Example 11 with TableNotFoundException

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

the class PropertiesSystemTableProvider method getSystemTable.

@Override
public Optional<SystemTable> getSystemTable(HiveMetadata metadata, ConnectorSession session, SchemaTableName tableName) {
    if (!PROPERTIES.matches(tableName)) {
        return Optional.empty();
    }
    SchemaTableName sourceTableName = PROPERTIES.getSourceTableName(tableName);
    Table table = metadata.getMetastore().getTable(sourceTableName.getSchemaName(), sourceTableName.getTableName()).orElseThrow(() -> new TableNotFoundException(tableName));
    if (isDeltaLakeTable(table) || isIcebergTable(table)) {
        return Optional.empty();
    }
    Map<String, String> sortedTableParameters = ImmutableSortedMap.copyOf(table.getParameters());
    List<ColumnMetadata> columns = sortedTableParameters.keySet().stream().map(key -> new ColumnMetadata(key, VarcharType.VARCHAR)).collect(toImmutableList());
    List<Type> types = columns.stream().map(ColumnMetadata::getType).collect(toImmutableList());
    Iterable<List<Object>> propertyValues = ImmutableList.of(ImmutableList.copyOf(sortedTableParameters.values()));
    return Optional.of(createSystemTable(new ConnectorTableMetadata(sourceTableName, columns), constraint -> new InMemoryRecordSet(types, propertyValues).cursor()));
}
Also used : HiveUtil.isIcebergTable(io.trino.plugin.hive.util.HiveUtil.isIcebergTable) Table(io.trino.plugin.hive.metastore.Table) PROPERTIES(io.trino.plugin.hive.SystemTableHandler.PROPERTIES) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) HiveUtil.isDeltaLakeTable(io.trino.plugin.hive.util.HiveUtil.isDeltaLakeTable) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Type(io.trino.spi.type.Type) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) ConnectorSession(io.trino.spi.connector.ConnectorSession) InMemoryRecordSet(io.trino.spi.connector.InMemoryRecordSet) SchemaTableName(io.trino.spi.connector.SchemaTableName) VarcharType(io.trino.spi.type.VarcharType) List(java.util.List) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Optional(java.util.Optional) SystemTables.createSystemTable(io.trino.plugin.hive.util.SystemTables.createSystemTable) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) SystemTable(io.trino.spi.connector.SystemTable) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) HiveUtil.isIcebergTable(io.trino.plugin.hive.util.HiveUtil.isIcebergTable) Table(io.trino.plugin.hive.metastore.Table) HiveUtil.isDeltaLakeTable(io.trino.plugin.hive.util.HiveUtil.isDeltaLakeTable) SystemTables.createSystemTable(io.trino.plugin.hive.util.SystemTables.createSystemTable) SystemTable(io.trino.spi.connector.SystemTable) SchemaTableName(io.trino.spi.connector.SchemaTableName) InMemoryRecordSet(io.trino.spi.connector.InMemoryRecordSet) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Type(io.trino.spi.type.Type) VarcharType(io.trino.spi.type.VarcharType) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata)

Example 12 with TableNotFoundException

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

the class SemiTransactionalHiveMetastore method finishUpdate.

public synchronized void finishUpdate(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.UPDATE, 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, updating or deleting in a table that was added, altered, inserted into, updated or deleted from 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 13 with TableNotFoundException

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

the class SemiTransactionalHiveMetastore method truncateUnpartitionedTable.

public synchronized void truncateUnpartitionedTable(ConnectorSession session, String databaseName, String tableName) {
    checkReadable();
    Optional<Table> table = getTable(databaseName, tableName);
    SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
    if (table.isEmpty()) {
        throw new TableNotFoundException(schemaTableName);
    }
    if (!table.get().getTableType().equals(MANAGED_TABLE.toString())) {
        throw new TrinoException(NOT_SUPPORTED, "Cannot delete from non-managed Hive table");
    }
    if (!table.get().getPartitionColumns().isEmpty()) {
        throw new IllegalArgumentException("Table is partitioned");
    }
    Path path = new Path(table.get().getStorage().getLocation());
    HdfsContext context = new HdfsContext(session);
    setExclusive((delegate, hdfsEnvironment) -> {
        RecursiveDeleteResult recursiveDeleteResult = recursiveDeleteFiles(hdfsEnvironment, context, path, ImmutableSet.of(""), false);
        if (!recursiveDeleteResult.getNotDeletedEligibleItems().isEmpty()) {
            throw new TrinoException(HIVE_FILESYSTEM_ERROR, format("Error deleting from unpartitioned table %s. These items cannot be deleted: %s", schemaTableName, recursiveDeleteResult.getNotDeletedEligibleItems()));
        }
    });
}
Also used : Path(org.apache.hadoop.fs.Path) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) TrinoException(io.trino.spi.TrinoException) HdfsContext(io.trino.plugin.hive.HdfsEnvironment.HdfsContext) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 14 with TableNotFoundException

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

the class GlueHiveMetastore method propagatePartitionErrorToTrinoException.

private static void propagatePartitionErrorToTrinoException(String databaseName, String tableName, List<PartitionError> partitionErrors) {
    if (partitionErrors != null && !partitionErrors.isEmpty()) {
        ErrorDetail errorDetail = partitionErrors.get(0).getErrorDetail();
        String glueExceptionCode = errorDetail.getErrorCode();
        switch(glueExceptionCode) {
            case "AlreadyExistsException":
                throw new TrinoException(ALREADY_EXISTS, errorDetail.getErrorMessage());
            case "EntityNotFoundException":
                throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), errorDetail.getErrorMessage());
            default:
                throw new TrinoException(HIVE_METASTORE_ERROR, errorDetail.getErrorCode() + ": " + errorDetail.getErrorMessage());
        }
    }
}
Also used : ErrorDetail(com.amazonaws.services.glue.model.ErrorDetail) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) TrinoException(io.trino.spi.TrinoException) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 15 with TableNotFoundException

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

the class GlueHiveMetastore method replaceTable.

@Override
public void replaceTable(String databaseName, String tableName, Table newTable, PrincipalPrivileges principalPrivileges) {
    try {
        TableInput newTableInput = GlueInputConverter.convertTable(newTable);
        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) 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)

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