This is an automated email from the ASF dual-hosted git repository.
amoghj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/main by this push:
new 2058053b0c AWS: Retain Glue Catalog table description after updating
Iceberg table (#10199)
2058053b0c is described below
commit 2058053b0c6e5b1c7e91fa029162f22d109aafb1
Author: Akira Ajisaka <[email protected]>
AuthorDate: Wed May 15 09:08:47 2024 +0900
AWS: Retain Glue Catalog table description after updating Iceberg table
(#10199)
---
.../org/apache/iceberg/aws/glue/GlueTestBase.java | 29 ++++++++++++++++++++++
.../iceberg/aws/glue/TestGlueCatalogTable.java | 13 ++++++++++
.../iceberg/aws/glue/GlueTableOperations.java | 3 +++
3 files changed, 45 insertions(+)
diff --git
a/aws/src/integration/java/org/apache/iceberg/aws/glue/GlueTestBase.java
b/aws/src/integration/java/org/apache/iceberg/aws/glue/GlueTestBase.java
index 2a810f0650..ed3a235eb0 100644
--- a/aws/src/integration/java/org/apache/iceberg/aws/glue/GlueTestBase.java
+++ b/aws/src/integration/java/org/apache/iceberg/aws/glue/GlueTestBase.java
@@ -39,6 +39,11 @@ import org.junit.jupiter.api.BeforeAll;
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"})
@@ -129,4 +134,28 @@ public class GlueTestBase {
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);
+ }
}
diff --git
a/aws/src/integration/java/org/apache/iceberg/aws/glue/TestGlueCatalogTable.java
b/aws/src/integration/java/org/apache/iceberg/aws/glue/TestGlueCatalogTable.java
index f6bdd89707..6dffdb5b92 100644
---
a/aws/src/integration/java/org/apache/iceberg/aws/glue/TestGlueCatalogTable.java
+++
b/aws/src/integration/java/org/apache/iceberg/aws/glue/TestGlueCatalogTable.java
@@ -182,6 +182,8 @@ public class TestGlueCatalogTable extends GlueTestBase {
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);
@@ -206,6 +208,17 @@ public class TestGlueCatalogTable extends GlueTestBase {
.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
diff --git
a/aws/src/main/java/org/apache/iceberg/aws/glue/GlueTableOperations.java
b/aws/src/main/java/org/apache/iceberg/aws/glue/GlueTableOperations.java
index 6e53e707aa..aedf785234 100644
--- a/aws/src/main/java/org/apache/iceberg/aws/glue/GlueTableOperations.java
+++ b/aws/src/main/java/org/apache/iceberg/aws/glue/GlueTableOperations.java
@@ -316,6 +316,9 @@ class GlueTableOperations extends
BaseMetastoreTableOperations {
.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))