use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class GlueHiveMetastore method dropColumn.
@Override
public void dropColumn(String databaseName, String tableName, String columnName) {
verifyCanDropColumn(this, databaseName, tableName, columnName);
Table oldTable = getExistingTable(databaseName, tableName);
if (oldTable.getColumn(columnName).isEmpty()) {
SchemaTableName name = new SchemaTableName(databaseName, tableName);
throw new ColumnNotFoundException(name, columnName);
}
ImmutableList.Builder<Column> newDataColumns = ImmutableList.builder();
oldTable.getDataColumns().stream().filter(fieldSchema -> !fieldSchema.getName().equals(columnName)).forEach(newDataColumns::add);
Table newTable = Table.builder(oldTable).setDataColumns(newDataColumns.build()).build();
replaceTable(databaseName, tableName, newTable, null);
}
use of io.trino.spi.connector.SchemaTableName 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());
}
}
}
use of io.trino.spi.connector.SchemaTableName 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);
}
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class GlueHiveMetastore method createTable.
@Override
public void createTable(Table table, PrincipalPrivileges principalPrivileges) {
try {
TableInput input = GlueInputConverter.convertTable(table);
stats.getCreateTable().call(() -> 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 TrinoException(HIVE_METASTORE_ERROR, e);
}
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class GlueHiveMetastore method updateTableStatistics.
@Override
public void updateTableStatistics(String databaseName, String tableName, AcidTransaction transaction, Function<PartitionStatistics, PartitionStatistics> update) {
Table table = getExistingTable(databaseName, tableName);
if (transaction.isAcidTransactionRunning()) {
table = Table.builder(table).setWriteId(OptionalLong.of(transaction.getWriteId())).build();
}
PartitionStatistics currentStatistics = getTableStatistics(table);
PartitionStatistics updatedStatistics = update.apply(currentStatistics);
try {
TableInput tableInput = GlueInputConverter.convertTable(table);
final Map<String, String> statisticsParameters = updateStatisticsParameters(table.getParameters(), updatedStatistics.getBasicStatistics());
tableInput.setParameters(statisticsParameters);
table = Table.builder(table).setParameters(statisticsParameters).build();
stats.getUpdateTable().call(() -> glueClient.updateTable(new UpdateTableRequest().withCatalogId(catalogId).withDatabaseName(databaseName).withTableInput(tableInput)));
columnStatisticsProvider.updateTableColumnStatistics(table, updatedStatistics.getColumnStatistics());
} catch (EntityNotFoundException e) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
} catch (AmazonServiceException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
}
}
Aggregations