use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class NativeCassandraSession method getTableMetadata.
private static AbstractTableMetadata getTableMetadata(KeyspaceMetadata keyspace, String caseInsensitiveTableName) {
List<AbstractTableMetadata> tables = Stream.concat(keyspace.getTables().stream(), keyspace.getMaterializedViews().stream()).filter(table -> table.getName().equalsIgnoreCase(caseInsensitiveTableName)).collect(toImmutableList());
if (tables.size() == 0) {
throw new TableNotFoundException(new SchemaTableName(keyspace.getName(), caseInsensitiveTableName));
} else if (tables.size() == 1) {
return tables.get(0);
}
String tableNames = tables.stream().map(AbstractTableMetadata::getName).sorted().collect(joining(", "));
throw new PrestoException(NOT_SUPPORTED, format("More than one table has been found for the case insensitive table name: %s -> (%s)", caseInsensitiveTableName, tableNames));
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class ThriftHiveMetastore method getPartitionStatistics.
@Override
public Map<String, PartitionStatistics> getPartitionStatistics(MetastoreContext metastoreContext, String databaseName, String tableName, Set<String> partitionNames) {
Table table = getTable(metastoreContext, databaseName, tableName).orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName)));
List<String> dataColumns = table.getSd().getCols().stream().map(FieldSchema::getName).collect(toImmutableList());
List<String> partitionColumns = table.getPartitionKeys().stream().map(FieldSchema::getName).collect(toImmutableList());
Map<String, HiveBasicStatistics> partitionBasicStatistics = getPartitionsByNames(metastoreContext, databaseName, tableName, ImmutableList.copyOf(partitionNames)).stream().collect(toImmutableMap(partition -> makePartName(partitionColumns, partition.getValues()), partition -> getHiveBasicStatistics(partition.getParameters())));
Map<String, OptionalLong> partitionRowCounts = partitionBasicStatistics.entrySet().stream().collect(toImmutableMap(Map.Entry::getKey, entry -> entry.getValue().getRowCount()));
Map<String, Map<String, HiveColumnStatistics>> partitionColumnStatistics = getPartitionColumnStatistics(metastoreContext, databaseName, tableName, partitionNames, dataColumns, partitionRowCounts);
ImmutableMap.Builder<String, PartitionStatistics> result = ImmutableMap.builder();
for (String partitionName : partitionNames) {
HiveBasicStatistics basicStatistics = partitionBasicStatistics.getOrDefault(partitionName, createEmptyStatistics());
Map<String, HiveColumnStatistics> columnStatistics = partitionColumnStatistics.getOrDefault(partitionName, ImmutableMap.of());
result.put(partitionName, new PartitionStatistics(basicStatistics, columnStatistics));
}
return result.build();
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class GlueHiveMetastore method updateTableStatistics.
@Override
public void updateTableStatistics(MetastoreContext metastoreContext, String databaseName, String tableName, Function<PartitionStatistics, PartitionStatistics> update) {
PartitionStatistics currentStatistics = getTableStatistics(metastoreContext, databaseName, tableName);
PartitionStatistics updatedStatistics = update.apply(currentStatistics);
if (!updatedStatistics.getColumnStatistics().isEmpty()) {
throw new PrestoException(NOT_SUPPORTED, "Glue metastore does not support column level statistics");
}
Table table = getTableOrElseThrow(metastoreContext, databaseName, tableName);
try {
TableInput tableInput = GlueInputConverter.convertTable(table);
tableInput.setParameters(updateStatisticsParameters(table.getParameters(), updatedStatistics.getBasicStatistics()));
UpdateTableRequest request = new UpdateTableRequest().withCatalogId(catalogId).withDatabaseName(databaseName).withTableInput(tableInput);
stats.getUpdateTable().record(() -> glueClient.updateTable(request));
} catch (EntityNotFoundException e) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
} catch (AmazonServiceException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class BridgingHiveMetastore method addColumn.
@Override
public void addColumn(MetastoreContext metastoreContext, String databaseName, String tableName, String columnName, HiveType columnType, String columnComment) {
Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(metastoreContext, databaseName, tableName);
if (!source.isPresent()) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
}
org.apache.hadoop.hive.metastore.api.Table table = source.get();
Column column = new Column(columnName, columnType, Optional.ofNullable(columnComment), Optional.empty());
table.getSd().getCols().add(metastoreContext.getColumnConverter().fromColumn(column));
alterTable(metastoreContext, databaseName, tableName, table);
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class BridgingHiveMetastore method renameTable.
@Override
public void renameTable(MetastoreContext metastoreContext, String databaseName, String tableName, String newDatabaseName, String newTableName) {
Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(metastoreContext, databaseName, tableName);
if (!source.isPresent()) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
}
org.apache.hadoop.hive.metastore.api.Table table = source.get();
table.setDbName(newDatabaseName);
table.setTableName(newTableName);
alterTable(metastoreContext, databaseName, tableName, table);
}
Aggregations