World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#470] feat(hive): Support detailed hive catalog property metadata (#473)
Qi Yu1b3e4963d7fd
diff --git a/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.java b/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.javaindex 8472cffbdc..422561e94b 100644--- a/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.java+++ b/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.java@@ -5,6 +5,8 @@package com.datastrato.graviton.catalog.hive;import static com.datastrato.graviton.catalog.BaseCatalog.CATALOG_BYPASS_PREFIX;+import static com.datastrato.graviton.catalog.hive.HiveCatalogPropertiesMeta.CLIENT_POOL_SIZE;+import static com.datastrato.graviton.catalog.hive.HiveCatalogPropertiesMeta.METASTORE_URIS;import static com.datastrato.graviton.catalog.hive.HiveTable.SUPPORT_TABLE_TYPES;import static com.datastrato.graviton.catalog.hive.HiveTablePropertiesMetadata.COMMENT;import static com.datastrato.graviton.catalog.hive.HiveTablePropertiesMetadata.TABLE_TYPE;@@ -34,6 +36,7 @@ import com.datastrato.graviton.rel.transforms.Transform;import com.datastrato.graviton.rel.transforms.Transforms;import com.google.common.annotations.VisibleForTesting;import com.google.common.base.Preconditions;+import com.google.common.collect.ImmutableMap;import com.google.common.collect.Maps;import io.substrait.type.Type;import java.io.IOException;@@ -45,6 +48,7 @@ import java.util.stream.Collectors;import org.apache.commons.lang3.ArrayUtils;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hive.conf.HiveConf;+import org.apache.hadoop.hive.conf.HiveConf.ConfVars;import org.apache.hadoop.hive.metastore.TableType;import org.apache.hadoop.hive.metastore.api.AlreadyExistsException;import org.apache.hadoop.hive.metastore.api.Database;@@ -71,6 +75,14 @@ public class HiveCatalogOperations implements CatalogOperations, SupportsSchemasprivate HiveTablePropertiesMetadata tablePropertiesMetadata;+ private HiveCatalogPropertiesMeta catalogPropertiesMetadata;++ // Map that maintains the mapping of keys in Graviton to that in Hive, for example, users+ // will only need to set the configuration 'METASTORE_URL' in Graviton and Graviton will change+ // it to `METASTOREURIS` automatically and pass it to Hive.+ public static final Map<String, String> GRAVITON_CONFIG_TO_HIVE =+ ImmutableMap.of(METASTORE_URIS, ConfVars.METASTOREURIS.varname);+/*** Constructs a new instance of HiveCatalogOperations.*@@ -88,23 +100,32 @@ public class HiveCatalogOperations implements CatalogOperations, SupportsSchemas*/@Overridepublic void initialize(Map<String, String> conf) throws RuntimeException {- Configuration hadoopConf = new Configuration();- conf.forEach(hadoopConf::set);- hiveConf = new HiveConf(hadoopConf, HiveCatalogOperations.class);+ this.tablePropertiesMetadata = new HiveTablePropertiesMetadata();+ this.catalogPropertiesMetadata = new HiveCatalogPropertiesMeta();- // Overwrite hive conf with graviton conf if exists+ Map<String, String> byPassConfig = Maps.newHashMap();conf.forEach((key, value) -> {if (key.startsWith(CATALOG_BYPASS_PREFIX)) {// Trim bypass prefix and pass it to hive conf- hiveConf.set(key.substring(CATALOG_BYPASS_PREFIX.length()), value);+ byPassConfig.put(key.substring(CATALOG_BYPASS_PREFIX.length()), value);+ } else if (GRAVITON_CONFIG_TO_HIVE.containsKey(key)) {+ byPassConfig.put(GRAVITON_CONFIG_TO_HIVE.get(key), value);+ } else {+ byPassConfig.put(key, value);}});- // todo(xun): add hive client pool size in config- this.clientPool = new HiveClientPool(1, hiveConf);+ Configuration hadoopConf = new Configuration();+ byPassConfig.forEach(hadoopConf::set);+ hiveConf = new HiveConf(hadoopConf, HiveCatalogOperations.class);- this.tablePropertiesMetadata = new HiveTablePropertiesMetadata();+ this.clientPool = new HiveClientPool(getClientPoolSize(conf), hiveConf);+ }++ @VisibleForTesting+ int getClientPoolSize(Map<String, String> conf) {+ return (int) catalogPropertiesMetadata.getOrDefault(conf, CLIENT_POOL_SIZE);}/** Closes the Hive catalog and releases the associated client pool. */@@ -808,7 +829,6 @@ public class HiveCatalogOperations implements CatalogOperations, SupportsSchemas@Overridepublic PropertiesMetadata catalogPropertiesMetadata() throws UnsupportedOperationException {- // TODO(yuqi): We will implement this in next PR- return Maps::newHashMap;+ return catalogPropertiesMetadata;}}diff --git a/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogPropertiesMeta.java b/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogPropertiesMeta.javanew file mode 100644index 0000000000..b8946796e3--- /dev/null+++ b/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogPropertiesMeta.java@@ -0,0 +1,44 @@+/*+ * Copyright 2023 Datastrato.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.graviton.catalog.hive;++import com.datastrato.graviton.catalog.BaseCatalogPropertiesMetadata;+import com.datastrato.graviton.catalog.PropertyEntry;+import com.google.common.collect.ImmutableMap;+import java.util.Map;++public class HiveCatalogPropertiesMeta extends BaseCatalogPropertiesMetadata {++ public static final String CLIENT_POOL_SIZE = "client.pool-size";+ public static final int DEFAULT_CLIENT_POOL_SIZE = 1;++ public static final String METASTORE_URIS = "metastore.uris";++ private static final Map<String, PropertyEntry<?>> HIVE_CATALOG_PROPERTY_ENTRIES =+ ImmutableMap.<String, PropertyEntry<?>>builder()+ .put(+ METASTORE_URIS,+ PropertyEntry.stringRequiredPropertyEntry(+ METASTORE_URIS, "The Hive metastore URIs", true, false))+ .put(+ CLIENT_POOL_SIZE,+ PropertyEntry.integerOptionalPropertyEntry(+ CLIENT_POOL_SIZE,+ "The maximum number of Hive clients in the pool for graviton",+ true,+ DEFAULT_CLIENT_POOL_SIZE,+ false))+ .putAll(BASIC_CATALOG_PROPERTY_ENTRIES)+ .build();++ @Override+ protected Map<String, PropertyEntry<?>> specificPropertyEntries() {+ // Currently, Hive catalog only needs to specify the metastore URIs.+ // TODO(yuqi), we can add more properties like username for metastore+ // (kerberos authentication) later.+ return HIVE_CATALOG_PROPERTY_ENTRIES;+ }+}diff --git a/catalogs/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/TestHiveCatalog.java b/catalogs/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/TestHiveCatalog.javaindex f838799c41..fff1974a3d 100644--- a/catalogs/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/TestHiveCatalog.java+++ b/catalogs/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/TestHiveCatalog.java@@ -4,6 +4,8 @@*/package com.datastrato.graviton.catalog.hive;+import static com.datastrato.graviton.catalog.hive.HiveCatalogPropertiesMeta.METASTORE_URIS;+import com.datastrato.graviton.Namespace;import com.datastrato.graviton.catalog.hive.miniHMS.MiniHiveMetastoreService;import com.datastrato.graviton.meta.AuditInfo;@@ -44,4 +46,44 @@ public class TestHiveCatalog extends MiniHiveMetastoreService {Assertions.assertTrue(dbs.contains(DB_NAME));}}++ @Test+ void testCatalogProperty() {+ AuditInfo auditInfo =+ new AuditInfo.Builder().withCreator("creator").withCreateTime(Instant.now()).build();++ CatalogEntity entity =+ new CatalogEntity.Builder()+ .withId(1L)+ .withName("catalog")+ .withNamespace(Namespace.of("metalake"))+ .withType(HiveCatalog.Type.RELATIONAL)+ .withProvider("hive")+ .withAuditInfo(auditInfo)+ .build();++ Map<String, String> conf = Maps.newHashMap();+ metastore.hiveConf().forEach(e -> conf.put(e.getKey(), e.getValue()));++ try (HiveCatalogOperations ops = new HiveCatalogOperations(entity)) {+ ops.initialize(conf);+ Assertions.assertDoesNotThrow(+ () -> {+ Map<String, String> map = Maps.newHashMap();+ map.put(METASTORE_URIS, "/tmp");+ ops.catalogPropertiesMetadata().validatePropertyForCreate(map);+ });++ Throwable throwable =+ Assertions.assertThrows(+ IllegalArgumentException.class,+ () -> ops.catalogPropertiesMetadata().validatePropertyForCreate(Maps.newHashMap()));++ Assertions.assertTrue(+ throwable+ .getMessage()+ .contains(+ String.format("Properties are required and must be set: [%s]", METASTORE_URIS)));+ }+ }}diff --git a/catalogs/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/TestHiveCatalogOperations.java b/catalogs/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/TestHiveCatalogOperations.javaindex 51bf05c9f9..e6c84fb520 100644--- a/catalogs/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/TestHiveCatalogOperations.java+++ b/catalogs/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/TestHiveCatalogOperations.java@@ -6,15 +6,40 @@package com.datastrato.graviton.catalog.hive;import static com.datastrato.graviton.catalog.BaseCatalog.CATALOG_BYPASS_PREFIX;+import static com.datastrato.graviton.catalog.hive.HiveCatalogPropertiesMeta.CLIENT_POOL_SIZE;+import static com.datastrato.graviton.catalog.hive.HiveCatalogPropertiesMeta.METASTORE_URIS;+import com.datastrato.graviton.Catalog;+import com.datastrato.graviton.catalog.PropertyEntry;import com.google.common.collect.Maps;import java.util.Map;import org.junit.jupiter.api.Assertions;import org.junit.jupiter.api.Test;class TestHiveCatalogOperations {+@Test- void testInitialize() {+ void testGetClientPoolSize() {+ Map<String, String> maps = Maps.newHashMap();+ maps.put(CLIENT_POOL_SIZE, "10");+ HiveCatalogOperations op = new HiveCatalogOperations(null);+ op.initialize(maps);+ Assertions.assertEquals(10, op.getClientPoolSize(maps));++ maps.clear();+ maps.put(CLIENT_POOL_SIZE + "_wrong_mark", "10");+ op = new HiveCatalogOperations(null);+ op.initialize(maps);+ Assertions.assertNotEquals(10, op.getClientPoolSize(maps));++ maps.put(CLIENT_POOL_SIZE, "1");+ op = new HiveCatalogOperations(null);+ op.initialize(maps);+ Assertions.assertEquals(1, op.getClientPoolSize(maps));+ }++ @Test+ void testInitialize() throws NoSuchFieldException, IllegalAccessException {Map<String, String> properties = Maps.newHashMap();HiveCatalogOperations hiveCatalogOperations = new HiveCatalogOperations(null);hiveCatalogOperations.initialize(properties);@@ -26,12 +51,22 @@ class TestHiveCatalogOperations {hiveCatalogOperations.initialize(properties);v = hiveCatalogOperations.hiveConf.get("mapreduce.job.reduces");Assertions.assertEquals("20", v);+ }- // Test If user properties can override the value in hive-site.xml- properties.clear();- properties.put("mapreduce.job.reduces", "30");- hiveCatalogOperations.initialize(properties);- v = hiveCatalogOperations.hiveConf.get("mapreduce.job.reduces");- Assertions.assertEquals("30", v);+ @Test+ void testPropertyMeta() {+ HiveCatalogOperations hiveCatalogOperations = new HiveCatalogOperations(null);+ hiveCatalogOperations.initialize(Maps.newHashMap());++ Map<String, PropertyEntry<?>> propertyEntryMap =+ hiveCatalogOperations.catalogPropertiesMetadata().propertyEntries();+ Assertions.assertEquals(4, propertyEntryMap.size());+ Assertions.assertTrue(propertyEntryMap.containsKey(METASTORE_URIS));+ Assertions.assertTrue(propertyEntryMap.containsKey(Catalog.PROPERTY_PACKAGE));+ Assertions.assertTrue(propertyEntryMap.containsKey(CLIENT_POOL_SIZE));++ Assertions.assertTrue(propertyEntryMap.get(METASTORE_URIS).isRequired());+ Assertions.assertFalse(propertyEntryMap.get(Catalog.PROPERTY_PACKAGE).isRequired());+ Assertions.assertFalse(propertyEntryMap.get(CLIENT_POOL_SIZE).isRequired());}}diff --git a/catalogs/catalog-hive/src/test/resources/hive-site.xml b/catalogs/catalog-hive/src/test/resources/hive-site.xmlindex 97626980c0..d721d3102e 100644--- a/catalogs/catalog-hive/src/test/resources/hive-site.xml+++ b/catalogs/catalog-hive/src/test/resources/hive-site.xml@@ -12,5 +12,6 @@<name>mapreduce.job.reduces</name><value>10</value></property>+</configuration>diff --git a/core/src/main/java/com/datastrato/graviton/catalog/BaseCatalogPropertiesMetadata.java b/core/src/main/java/com/datastrato/graviton/catalog/BaseCatalogPropertiesMetadata.javanew file mode 100644index 0000000000..e62a57de8f--- /dev/null+++ b/core/src/main/java/com/datastrato/graviton/catalog/BaseCatalogPropertiesMetadata.java@@ -0,0 +1,27 @@+/*+ * Copyright 2023 Datastrato.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.graviton.catalog;++import static com.datastrato.graviton.Catalog.PROPERTY_PACKAGE;++import com.google.common.collect.ImmutableList;+import com.google.common.collect.Maps;+import java.util.Map;++public abstract class BaseCatalogPropertiesMetadata extends BasePropertiesMetadata {++ protected static final Map<String, PropertyEntry<?>> BASIC_CATALOG_PROPERTY_ENTRIES =+ Maps.uniqueIndex(+ ImmutableList.of(+ PropertyEntry.stringImmutablePropertyEntry(+ PROPERTY_PACKAGE,+ "The path of the catalog-related classes and resources",+ false,+ null,+ false,+ false)),+ PropertyEntry::getName);+}diff --git a/core/src/main/java/com/datastrato/graviton/catalog/CatalogManager.java b/core/src/main/java/com/datastrato/graviton/catalog/CatalogManager.javaindex 002f318a78..85bb73ff0b 100644--- a/core/src/main/java/com/datastrato/graviton/catalog/CatalogManager.java+++ b/core/src/main/java/com/datastrato/graviton/catalog/CatalogManager.java@@ -298,12 +298,12 @@ public class CatalogManager implements SupportsCatalogs, Closeable {Arrays.stream(catalogChanges).forEach(- tableChange -> {- if (tableChange instanceof SetProperty) {- SetProperty setProperty = (SetProperty) tableChange;+ catalogChange -> {+ if (catalogChange instanceof SetProperty) {+ SetProperty setProperty = (SetProperty) catalogChange;upserts.put(setProperty.getProperty(), setProperty.getValue());- } else if (tableChange instanceof RemoveProperty) {- RemoveProperty removeProperty = (RemoveProperty) tableChange;+ } else if (catalogChange instanceof RemoveProperty) {+ RemoveProperty removeProperty = (RemoveProperty) catalogChange;deletes.put(removeProperty.getProperty(), removeProperty.getProperty());}});diff --git a/core/src/main/java/com/datastrato/graviton/catalog/PropertyEntry.java b/core/src/main/java/com/datastrato/graviton/catalog/PropertyEntry.javaindex c7c78c43dc..458f648c43 100644--- a/core/src/main/java/com/datastrato/graviton/catalog/PropertyEntry.java+++ b/core/src/main/java/com/datastrato/graviton/catalog/PropertyEntry.java@@ -178,6 +178,28 @@ public final class PropertyEntry<T> {.build();}+ public static PropertyEntry<Integer> integerPropertyEntry(+ String name,+ String description,+ boolean required,+ boolean immutable,+ Integer defaultValue,+ boolean hidden,+ boolean reserved) {+ return new Builder<Integer>()+ .withName(name)+ .withDescription(description)+ .withRequired(required)+ .withImmutable(immutable)+ .withJavaType(Integer.class)+ .withDefaultValue(defaultValue)+ .withDecoder(Integer::parseInt)+ .withEncoder(String::valueOf)+ .withHidden(hidden)+ .withReserved(reserved)+ .build();+ }+public static PropertyEntry<String> stringReservedPropertyEntry(String name, String description, boolean hidden) {return stringPropertyEntry(name, description, false, true, null, hidden, true);@@ -215,6 +237,11 @@ public final class PropertyEntry<T> {return stringPropertyEntry(name, description, true, immutable, null, hidden, false);}+ public static PropertyEntry<Integer> integerOptionalPropertyEntry(+ String name, String description, boolean immutable, int defaultValue, boolean hidden) {+ return integerPropertyEntry(name, description, false, immutable, defaultValue, hidden, false);+ }+public static PropertyEntry<String> stringImmutablePropertyEntry(String name,String description,diff --git a/core/src/test/java/com/datastrato/graviton/TestCatalogOperations.java b/core/src/test/java/com/datastrato/graviton/TestCatalogOperations.javaindex a04fa59efa..e2d17aea8d 100644--- a/core/src/test/java/com/datastrato/graviton/TestCatalogOperations.java+++ b/core/src/test/java/com/datastrato/graviton/TestCatalogOperations.java@@ -322,6 +322,24 @@ public class TestCatalogOperations implements CatalogOperations, TableCatalog, S.build();}};+ } else if (config.containsKey("hive")) {+ return new BasePropertiesMetadata() {+ @Override+ protected Map<String, PropertyEntry<?>> specificPropertyEntries() {+ return ImmutableMap.<String, PropertyEntry<?>>builder()+ .put(+ "hive.metastore.uris",+ PropertyEntry.stringPropertyEntry(+ "hive.metastore.uris",+ "The Hive metastore URIs",+ true,+ true,+ null,+ false,+ false))+ .build();+ }+ };}return Maps::newHashMap;}diff --git a/core/src/test/java/com/datastrato/graviton/catalog/TestCatalogManager.java b/core/src/test/java/com/datastrato/graviton/catalog/TestCatalogManager.javaindex bb05a38d06..ba0c7c5a6c 100644--- a/core/src/test/java/com/datastrato/graviton/catalog/TestCatalogManager.java+++ b/core/src/test/java/com/datastrato/graviton/catalog/TestCatalogManager.java@@ -96,6 +96,44 @@ public class TestCatalogManager {}}+ @Test+ void testCreateWithHiveProperty() throws IOException {+ NameIdentifier ident = NameIdentifier.of("metalake", "test445");+ Map<String, String> props1 = ImmutableMap.<String, String>builder().put("hive", "hive").build();+ Assertions.assertThrowsExactly(+ IllegalArgumentException.class,+ () ->+ catalogManager.createCatalog(+ ident, Catalog.Type.RELATIONAL, provider, "comment", props1));+ // BUG here, In memory store does not support rollback operation, so the catalog is created in+ // entity store,+ // we need to remove it manually+ reset();+ Map<String, String> props2 =+ ImmutableMap.<String, String>builder()+ .put("hive", "hive")+ .put("hive.metastore.uris", "mock_url")+ .build();+ Assertions.assertDoesNotThrow(+ () ->+ catalogManager.createCatalog(+ ident, Catalog.Type.RELATIONAL, provider, "comment", props2));+ reset();++ Map<String, String> props3 =+ ImmutableMap.<String, String>builder()+ .put("hive", "hive")+ .put("hive.metastore.uris", "")+ .put("hive.metastore.sasl.enabled", "true")+ .put("hive.metastore.kerberos.principal", "mock_principal")+ .put("hive.metastore.kerberos.keytab.file", "mock_keytab")+ .build();+ Assertions.assertDoesNotThrow(+ () ->+ catalogManager.createCatalog(+ ident, Catalog.Type.RELATIONAL, provider, "comment", props3));+ }+@Test@Order(1)void testLoadTable() throws IOException {diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/test/catalog/hive/CatalogHiveIT.java b/integration-test/src/test/java/com/datastrato/graviton/integration/test/catalog/hive/CatalogHiveIT.javaindex 0c0036e9b0..d4c86cfa03 100644--- a/integration-test/src/test/java/com/datastrato/graviton/integration/test/catalog/hive/CatalogHiveIT.java+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/test/catalog/hive/CatalogHiveIT.java@@ -5,6 +5,7 @@package com.datastrato.graviton.integration.test.catalog.hive;import static com.datastrato.graviton.catalog.BaseCatalog.CATALOG_BYPASS_PREFIX;+import static com.datastrato.graviton.catalog.hive.HiveCatalogPropertiesMeta.METASTORE_URIS;import static com.datastrato.graviton.catalog.hive.HiveTablePropertiesMetadata.COMMENT;import static com.datastrato.graviton.catalog.hive.HiveTablePropertiesMetadata.EXTERNAL;import static com.datastrato.graviton.catalog.hive.HiveTablePropertiesMetadata.FORMAT;@@ -128,8 +129,7 @@ public class CatalogHiveIT extends AbstractIT {private static void createCatalog() {Map<String, String> properties = Maps.newHashMap();- properties.put(- CATALOG_BYPASS_PREFIX + HiveConf.ConfVars.METASTOREURIS.varname, HIVE_METASTORE_URIS);+ properties.put(METASTORE_URIS, HIVE_METASTORE_URIS);properties.put(CATALOG_BYPASS_PREFIX + HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES.varname, "30");properties.put(