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);
}
}
}
}
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();
}
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));
}
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);
}
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);
}
Aggregations