Skip to content

Commit

Permalink
[#6035]feat(spark-connector):Support custom catalog backend (#6036)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
When the catalog backend is `custom`, add the `catalog-impl` instead
`type` in properties

### Why are the changes needed?

Fix: #6035 

### Does this PR introduce _any_ user-facing change?
no

### How was this patch tested?
add a new case in `TestIcebergPropertiesConverter`
  • Loading branch information
liangyouze authored Jan 7, 2025
1 parent 688c1c9 commit cb9cdd8
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.gravitino.iceberg.common;
package org.apache.gravitino.catalog.lakehouse.iceberg;

public enum IcebergCatalogBackend {
HIVE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class IcebergPropertiesUtils {
static {
Map<String, String> map = new HashMap();
map.put(IcebergConstants.CATALOG_BACKEND, IcebergConstants.CATALOG_BACKEND);
map.put(IcebergConstants.CATALOG_BACKEND_IMPL, IcebergConstants.CATALOG_BACKEND_IMPL);
map.put(IcebergConstants.GRAVITINO_JDBC_DRIVER, IcebergConstants.GRAVITINO_JDBC_DRIVER);
map.put(IcebergConstants.GRAVITINO_JDBC_USER, IcebergConstants.ICEBERG_JDBC_USER);
map.put(IcebergConstants.GRAVITINO_JDBC_PASSWORD, IcebergConstants.ICEBERG_JDBC_PASSWORD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Map;
import org.apache.gravitino.connector.BaseCatalogPropertiesMetadata;
import org.apache.gravitino.connector.PropertyEntry;
import org.apache.gravitino.iceberg.common.IcebergCatalogBackend;
import org.apache.gravitino.iceberg.common.authentication.AuthenticationConfig;
import org.apache.gravitino.iceberg.common.authentication.kerberos.KerberosConfig;
import org.apache.gravitino.storage.AzureProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
import org.apache.gravitino.SchemaChange;
import org.apache.gravitino.SupportsSchemas;
import org.apache.gravitino.auth.AuthConstants;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergCatalogBackend;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergSchemaPropertiesMetadata;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergTable;
import org.apache.gravitino.catalog.lakehouse.iceberg.ops.IcebergCatalogWrapperHelper;
import org.apache.gravitino.client.GravitinoMetalake;
import org.apache.gravitino.exceptions.NoSuchSchemaException;
import org.apache.gravitino.exceptions.SchemaAlreadyExistsException;
import org.apache.gravitino.exceptions.TableAlreadyExistsException;
import org.apache.gravitino.iceberg.common.IcebergCatalogBackend;
import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.gravitino.iceberg.common.utils.IcebergCatalogUtil;
import org.apache.gravitino.integration.test.container.ContainerSuite;
Expand Down
3 changes: 2 additions & 1 deletion docs/spark-connector/spark-catalog-iceberg.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ Gravitino spark connector will transform below property names which are defined

| Gravitino catalog property name | Spark Iceberg connector configuration | Description | Since Version |
|---------------------------------|---------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------|
| `catalog-backend` | `type` | Catalog backend type | 0.5.0 |
| `catalog-backend` | `type` | Catalog backend type.Supports `hive` or `jdbc` or `rest` or `custom` | 0.5.0 |
| `catalog-backend-impl` | `catalog-impl` | The fully-qualified class name of a custom catalog implementation, only worked if `catalog-backend` is `custom` | 0.8.0-incubating |
| `uri` | `uri` | Catalog backend uri | 0.5.0 |
| `warehouse` | `warehouse` | Catalog backend warehouse | 0.5.0 |
| `jdbc-user` | `jdbc.user` | JDBC user name | 0.5.0 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.apache.gravitino.iceberg.common.IcebergCatalogBackend;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergCatalogBackend;
import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.gravitino.iceberg.common.utils.IcebergCatalogUtil;
import org.apache.gravitino.utils.IsolatedClassLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergCatalogBackend;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants;
import org.apache.gravitino.exceptions.ConnectionFailedException;
import org.apache.gravitino.iceberg.common.ClosableHiveCatalog;
import org.apache.gravitino.iceberg.common.IcebergCatalogBackend;
import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.gravitino.iceberg.common.authentication.AuthenticationConfig;
import org.apache.gravitino.iceberg.common.authentication.kerberos.HiveBackendProxy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import java.util.HashMap;
import java.util.Map;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergCatalogBackend;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants;
import org.apache.gravitino.iceberg.common.IcebergCatalogBackend;
import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.iceberg.CatalogProperties;
import org.apache.iceberg.catalog.Catalog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.util.HashMap;
import java.util.Map;
import org.apache.gravitino.iceberg.common.IcebergCatalogBackend;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergCatalogBackend;
import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.gravitino.integration.test.container.ContainerSuite;
import org.apache.gravitino.integration.test.container.HiveContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import java.util.HashMap;
import java.util.Map;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergCatalogBackend;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants;
import org.apache.gravitino.iceberg.common.IcebergCatalogBackend;
import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.gravitino.integration.test.container.ContainerSuite;
import org.apache.gravitino.integration.test.container.HiveContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.util.HashMap;
import java.util.Map;
import org.apache.gravitino.iceberg.common.IcebergCatalogBackend;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergCatalogBackend;
import org.apache.gravitino.iceberg.common.IcebergConfig;

public class IcebergRESTMemoryCatalogIT extends IcebergRESTServiceIT {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.util.stream.IntStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.gravitino.iceberg.common.IcebergCatalogBackend;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergCatalogBackend;
import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.gravitino.iceberg.integration.test.util.IcebergRESTServerManager;
import org.apache.gravitino.integration.test.util.ITUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.Map;
import java.util.Objects;
import org.apache.commons.io.FileUtils;
import org.apache.gravitino.iceberg.common.IcebergCatalogBackend;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergCatalogBackend;
import org.apache.gravitino.iceberg.common.IcebergConfig;
import org.apache.gravitino.integration.test.container.HiveContainer;
import org.apache.gravitino.integration.test.util.GravitinoITUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class IcebergPropertiesConstants {
public static final String GRAVITINO_ICEBERG_CATALOG_BACKEND = IcebergConstants.CATALOG_BACKEND;

static final String ICEBERG_CATALOG_TYPE = CatalogUtil.ICEBERG_CATALOG_TYPE;
static final String ICEBERG_CATALOG_IMPL = CatalogProperties.CATALOG_IMPL;

public static final String GRAVITINO_ICEBERG_CATALOG_WAREHOUSE = IcebergConstants.WAREHOUSE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergCatalogBackend;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergPropertiesUtils;
import org.apache.gravitino.spark.connector.PropertiesConverter;
Expand All @@ -49,7 +50,20 @@ public Map<String, String> toSparkCatalogProperties(Map<String, String> properti
Preconditions.checkArgument(
StringUtils.isNotBlank(catalogBackend),
String.format("%s should not be empty", IcebergConstants.CATALOG_BACKEND));
all.put(IcebergPropertiesConstants.ICEBERG_CATALOG_TYPE, catalogBackend);
if (catalogBackend.equalsIgnoreCase(IcebergCatalogBackend.CUSTOM.name())) {
String catalogBackendImpl = all.remove(IcebergConstants.CATALOG_BACKEND_IMPL);
Preconditions.checkArgument(
StringUtils.isNotBlank(catalogBackendImpl),
String.format(
"%s should not be empty when %s is %s",
IcebergConstants.CATALOG_BACKEND_IMPL,
IcebergConstants.CATALOG_BACKEND,
IcebergCatalogBackend.CUSTOM.name()));
all.put(IcebergPropertiesConstants.ICEBERG_CATALOG_IMPL, catalogBackendImpl);
} else {
all.put(IcebergPropertiesConstants.ICEBERG_CATALOG_TYPE, catalogBackend);
}

all.put(IcebergPropertiesConstants.ICEBERG_CATALOG_CACHE_ENABLED, "FALSE");
return all;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergCatalogBackend;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -113,4 +115,29 @@ void testCatalogPropertiesWithRestBackend() {
"rest-warehouse"),
properties);
}

@Test
void testCatalogPropertiesWithCustomBackend() {
Map<String, String> properties =
icebergPropertiesConverter.toSparkCatalogProperties(
ImmutableMap.of(
IcebergPropertiesConstants.GRAVITINO_ICEBERG_CATALOG_BACKEND,
IcebergCatalogBackend.CUSTOM.name(),
IcebergConstants.CATALOG_BACKEND_IMPL,
"CustomCatalog",
IcebergPropertiesConstants.GRAVITINO_ICEBERG_CATALOG_WAREHOUSE,
"custom-warehouse",
"key1",
"value1"));

Assertions.assertEquals(
ImmutableMap.of(
IcebergPropertiesConstants.ICEBERG_CATALOG_CACHE_ENABLED,
"FALSE",
IcebergPropertiesConstants.ICEBERG_CATALOG_IMPL,
"CustomCatalog",
IcebergPropertiesConstants.ICEBERG_CATALOG_WAREHOUSE,
"custom-warehouse"),
properties);
}
}

0 comments on commit cb9cdd8

Please sign in to comment.