Skip to content

Commit

Permalink
fix(iceberg-rest-server): Support to get custom property in custom ca…
Browse files Browse the repository at this point in the history
…talog-backend
  • Loading branch information
liangyouze committed Dec 27, 2024
1 parent ba8df39 commit 9e014e8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -75,8 +79,11 @@ public Optional<IcebergConfig> getIcebergCatalogConfig(String catalogName) {
"lakehouse-iceberg".equals(catalog.provider()),
String.format("%s.%s is not iceberg catalog", gravitinoMetalake, catalogName));

Map<String, String> properties =
IcebergPropertiesUtils.toIcebergCatalogProperties(catalog.properties());
Map<String, String> catalogProperties = catalog.properties();
Map<String, String> properties = new HashMap<>();
properties.putAll(IcebergPropertiesUtils.toIcebergCatalogProperties(catalogProperties));
properties.putAll(MapUtils.getPrefixMap(catalogProperties, CATALOG_BYPASS_PREFIX));

return Optional.of(new IcebergConfig(properties));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String>() {
{
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<IcebergConfig> icebergCatalogConfig =
provider.getIcebergCatalogConfig(customCatalogName);
Assertions.assertTrue(icebergCatalogConfig.isPresent());
Map<String, String> 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);
}
}

0 comments on commit 9e014e8

Please sign in to comment.