Skip to content

Commit

Permalink
AWS: Retain Glue Catalog table description after updating Iceberg tab…
Browse files Browse the repository at this point in the history
…le (apache#10199)
  • Loading branch information
aajisaka authored May 15, 2024
1 parent a6fb9cd commit 2058053
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.services.glue.GlueClient;
import software.amazon.awssdk.services.glue.model.GetTableRequest;
import software.amazon.awssdk.services.glue.model.GetTableResponse;
import software.amazon.awssdk.services.glue.model.Table;
import software.amazon.awssdk.services.glue.model.TableInput;
import software.amazon.awssdk.services.glue.model.UpdateTableRequest;
import software.amazon.awssdk.services.s3.S3Client;

@SuppressWarnings({"VisibilityModifier", "HideUtilityClassConstructor"})
Expand Down Expand Up @@ -129,4 +134,28 @@ public static String createTable(String namespace, String tableName) {
glueCatalog.createTable(TableIdentifier.of(namespace, tableName), schema, partitionSpec);
return tableName;
}

// Directly call Glue API to update table description
public static void updateTableDescription(
String namespace, String tableName, String description) {
GetTableResponse response =
glue.getTable(GetTableRequest.builder().databaseName(namespace).name(tableName).build());
Table table = response.table();
UpdateTableRequest request =
UpdateTableRequest.builder()
.catalogId(table.catalogId())
.databaseName(table.databaseName())
.tableInput(
TableInput.builder()
.description(description)
.name(table.name())
.partitionKeys(table.partitionKeys())
.tableType(table.tableType())
.owner(table.owner())
.parameters(table.parameters())
.storageDescriptor(table.storageDescriptor())
.build())
.build();
glue.updateTable(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ public void testUpdateTable() {
assertThat(current).isNull();
// create table, refresh should update
createTable(namespace, tableName);
String description = "test description";
updateTableDescription(namespace, tableName, description);
current = ops.refresh();
assertThat(current.schema()).asString().isEqualTo(schema.toString());
assertThat(current.spec()).isEqualTo(partitionSpec);
Expand All @@ -206,6 +208,17 @@ public void testUpdateTable() {
.isEqualTo("EXTERNAL_TABLE");
assertThat(response.table().storageDescriptor().columns()).hasSameSizeAs(schema.columns());
assertThat(response.table().partitionKeys()).hasSameSizeAs(partitionSpec.fields());
assertThat(response.table().description()).isEqualTo(description);

String updatedComment = "test updated comment";
table
.updateProperties()
.set(IcebergToGlueConverter.GLUE_DESCRIPTION_KEY, updatedComment)
.commit();
// check table in Glue
response =
glue.getTable(GetTableRequest.builder().databaseName(namespace).name(tableName).build());
assertThat(response.table().description()).isEqualTo(updatedComment);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ void persistGlueTable(
.skipArchive(awsProperties.glueCatalogSkipArchive())
.tableInput(
TableInput.builder()
// Call description before applyMutation so that applyMutation overwrites the
// description with the comment specified in the query
.description(glueTable.description())
.applyMutation(
builder ->
IcebergToGlueConverter.setTableInputInformation(builder, metadata))
Expand Down

0 comments on commit 2058053

Please sign in to comment.