use of com.amazonaws.services.glue.model.EntityNotFoundException in project presto by prestodb.
the class GlueHiveMetastore method createTable.
@Override
public void createTable(MetastoreContext metastoreContext, Table table, PrincipalPrivileges principalPrivileges) {
try {
TableInput input = GlueInputConverter.convertTable(table);
stats.getCreateTable().record(() -> glueClient.createTable(new CreateTableRequest().withCatalogId(catalogId).withDatabaseName(table.getDatabaseName()).withTableInput(input)));
} catch (AlreadyExistsException e) {
throw new TableAlreadyExistsException(new SchemaTableName(table.getDatabaseName(), table.getTableName()));
} catch (EntityNotFoundException e) {
throw new SchemaNotFoundException(table.getDatabaseName());
} catch (AmazonServiceException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
}
use of com.amazonaws.services.glue.model.EntityNotFoundException in project presto by prestodb.
the class GlueHiveMetastore method replaceTable.
@Override
public void replaceTable(MetastoreContext metastoreContext, String databaseName, String tableName, Table newTable, PrincipalPrivileges principalPrivileges) {
try {
TableInput newTableInput = GlueInputConverter.convertTable(newTable);
stats.getUpdateTable().record(() -> 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 PrestoException(HIVE_METASTORE_ERROR, e);
}
}
use of com.amazonaws.services.glue.model.EntityNotFoundException in project presto by prestodb.
the class GlueHiveMetastore method getAllTables.
@Override
public Optional<List<String>> getAllTables(MetastoreContext metastoreContext, String databaseName) {
try {
List<String> tableNames = new ArrayList<>();
GetTablesRequest request = new GetTablesRequest().withCatalogId(catalogId).withDatabaseName(databaseName);
do {
GetTablesResult result = stats.getGetTables().record(() -> glueClient.getTables(request));
request.setNextToken(result.getNextToken());
result.getTableList().forEach(table -> tableNames.add(table.getName()));
} while (request.getNextToken() != null);
return Optional.of(tableNames);
} catch (EntityNotFoundException e) {
// database does not exist
return Optional.empty();
} catch (AmazonServiceException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
}
use of com.amazonaws.services.glue.model.EntityNotFoundException in project presto by prestodb.
the class GlueHiveMetastore method updatePartitionStatistics.
@Override
public void updatePartitionStatistics(MetastoreContext metastoreContext, String databaseName, String tableName, String partitionName, Function<PartitionStatistics, PartitionStatistics> update) {
PartitionStatistics currentStatistics = getPartitionStatistics(metastoreContext, databaseName, tableName, ImmutableSet.of(partitionName)).get(partitionName);
if (currentStatistics == null) {
throw new PrestoException(HIVE_PARTITION_DROPPED_DURING_QUERY, "Statistics result does not contain entry for partition: " + partitionName);
}
PartitionStatistics updatedStatistics = update.apply(currentStatistics);
if (!updatedStatistics.getColumnStatistics().isEmpty()) {
throw new PrestoException(NOT_SUPPORTED, "Glue metastore does not support column level statistics");
}
List<String> partitionValues = toPartitionValues(partitionName);
Partition partition = getPartition(metastoreContext, databaseName, tableName, partitionValues).orElseThrow(() -> new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partitionValues));
try {
PartitionInput partitionInput = GlueInputConverter.convertPartition(partition);
partitionInput.setParameters(updateStatisticsParameters(partition.getParameters(), updatedStatistics.getBasicStatistics()));
stats.getUpdatePartition().record(() -> glueClient.updatePartition(new UpdatePartitionRequest().withCatalogId(catalogId).withDatabaseName(databaseName).withTableName(tableName).withPartitionValueList(partition.getValues()).withPartitionInput(partitionInput)));
} catch (EntityNotFoundException e) {
throw new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partitionValues);
} catch (AmazonServiceException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
}
use of com.amazonaws.services.glue.model.EntityNotFoundException in project presto by prestodb.
the class GlueHiveMetastore method getAllViews.
@Override
public Optional<List<String>> getAllViews(MetastoreContext metastoreContext, String databaseName) {
try {
List<String> views = new ArrayList<>();
GetTablesRequest request = new GetTablesRequest().withCatalogId(catalogId).withDatabaseName(databaseName);
do {
GetTablesResult result = stats.getGetTables().record(() -> glueClient.getTables(request));
request.setNextToken(result.getNextToken());
result.getTableList().stream().filter(table -> VIRTUAL_VIEW.name().equals(table.getTableType())).forEach(table -> views.add(table.getName()));
} while (request.getNextToken() != null);
return Optional.of(views);
} catch (EntityNotFoundException e) {
// database does not exist
return Optional.empty();
} catch (AmazonServiceException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
}
Aggregations