Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#9666]fix(iceberg): Fix Iceberg migrate procedure by preserving stageCreate flag (#9667)

Bharath Krishnac3da4604783b
diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableOperationExecutor.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableOperationExecutor.java
index ad0ee7f077..8319a200aa 100644
--- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableOperationExecutor.java
+++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableOperationExecutor.java
@@ -72,15 +72,21 @@ public class IcebergTableOperationExecutor implements IcebergTableOperationDispa
authenticatedUser);
// CreateTableRequest is immutable, so we need to rebuild it with modified properties
- createTableRequest =
+ CreateTableRequest.Builder builder =
CreateTableRequest.builder()
.withName(createTableRequest.name())
.withSchema(createTableRequest.schema())
.withPartitionSpec(createTableRequest.spec())
.withWriteOrder(createTableRequest.writeOrder())
.withLocation(createTableRequest.location())
- .setProperties(properties)
- .build();
+ .setProperties(properties);
+
+ // Preserve the stageCreate flag when rebuilding the request
+ if (createTableRequest.stageCreate()) {
+ builder.stageCreate();
+ }
+
+ createTableRequest = builder.build();
}
}
diff --git a/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/dispatcher/TestIcebergTableOperationExecutor.java b/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/dispatcher/TestIcebergTableOperationExecutor.java
index 47c2ffb4d2..65e271731d 100644
--- a/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/dispatcher/TestIcebergTableOperationExecutor.java
+++ b/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/dispatcher/TestIcebergTableOperationExecutor.java
@@ -144,4 +144,48 @@ public class TestIcebergTableOperationExecutor {
String actualOwner = requestCaptor.getValue().properties().get(IcebergConstants.OWNER);
Assertions.assertEquals(clientProvidedOwner, actualOwner);
}
+
+ @Test
+ public void testCreateTablePreservesStageCreateTrue() {
+ when(mockContext.userName()).thenReturn("[email protected]");
+ LoadTableResponse mockResponse = mock(LoadTableResponse.class);
+ when(mockCatalogWrapper.createTable(any(), any(), anyBoolean())).thenReturn(mockResponse);
+
+ CreateTableRequest stagedRequest =
+ CreateTableRequest.builder()
+ .withName("test_table")
+ .withSchema(TABLE_SCHEMA)
+ .stageCreate()
+ .build();
+
+ executor.createTable(mockContext, Namespace.of("test_namespace"), stagedRequest);
+
+ ArgumentCaptor<CreateTableRequest> requestCaptor =
+ ArgumentCaptor.forClass(CreateTableRequest.class);
+ verify(mockCatalogWrapper).createTable(any(), requestCaptor.capture(), anyBoolean());
+
+ Assertions.assertTrue(
+ requestCaptor.getValue().stageCreate(),
+ "stageCreate=true must be preserved when rebuilding request");
+ }
+
+ @Test
+ public void testCreateTablePreservesStageCreateFalse() {
+ when(mockContext.userName()).thenReturn("[email protected]");
+ LoadTableResponse mockResponse = mock(LoadTableResponse.class);
+ when(mockCatalogWrapper.createTable(any(), any(), anyBoolean())).thenReturn(mockResponse);
+
+ CreateTableRequest normalRequest =
+ CreateTableRequest.builder().withName("test_table").withSchema(TABLE_SCHEMA).build();
+
+ executor.createTable(mockContext, Namespace.of("test_namespace"), normalRequest);
+
+ ArgumentCaptor<CreateTableRequest> requestCaptor =
+ ArgumentCaptor.forClass(CreateTableRequest.class);
+ verify(mockCatalogWrapper).createTable(any(), requestCaptor.capture(), anyBoolean());
+
+ Assertions.assertFalse(
+ requestCaptor.getValue().stageCreate(),
+ "stageCreate=false must remain false when rebuilding request");
+ }
}