diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/provider/DynamicIcebergConfigProvider.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/provider/DynamicIcebergConfigProvider.java index 0f35fae529a..62ce035f939 100644 --- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/provider/DynamicIcebergConfigProvider.java +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/provider/DynamicIcebergConfigProvider.java @@ -18,8 +18,11 @@ */ package org.apache.gravitino.iceberg.service.provider; +import static org.apache.gravitino.connector.BaseCatalog.CATALOG_BYPASS_PREFIX; + import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import java.util.HashMap; import java.util.Map; import java.util.Optional; import org.apache.commons.lang3.StringUtils; @@ -29,6 +32,7 @@ import org.apache.gravitino.client.GravitinoAdminClient; import org.apache.gravitino.exceptions.NoSuchCatalogException; import org.apache.gravitino.iceberg.common.IcebergConfig; +import org.apache.gravitino.utils.MapUtils; /** * This provider proxy Gravitino lakehouse-iceberg catalogs. @@ -75,8 +79,11 @@ public Optional getIcebergCatalogConfig(String catalogName) { "lakehouse-iceberg".equals(catalog.provider()), String.format("%s.%s is not iceberg catalog", gravitinoMetalake, catalogName)); - Map properties = - IcebergPropertiesUtils.toIcebergCatalogProperties(catalog.properties()); + Map catalogProperties = catalog.properties(); + Map properties = new HashMap<>(); + properties.putAll(IcebergPropertiesUtils.toIcebergCatalogProperties(catalogProperties)); + properties.putAll(MapUtils.getPrefixMap(catalogProperties, CATALOG_BYPASS_PREFIX)); + return Optional.of(new IcebergConfig(properties)); } diff --git a/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/provider/TestDynamicIcebergConfigProvider.java b/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/provider/TestDynamicIcebergConfigProvider.java index 4eb5da5afce..de1bcb13812 100644 --- a/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/provider/TestDynamicIcebergConfigProvider.java +++ b/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/provider/TestDynamicIcebergConfigProvider.java @@ -19,10 +19,13 @@ package org.apache.gravitino.iceberg.service.provider; import java.util.HashMap; +import java.util.Map; +import java.util.Optional; import org.apache.gravitino.Catalog; import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants; import org.apache.gravitino.client.GravitinoAdminClient; import org.apache.gravitino.client.GravitinoMetalake; +import org.apache.gravitino.iceberg.common.IcebergConfig; import org.apache.gravitino.iceberg.common.ops.IcebergCatalogWrapper; import org.apache.iceberg.hive.HiveCatalog; import org.apache.iceberg.jdbc.JdbcCatalog; @@ -113,4 +116,40 @@ public void testInvalidIcebergTableOps() { IllegalArgumentException.class, () -> provider.getIcebergCatalogConfig(IcebergConstants.ICEBERG_REST_DEFAULT_CATALOG)); } + + @Test + public void testCustomProperties() { + String customCatalogName = "custom_backend"; + + Catalog customMockCatalog = Mockito.mock(Catalog.class); + + GravitinoMetalake gravitinoMetalake = Mockito.mock(GravitinoMetalake.class); + Mockito.when(gravitinoMetalake.loadCatalog(customCatalogName)).thenReturn(customMockCatalog); + + Mockito.when(customMockCatalog.provider()).thenReturn("lakehouse-iceberg"); + + Mockito.when(customMockCatalog.properties()) + .thenReturn( + new HashMap() { + { + put(IcebergConstants.CATALOG_BACKEND, "custom"); + put(IcebergConstants.CATALOG_BACKEND_NAME, customCatalogName); + put("gravitino.bypass.custom-k1", "custom-v1"); + put("custom-k2", "custom-v2"); + } + }); + GravitinoAdminClient client = Mockito.mock(GravitinoAdminClient.class); + Mockito.when(client.loadMetalake(Mockito.any())).thenReturn(gravitinoMetalake); + DynamicIcebergConfigProvider provider = new DynamicIcebergConfigProvider(); + provider.setClient(client); + Optional icebergCatalogConfig = + provider.getIcebergCatalogConfig(customCatalogName); + Assertions.assertTrue(icebergCatalogConfig.isPresent()); + Map icebergCatalogProperties = + icebergCatalogConfig.get().getIcebergCatalogProperties(); + Assertions.assertEquals(icebergCatalogProperties.get("custom_k1"), "custom_v1"); + Assertions.assertFalse(icebergCatalogProperties.containsKey("custom_k2")); + Assertions.assertEquals( + icebergCatalogProperties.get(IcebergConstants.CATALOG_BACKEND_NAME), customCatalogName); + } }