Search in sources :

Example 71 with TableNotFoundException

use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.

the class InMemoryHiveMetastore method dropTable.

@Override
public synchronized void dropTable(MetastoreContext metastoreContext, String databaseName, String tableName, boolean deleteData) {
    List<String> locations = listAllDataPaths(metastoreContext, this, databaseName, tableName);
    SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
    Table table = relations.remove(schemaTableName);
    if (table == null) {
        throw new TableNotFoundException(schemaTableName);
    }
    views.remove(schemaTableName);
    partitions.keySet().removeIf(partitionName -> partitionName.matches(databaseName, tableName));
    // remove data
    if (deleteData && table.getTableType().equals(MANAGED_TABLE.name())) {
        for (String location : locations) {
            if (location != null) {
                File directory = new File(new Path(location).toUri());
                checkArgument(isParentDir(directory, baseDirectory), "Table directory must be inside of the metastore base directory");
                deleteDirectory(directory);
            }
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Table(org.apache.hadoop.hive.metastore.api.Table) SchemaTableName(com.facebook.presto.spi.SchemaTableName) File(java.io.File)

Example 72 with TableNotFoundException

use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.

the class IcebergAbstractMetadata method listTableColumns.

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    List<SchemaTableName> tables = prefix.getTableName() != null ? singletonList(prefix.toSchemaTableName()) : listTables(session, Optional.of(prefix.getSchemaName()));
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
    for (SchemaTableName table : tables) {
        try {
            columns.put(table, getTableMetadata(session, table).getColumns());
        } catch (TableNotFoundException e) {
            log.warn(String.format("table disappeared during listing operation: %s", e.getMessage()));
        } catch (UnknownTableTypeException e) {
            log.warn(String.format("%s: Unknown table type of table %s", e.getMessage(), table.getTableName()));
        }
    }
    return columns.build();
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Collections.singletonList(java.util.Collections.singletonList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 73 with TableNotFoundException

use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.

the class IcebergHiveMetadata method getTableMetadata.

@Override
protected ConnectorTableMetadata getTableMetadata(ConnectorSession session, SchemaTableName table) {
    MetastoreContext metastoreContext = new MetastoreContext(session.getIdentity(), session.getQueryId(), session.getClientInfo(), session.getSource(), Optional.empty(), false, HiveColumnConverterProvider.DEFAULT_COLUMN_CONVERTER_PROVIDER);
    if (!metastore.getTable(metastoreContext, table.getSchemaName(), table.getTableName()).isPresent()) {
        throw new TableNotFoundException(table);
    }
    org.apache.iceberg.Table icebergTable = getHiveIcebergTable(metastore, hdfsEnvironment, session, table);
    List<ColumnMetadata> columns = getColumnMetadatas(icebergTable);
    return new ConnectorTableMetadata(table, columns, createMetadataProperties(icebergTable), getTableComment(icebergTable));
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 74 with TableNotFoundException

use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.

the class FileHiveMetastore method updateTableStatistics.

@Override
public synchronized void updateTableStatistics(MetastoreContext metastoreContext, String databaseName, String tableName, Function<PartitionStatistics, PartitionStatistics> update) {
    PartitionStatistics originalStatistics = getTableStatistics(metastoreContext, 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)));
    TableMetadata updatedMetadata = tableMetadata.withParameters(updateStatisticsParameters(tableMetadata.getParameters(), updatedStatistics.getBasicStatistics())).withColumnStatistics(updatedStatistics.getColumnStatistics());
    writeSchemaFile("table", tableMetadataDirectory, tableCodec, updatedMetadata, true);
}
Also used : Path(org.apache.hadoop.fs.Path) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) PartitionStatistics(com.facebook.presto.hive.metastore.PartitionStatistics) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 75 with TableNotFoundException

use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.

the class FileHiveMetastore method getTableStatistics.

@Override
public synchronized PartitionStatistics getTableStatistics(MetastoreContext metastoreContext, String databaseName, String tableName) {
    Path tableMetadataDirectory = getTableMetadataDirectory(databaseName, tableName);
    TableMetadata tableMetadata = readSchemaFile("table", tableMetadataDirectory, tableCodec).orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName)));
    HiveBasicStatistics basicStatistics = getHiveBasicStatistics(tableMetadata.getParameters());
    Map<String, HiveColumnStatistics> columnStatistics = tableMetadata.getColumnStatistics();
    return new PartitionStatistics(basicStatistics, columnStatistics);
}
Also used : Path(org.apache.hadoop.fs.Path) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) PartitionStatistics(com.facebook.presto.hive.metastore.PartitionStatistics) HiveColumnStatistics(com.facebook.presto.hive.metastore.HiveColumnStatistics) MetastoreUtil.getHiveBasicStatistics(com.facebook.presto.hive.metastore.MetastoreUtil.getHiveBasicStatistics) HiveBasicStatistics(com.facebook.presto.hive.HiveBasicStatistics) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Aggregations

TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)95 SchemaTableName (com.facebook.presto.spi.SchemaTableName)68 PrestoException (com.facebook.presto.spi.PrestoException)38 Table (com.facebook.presto.hive.metastore.Table)36 ImmutableMap (com.google.common.collect.ImmutableMap)33 MetastoreContext (com.facebook.presto.hive.metastore.MetastoreContext)28 ImmutableList (com.google.common.collect.ImmutableList)28 List (java.util.List)24 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)23 ColumnHandle (com.facebook.presto.spi.ColumnHandle)22 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)20 Constraint (com.facebook.presto.spi.Constraint)20 Map (java.util.Map)20 Set (java.util.Set)20 Optional (java.util.Optional)19 Column (com.facebook.presto.hive.metastore.Column)18 PartitionStatistics (com.facebook.presto.hive.metastore.PartitionStatistics)18 HashSet (java.util.HashSet)18 SystemTable (com.facebook.presto.spi.SystemTable)17 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)17