Skip to content

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

[#63] feat(catalog): Implement the hive client in the HiveCatalog (#65)

Xun Liu5fa671d4fdf3
diff --git a/catalog-hive/build.gradle.kts b/catalog-hive/build.gradle.kts
new file mode 100644
index 0000000000..9fc9dcd12f
--- /dev/null
+++ b/catalog-hive/build.gradle.kts
@@ -0,0 +1,27 @@
+description = "hive catalog"
+
+plugins {
+ `maven-publish`
+ id("java")
+ id("idea")
+ id("com.diffplug.spotless")
+}
+
+dependencies {
+ implementation(project(":core"))
+
+ implementation(libs.hive2.metastore)
+ implementation(libs.hive2.exec) {
+ exclude("org.slf4j")
+ exclude("org.pentaho", "pentaho-aggdesigner-algorithm")
+ }
+ implementation(libs.guava)
+
+ testImplementation(libs.slf4j.jdk14)
+ testImplementation(libs.junit.jupiter.api)
+ testRuntimeOnly(libs.junit.jupiter.engine)
+}
+
+tasks.test {
+ useJUnitPlatform()
+}
\ No newline at end of file
diff --git a/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalog.java b/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalog.java
new file mode 100644
index 0000000000..18bf6e91c2
--- /dev/null
+++ b/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalog.java
@@ -0,0 +1,57 @@
+package com.datastrato.graviton.catalog.hive;
+
+import com.datastrato.graviton.Config;
+import com.datastrato.graviton.meta.BaseCatalog;
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HiveCatalog extends BaseCatalog {
+ public static final Logger LOG = LoggerFactory.getLogger(HiveCatalog.class);
+
+ @VisibleForTesting HiveClientPool clientPool;
+
+ private HiveConf hiveConf;
+
+ @Override
+ public void close() {
+ if (clientPool != null) {
+ clientPool.close();
+ }
+ }
+
+ @Override
+ public void initialize(Config config) throws RuntimeException {
+ // todo(xun): add hive client pool size in config
+ this.clientPool = new HiveClientPool(1, hiveConf);
+ }
+
+ public static class Builder extends BaseCatalog.BaseCatalogBuilder<Builder, HiveCatalog> {
+ HiveConf hiveConf;
+
+ HiveCatalog hiveCatalog = new HiveCatalog();
+
+ @Override
+ protected HiveCatalog internalBuild() {
+ hiveCatalog.id = id;
+ hiveCatalog.lakehouseId = lakehouseId;
+ hiveCatalog.name = name;
+ hiveCatalog.namespace = namespace;
+ hiveCatalog.type = type;
+ hiveCatalog.comment = comment;
+ hiveCatalog.properties = properties;
+ hiveCatalog.auditInfo = auditInfo;
+ hiveCatalog.hiveConf = hiveConf;
+
+ return hiveCatalog;
+ }
+
+ public Builder withHiveConf(Configuration conf) {
+ this.hiveConf = new HiveConf(conf, HiveCatalog.class);
+ this.hiveConf.addResource(conf);
+ return this;
+ }
+ }
+}
diff --git a/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveClientPool.java b/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveClientPool.java
new file mode 100644
index 0000000000..35e4265ab2
--- /dev/null
+++ b/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveClientPool.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.datastrato.graviton.catalog.hive;
+
+import com.datastrato.graviton.catalog.hive.dyn.DynMethods;
+import com.datastrato.graviton.util.ClientPoolImpl;
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.HiveMetaHookLoader;
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.RetryingMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.thrift.TException;
+import org.apache.thrift.transport.TTransportException;
+
+// hive-metastore/src/main/java/org/apache/iceberg/hive/HiveClientPool.java
+public class HiveClientPool extends ClientPoolImpl<IMetaStoreClient, TException> {
+
+ private static final DynMethods.StaticMethod GET_CLIENT =
+ DynMethods.builder("getProxy")
+ .impl(
+ RetryingMetaStoreClient.class,
+ HiveConf.class,
+ HiveMetaHookLoader.class,
+ String.class) // Hive 1 and 2
+ .impl(
+ RetryingMetaStoreClient.class,
+ Configuration.class,
+ HiveMetaHookLoader.class,
+ String.class) // Hive 3
+ .buildStatic();
+
+ private final HiveConf hiveConf;
+
+ public HiveClientPool(int poolSize, Configuration conf) {
+ // Do not allow retry by default as we rely on RetryingHiveClient
+ super(poolSize, TTransportException.class, false);
+ this.hiveConf = new HiveConf(conf, HiveClientPool.class);
+ this.hiveConf.addResource(conf);
+ }
+
+ @Override
+ protected IMetaStoreClient newClient() {
+ try {
+ try {
+ return GET_CLIENT.invoke(
+ hiveConf, (HiveMetaHookLoader) tbl -> null, HiveMetaStoreClient.class.getName());
+ } catch (RuntimeException e) {
+ // any MetaException would be wrapped into RuntimeException during reflection, so let's
+ // double-check type here
+ if (e.getCause() instanceof MetaException) {
+ throw (MetaException) e.getCause();
+ }
+ throw e;
+ }
+ } catch (MetaException e) {
+ throw new RuntimeException("Failed to connect to Hive Metastore", e);
+ } catch (Throwable t) {
+ if (t.getMessage().contains("Another instance of Derby may have already booted")) {
+ throw new RuntimeException(
+ "Failed to start an embedded metastore because embedded "
+ + "Derby supports only one client at a time. To fix this, use a metastore that supports "
+ + "multiple clients.",
+ t);
+ }
+
+ throw new RuntimeException("Failed to connect to Hive Metastore", t);
+ }
+ }
+
+ @Override
+ protected IMetaStoreClient reconnect(IMetaStoreClient client) {
+ try {
+ client.close();
+ client.reconnect();
+ } catch (MetaException e) {
+ throw new RuntimeException("Failed to reconnect to Hive Metastore", e);
+ }
+ return client;
+ }
+
+ @Override
+ protected boolean isConnectionException(Exception e) {
+ return super.isConnectionException(e)
+ || (e != null
+ && e instanceof MetaException
+ && e.getMessage()
+ .contains("Got exception: org.apache.thrift.transport.TTransportException"));
+ }
+
+ @Override
+ protected void close(IMetaStoreClient client) {
+ client.close();
+ }
+
+ @VisibleForTesting
+ HiveConf hiveConf() {
+ return hiveConf;
+ }
+}
diff --git a/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/dyn/DynConstructors.java b/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/dyn/DynConstructors.java
new file mode 100644
index 0000000000..075a487858
--- /dev/null
+++ b/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/dyn/DynConstructors.java
@@ -0,0 +1,298 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.datastrato.graviton.catalog.hive.dyn;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Throwables;
+import com.google.common.collect.Maps;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Arrays;
+import java.util.Map;
+
+// common/src/main/java/org/apache/iceberg/common/DynConstructors.java
+public class DynConstructors {
+ private DynConstructors() {}
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static Builder builder(Class<?> baseClass) {
+ return new Builder(baseClass);
+ }
+
+ private static NoSuchMethodException buildCheckedException(
+ Class<?> baseClass, Map<String, Throwable> problems) {
+ NoSuchMethodException exc =
+ new NoSuchMethodException(
+ "Cannot find constructor for " + baseClass + "\n" + formatProblems(problems));
+ problems.values().forEach(exc::addSuppressed);
+ return exc;
+ }
+
+ private static RuntimeException buildRuntimeException(
+ Class<?> baseClass, Map<String, Throwable> problems) {
+ RuntimeException exc =
+ new RuntimeException(
+ "Cannot find constructor for " + baseClass + "\n" + formatProblems(problems));
+ problems.values().forEach(exc::addSuppressed);
+ return exc;
+ }
+
+ private static String formatProblems(Map<String, Throwable> problems) {
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ for (Map.Entry<String, Throwable> problem : problems.entrySet()) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append("\n");
+ }
+ sb.append("\tMissing ")
+ .append(problem.getKey())
+ .append(" [")
+ .append(problem.getValue().getClass().getName())
+ .append(": ")
+ .append(problem.getValue().getMessage())
+ .append("]");
+ }
+ return sb.toString();
+ }
+
+ private static String methodName(Class<?> targetClass, Class<?>... types) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(targetClass.getName()).append("(");
+ boolean first = true;
+ for (Class<?> type : types) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(",");
+ }
+ sb.append(type.getName());
+ }
+ sb.append(")");
+ return sb.toString();
+ }
+
+ public static class Ctor<C> extends DynMethods.UnboundMethod {
+ private final Constructor<C> ctor;
+ private final Class<? extends C> constructed;
+
+ private Ctor(Constructor<C> constructor, Class<? extends C> constructed) {
+ super(null, "newInstance");
+ this.ctor = constructor;
+ this.constructed = constructed;
+ }
+
+ public Class<? extends C> getConstructedClass() {
+ return constructed;
+ }
+
+ public C newInstanceChecked(Object... args) throws Exception {
+ try {
+ if (args.length > ctor.getParameterCount()) {
+ return ctor.newInstance(Arrays.copyOfRange(args, 0, ctor.getParameterCount()));
+ } else {
+ return ctor.newInstance(args);
+ }
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw e;
+ } catch (InvocationTargetException e) {
+ Throwables.propagateIfInstanceOf(e.getCause(), Exception.class);
+ Throwables.propagateIfInstanceOf(e.getCause(), RuntimeException.class);
+ throw Throwables.propagate(e.getCause());
+ }
+ }
+
+ public C newInstance(Object... args) {
+ try {
+ return newInstanceChecked(args);
+ } catch (Exception e) {
+ Throwables.propagateIfInstanceOf(e, RuntimeException.class);
+ throw Throwables.propagate(e);
+ }
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <R> R invoke(Object target, Object... args) {
+ Preconditions.checkArgument(
+ target == null, "Invalid call to constructor: target must be null");
+ return (R) newInstance(args);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <R> R invokeChecked(Object target, Object... args) throws Exception {
+ Preconditions.checkArgument(
+ target == null, "Invalid call to constructor: target must be null");
+ return (R) newInstanceChecked(args);
+ }
+
+ @Override
+ public DynMethods.BoundMethod bind(Object receiver) {
+ throw new IllegalStateException("Cannot bind constructors");
+ }
+
+ @Override
+ public boolean isStatic() {
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "(constructor=" + ctor + ", class=" + constructed + ")";
+ }
+ }
+
+ public static class Builder {
+ private final Class<?> baseClass;
+ private final Map<String, Throwable> problems = Maps.newHashMap();
+ private ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ private Ctor ctor = null;
+
+ public Builder(Class<?> baseClass) {
+ this.baseClass = baseClass;
+ }
+
+ public Builder() {
+ this.baseClass = null;
+ }
+
+ /**
+ * Set the {@link ClassLoader} used to lookup classes by name.
+ *
+ * <p>If not set, the current thread's ClassLoader is used.
+ *
+ * @param newLoader a ClassLoader
+ * @return this Builder for method chaining
+ */
+ public Builder loader(ClassLoader newLoader) {
+ this.loader = newLoader;
+ return this;
+ }
+
+ public Builder impl(String className, Class<?>... types) {
+ // don't do any work if an implementation has been found
+ if (ctor != null) {
+ return this;
+ }
+
+ try {
+ Class<?> targetClass = Class.forName(className, true, loader);
+ impl(targetClass, types);
+ } catch (NoClassDefFoundError | ClassNotFoundException e) {
+ // cannot load this implementation
+ problems.put(className, e);
+ }
+ return this;
+ }
+
+ public <T> Builder impl(Class<T> targetClass, Class<?>... types) {
+ // don't do any work if an implementation has been found
+ if (ctor != null) {
+ return this;
+ }
+
+ try {
+ ctor = new Ctor<T>(targetClass.getConstructor(types), targetClass);
+ } catch (NoSuchMethodException e) {
+ // not the right implementation
+ problems.put(methodName(targetClass, types), e);
+ }
+ return this;
+ }
+
+ public Builder hiddenImpl(Class<?>... types) {
+ hiddenImpl(baseClass, types);
+ return this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Builder hiddenImpl(String className, Class<?>... types) {
+ // don't do any work if an implementation has been found
+ if (ctor != null) {
+ return this;
+ }
+
+ try {
+ Class targetClass = Class.forName(className, true, loader);
+ hiddenImpl(targetClass, types);
+ } catch (NoClassDefFoundError | ClassNotFoundException e) {
+ // cannot load this implementation
+ problems.put(className, e);
+ }
+ return this;
+ }
+
+ public <T> Builder hiddenImpl(Class<T> targetClass, Class<?>... types) {
+ // don't do any work if an implementation has been found
+ if (ctor != null) {
+ return this;
+ }
+
+ try {
+ Constructor<T> hidden = targetClass.getDeclaredConstructor(types);
+ AccessController.doPrivileged(new MakeAccessible(hidden));
+ ctor = new Ctor<T>(hidden, targetClass);
+ } catch (SecurityException e) {
+ // unusable
+ problems.put(methodName(targetClass, types), e);
+ } catch (NoSuchMethodException e) {
+ // not the right implementation
+ problems.put(methodName(targetClass, types), e);
+ }
+ return this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <C> Ctor<C> buildChecked() throws NoSuchMethodException {
+ if (ctor != null) {
+ return ctor;
+ }
+ throw buildCheckedException(baseClass, problems);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <C> Ctor<C> build() {
+ if (ctor != null) {
+ return ctor;
+ }
+ throw buildRuntimeException(baseClass, problems);
+ }
+ }
+
+ private static class MakeAccessible implements PrivilegedAction<Void> {
+ private final Constructor<?> hidden;
+
+ MakeAccessible(Constructor<?> hidden) {
+ this.hidden = hidden;
+ }
+
+ @Override
+ public Void run() {
+ hidden.setAccessible(true);
+ return null;
+ }
+ }
+}
diff --git a/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/dyn/DynFields.java b/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/dyn/DynFields.java
new file mode 100644
index 0000000000..0f07444a6d
--- /dev/null
+++ b/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/dyn/DynFields.java
@@ -0,0 +1,430 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.datastrato.graviton.catalog.hive.dyn;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Throwables;
+import com.google.common.collect.Sets;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Set;
+
+// common/src/main/java/org/apache/iceberg/common/DynFields.java
+public class DynFields {
+
+ private DynFields() {}
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Convenience wrapper class around {@link Field}.
+ *
+ * <p>Allows callers to invoke the wrapped method with all Exceptions wrapped by RuntimeException,
+ * or with a single Exception catch block.
+ */
+ public static class UnboundField<T> {
+ private final Field field;
+ private final String name;
+
+ private UnboundField(Field field, String name) {
+ this.field = field;
+ this.name = name;
+ }
+
+ @SuppressWarnings("unchecked")
+ public T get(Object target) {
+ try {
+ return (T) field.get(target);
+ } catch (IllegalAccessException e) {
+ throw Throwables.propagate(e);
+ }
+ }
+
+ public void set(Object target, T value) {
+ try {
+ field.set(target, value);
+ } catch (IllegalAccessException e) {
+ throw Throwables.propagate(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("class", field.getDeclaringClass().toString())
+ .add("name", name)
+ .add("type", field.getType())
+ .toString();
+ }
+
+ /**
+ * Returns this method as a BoundMethod for the given receiver.
+ *
+ * @param target an Object on which to get or set this field
+ * @return a {@link BoundField} for this field and the target
+ * @throws IllegalStateException if the method is static
+ * @throws IllegalArgumentException if the receiver's class is incompatible
+ */
+ public BoundField<T> bind(Object target) {
+ Preconditions.checkState(
+ !isStatic() || this == AlwaysNull.INSTANCE, "Cannot bind static field %s", name);
+ Preconditions.checkArgument(
+ field.getDeclaringClass().isAssignableFrom(target.getClass()),
+ "Cannot bind field %s to instance of %s",
+ name,
+ target.getClass());
+
+ return new BoundField<>(this, target);
+ }
+
+ /**
+ * Returns this field as a StaticField.
+ *
+ * @return a {@link StaticField} for this field
+ * @throws IllegalStateException if the method is not static
+ */
+ public StaticField<T> asStatic() {
+ Preconditions.checkState(isStatic(), "Field %s is not static", name);
+ return new StaticField<>(this);
+ }
+
+ /** Returns whether the field is a static field. */
+ public boolean isStatic() {
+ return Modifier.isStatic(field.getModifiers());
+ }
+
+ /** Returns whether the field is always null. */
+ public boolean isAlwaysNull() {
+ return this == AlwaysNull.INSTANCE;
+ }
+ }
+
+ private static class AlwaysNull extends UnboundField<Void> {
+ private static final AlwaysNull INSTANCE = new AlwaysNull();
+
+ private AlwaysNull() {
+ super(null, "AlwaysNull");
+ }
+
+ @Override
+ public Void get(Object target) {
+ return null;
+ }
+
+ @Override
+ public void set(Object target, Void value) {}
+
+ @Override
+ public String toString() {
+ return "Field(AlwaysNull)";
+ }
+
+ @Override
+ public boolean isStatic() {
+ return true;
+ }
+
+ @Override
+ public boolean isAlwaysNull() {
+ return true;
+ }
+ }
+
+ public static class StaticField<T> {
+ private final UnboundField<T> field;
+
+ private StaticField(UnboundField<T> field) {
+ this.field = field;
+ }
+
+ public T get() {
+ return field.get(null);
+ }
+
+ public void set(T value) {
+ field.set(null, value);
+ }
+ }
+
+ public static class BoundField<T> {
+ private final UnboundField<T> field;
+ private final Object target;
+
+ private BoundField(UnboundField<T> field, Object target) {
+ this.field = field;
+ this.target = target;
+ }
+
+ public T get() {
+ return field.get(target);
+ }
+
+ public void set(T value) {
+ field.set(target, value);
+ }
+ }
+
+ public static class Builder {
+ private final Set<String> candidates = Sets.newHashSet();
+ private ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ private UnboundField<?> field = null;
+ private boolean defaultAlwaysNull = false;
+
+ private Builder() {}
+
+ /**
+ * Set the {@link ClassLoader} used to lookup classes by name.
+ *
+ * <p>If not set, the current thread's ClassLoader is used.
+ *
+ * @param newLoader a ClassLoader
+ * @return this Builder for method chaining
+ */
+ public Builder loader(ClassLoader newLoader) {
+ this.loader = newLoader;
+ return this;
+ }
+
+ /**
+ * Instructs this builder to return AlwaysNull if no implementation is found.
+ *
+ * @return this Builder for method chaining
+ */
+ public Builder defaultAlwaysNull() {
+ this.defaultAlwaysNull = true;
+ return this;
+ }
+
+ /**
+ * Checks for an implementation, first finding the class by name.
+ *
+ * @param className name of a class
+ * @param fieldName name of the field
+ * @return this Builder for method chaining
+ * @see Class#forName(String)
+ * @see Class#getField(String)
+ */
+ public Builder impl(String className, String fieldName) {
+ // don't do any work if an implementation has been found
+ if (field != null) {
+ return this;
+ }
+
+ try {
+ Class<?> targetClass = Class.forName(className, true, loader);
+ impl(targetClass, fieldName);
+ } catch (ClassNotFoundException e) {
+ // not the right implementation
+ candidates.add(className + "." + fieldName);
+ }
+ return this;
+ }
+
+ /**
+ * Checks for an implementation.
+ *
+ * @param targetClass a class instance
+ * @param fieldName name of a field (different from constructor)
+ * @return this Builder for method chaining
+ * @see Class#forName(String)
+ * @see Class#getField(String)
+ */
+ public Builder impl(Class<?> targetClass, String fieldName) {
+ // don't do any work if an implementation has been found
+ if (field != null || targetClass == null) {
+ return this;
+ }
+
+ try {
+ this.field = new UnboundField<>(targetClass.getField(fieldName), fieldName);
+ } catch (NoSuchFieldException e) {
+ // not the right implementation
+ candidates.add(targetClass.getName() + "." + fieldName);
+ }
+ return this;
+ }
+
+ /**
+ * Checks for a hidden implementation, first finding the class by name.
+ *
+ * @param className name of a class
+ * @param fieldName name of a field (different from constructor)
+ * @return this Builder for method chaining
+ * @see Class#forName(String)
+ * @see Class#getField(String)
+ */
+ public Builder hiddenImpl(String className, String fieldName) {
+ // don't do any work if an implementation has been found
+ if (field != null) {
+ return this;
+ }
+
+ try {
+ Class<?> targetClass = Class.forName(className, true, loader);
+ hiddenImpl(targetClass, fieldName);
+ } catch (ClassNotFoundException e) {
+ // not the right implementation
+ candidates.add(className + "." + fieldName);
+ }
+ return this;
+ }
+
+ /**
+ * Checks for a hidden implementation.
+ *
+ * @param targetClass a class instance
+ * @param fieldName name of a field (different from constructor)
+ * @return this Builder for method chaining
+ * @see Class#forName(String)
+ * @see Class#getField(String)
+ */
+ public Builder hiddenImpl(Class<?> targetClass, String fieldName) {
+ // don't do any work if an implementation has been found
+ if (field != null || targetClass == null) {
+ return this;
+ }
+
+ try {
+ Field hidden = targetClass.getDeclaredField(fieldName);
+ AccessController.doPrivileged(new MakeFieldAccessible(hidden));
+ this.field = new UnboundField(hidden, fieldName);
+ } catch (SecurityException | NoSuchFieldException e) {
+ // unusable
+ candidates.add(targetClass.getName() + "." + fieldName);
+ }
+ return this;
+ }
+
+ /**
+ * Returns the first valid implementation as a UnboundField or throws a NoSuchFieldException if
+ * there is none.
+ *
+ * @param <T> Java class stored in the field
+ * @return a {@link UnboundField} with a valid implementation
+ * @throws NoSuchFieldException if no implementation was found
+ */
+ @SuppressWarnings("unchecked")
+ public <T> UnboundField<T> buildChecked() throws NoSuchFieldException {
+ if (field != null) {
+ return (UnboundField<T>) field;
+ } else if (defaultAlwaysNull) {
+ return (UnboundField<T>) AlwaysNull.INSTANCE;
+ } else {
+ throw new NoSuchFieldException(
+ "Cannot find field from candidates: " + Joiner.on(", ").join(candidates));
+ }
+ }
+
+ /**
+ * Returns the first valid implementation as a BoundMethod or throws a NoSuchMethodException if
+ * there is none.
+ *
+ * @param target an Object on which to get and set the field
+ * @param <T> Java class stored in the field
+ * @return a {@link BoundField} with a valid implementation and target
+ * @throws IllegalStateException if the method is static
+ * @throws IllegalArgumentException if the receiver's class is incompatible
+ * @throws NoSuchFieldException if no implementation was found
+ */
+ public <T> BoundField<T> buildChecked(Object target) throws NoSuchFieldException {
+ return this.<T>buildChecked().bind(target);
+ }
+
+ /**
+ * Returns the first valid implementation as a UnboundField or throws a NoSuchFieldException if
+ * there is none.
+ *
+ * @param <T> Java class stored in the field
+ * @return a {@link UnboundField} with a valid implementation
+ * @throws RuntimeException if no implementation was found
+ */
+ @SuppressWarnings("unchecked")
+ public <T> UnboundField<T> build() {
+ if (field != null) {
+ return (UnboundField<T>) field;
+ } else if (defaultAlwaysNull) {
+ return (UnboundField<T>) AlwaysNull.INSTANCE;
+ } else {
+ throw new RuntimeException(
+ "Cannot find field from candidates: " + Joiner.on(", ").join(candidates));
+ }
+ }
+
+ /**
+ * Returns the first valid implementation as a BoundMethod or throws a RuntimeException if there
+ * is none.
+ *
+ * @param target an Object on which to get and set the field
+ * @param <T> Java class stored in the field
+ * @return a {@link BoundField} with a valid implementation and target
+ * @throws IllegalStateException if the method is static
+ * @throws IllegalArgumentException if the receiver's class is incompatible
+ * @throws RuntimeException if no implementation was found
+ */
+ public <T> BoundField<T> build(Object target) {
+ return this.<T>build().bind(target);
+ }
+
+ /**
+ * Returns the first valid implementation as a StaticField or throws a NoSuchFieldException if
+ * there is none.
+ *
+ * @param <T> Java class stored in the field
+ * @return a {@link StaticField} with a valid implementation
+ * @throws IllegalStateException if the method is not static
+ * @throws NoSuchFieldException if no implementation was found
+ */
+ public <T> StaticField<T> buildStaticChecked() throws NoSuchFieldException {
+ return this.<T>buildChecked().asStatic();
+ }
+
+ /**
+ * Returns the first valid implementation as a StaticField or throws a RuntimeException if there
+ * is none.
+ *
+ * @param <T> Java class stored in the field
+ * @return a {@link StaticField} with a valid implementation
+ * @throws IllegalStateException if the method is not static
+ * @throws RuntimeException if no implementation was found
+ */
+ public <T> StaticField<T> buildStatic() {
+ return this.<T>build().asStatic();
+ }
+ }
+
+ private static class MakeFieldAccessible implements PrivilegedAction<Void> {
+ private final Field hidden;
+
+ MakeFieldAccessible(Field hidden) {
+ this.hidden = hidden;
+ }
+
+ @Override
+ public Void run() {
+ hidden.setAccessible(true);
+ return null;
+ }
+ }
+}
diff --git a/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/dyn/DynMethods.java b/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/dyn/DynMethods.java
new file mode 100644
index 0000000000..a2114e4938
--- /dev/null
+++ b/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/dyn/DynMethods.java
@@ -0,0 +1,522 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.datastrato.graviton.catalog.hive.dyn;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Throwables;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Arrays;
+
+// common/src/main/java/org/apache/iceberg/common/DynMethods.java
+public class DynMethods {
+ private DynMethods() {}
+
+ /**
+ * Constructs a new builder for calling methods dynamically.
+ *
+ * @param methodName name of the method the builder will locate
+ * @return a Builder for finding a method
+ */
+ public static Builder builder(String methodName) {
+ return new Builder(methodName);
+ }
+
+ /**
+ * Convenience wrapper class around {@link Method}.
+ *
+ * <p>Allows callers to invoke the wrapped method with all Exceptions wrapped by RuntimeException,
+ * or with a single Exception catch block.
+ */
+ public static class UnboundMethod {
+
+ /** Singleton {@link UnboundMethod}, performs no operation and returns null. */
+ private static final UnboundMethod NOOP =
+ new UnboundMethod(null, "NOOP") {
+ @Override
+ public <R> R invokeChecked(Object target, Object... args) throws Exception {
+ return null;
+ }
+
+ @Override
+ public BoundMethod bind(Object receiver) {
+ return new BoundMethod(this, receiver);
+ }
+
+ @Override
+ public StaticMethod asStatic() {
+ return new StaticMethod(this);
+ }
+
+ @Override
+ public boolean isStatic() {
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "DynMethods.UnboundMethod(NOOP)";
+ }
+ };
+
+ private final Method method;
+ private final String name;
+ private final int argLength;
+
+ UnboundMethod(Method method, String name) {
+ this.method = method;
+ this.name = name;
+ this.argLength =
+ (method == null || method.isVarArgs()) ? -1 : method.getParameterTypes().length;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <R> R invokeChecked(Object target, Object... args) throws Exception {
+ try {
+ if (argLength < 0) {
+ return (R) method.invoke(target, args);
+ } else {
+ return (R) method.invoke(target, Arrays.copyOfRange(args, 0, argLength));
+ }
+
+ } catch (InvocationTargetException e) {
+ Throwables.propagateIfInstanceOf(e.getCause(), Exception.class);
+ Throwables.propagateIfInstanceOf(e.getCause(), RuntimeException.class);
+ throw Throwables.propagate(e.getCause());
+ }
+ }
+
+ public <R> R invoke(Object target, Object... args) {
+ try {
+ return this.invokeChecked(target, args);
+ } catch (Exception e) {
+ Throwables.propagateIfInstanceOf(e, RuntimeException.class);
+ throw Throwables.propagate(e);
+ }
+ }
+
+ /**
+ * Returns this method as a BoundMethod for the given receiver.
+ *
+ * @param receiver an Object to receive the method invocation
+ * @return a {@link BoundMethod} for this method and the receiver
+ * @throws IllegalStateException if the method is static
+ * @throws IllegalArgumentException if the receiver's class is incompatible
+ */
+ public BoundMethod bind(Object receiver) {
+ Preconditions.checkState(
+ !isStatic(), "Cannot bind static method %s", method.toGenericString());
+ Preconditions.checkArgument(
+ method.getDeclaringClass().isAssignableFrom(receiver.getClass()),
+ "Cannot bind %s to instance of %s",
+ method.toGenericString(),
+ receiver.getClass());
+
+ return new BoundMethod(this, receiver);
+ }
+
+ /** Returns whether the method is a static method. */
+ public boolean isStatic() {
+ return Modifier.isStatic(method.getModifiers());
+ }
+
+ /** Returns whether the method is a noop. */
+ public boolean isNoop() {
+ return this == NOOP;
+ }
+
+ /**
+ * Returns this method as a StaticMethod.
+ *
+ * @return a {@link StaticMethod} for this method
+ * @throws IllegalStateException if the method is not static
+ */
+ public StaticMethod asStatic() {
+ Preconditions.checkState(isStatic(), "Method is not static");
+ return new StaticMethod(this);
+ }
+
+ @Override
+ public String toString() {
+ return "DynMethods.UnboundMethod(name=" + name + " method=" + method.toGenericString() + ")";
+ }
+ }
+
+ public static class BoundMethod {
+ private final UnboundMethod method;
+ private final Object receiver;
+
+ private BoundMethod(UnboundMethod method, Object receiver) {
+ this.method = method;
+ this.receiver = receiver;
+ }
+
+ public <R> R invokeChecked(Object... args) throws Exception {
+ return method.invokeChecked(receiver, args);
+ }
+
+ public <R> R invoke(Object... args) {
+ return method.invoke(receiver, args);
+ }
+ }
+
+ public static class StaticMethod {
+ private final UnboundMethod method;
+
+ private StaticMethod(UnboundMethod method) {
+ this.method = method;
+ }
+
+ public <R> R invokeChecked(Object... args) throws Exception {
+ return method.invokeChecked(null, args);
+ }
+
+ public <R> R invoke(Object... args) {
+ return method.invoke(null, args);
+ }
+ }
+
+ public static class Builder {
+ private final String name;
+ private ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ private UnboundMethod method = null;
+
+ public Builder(String methodName) {
+ this.name = methodName;
+ }
+
+ /**
+ * Set the {@link ClassLoader} used to lookup classes by name.
+ *
+ * <p>If not set, the current thread's ClassLoader is used.
+ *
+ * @param newLoader a ClassLoader
+ * @return this Builder for method chaining
+ */
+ public Builder loader(ClassLoader newLoader) {
+ this.loader = newLoader;
+ return this;
+ }
+
+ /**
+ * If no implementation has been found, adds a NOOP method.
+ *
+ * <p>Note: calls to impl will not match after this method is called!
+ *
+ * @return this Builder for method chaining
+ */
+ public Builder orNoop() {
+ if (method == null) {
+ this.method = UnboundMethod.NOOP;
+ }
+ return this;
+ }
+
+ /**
+ * Checks for an implementation, first finding the given class by name.
+ *
+ * @param className name of a class
+ * @param methodName name of a method (different from constructor)
+ * @param argClasses argument classes for the method
+ * @return this Builder for method chaining
+ * @see Class#forName(String)
+ * @see Class#getMethod(String, Class[])
+ */
+ public Builder impl(String className, String methodName, Class<?>... argClasses) {
+ // don't do any work if an implementation has been found
+ if (method != null) {
+ return this;
+ }
+
+ try {
+ Class<?> targetClass = Class.forName(className, true, loader);
+ impl(targetClass, methodName, argClasses);
+ } catch (ClassNotFoundException e) {
+ // not the right implementation
+ }
+ return this;
+ }
+
+ /**
+ * Checks for an implementation, first finding the given class by name.
+ *
+ * <p>The name passed to the constructor is the method name used.
+ *
+ * @param className name of a class
+ * @param argClasses argument classes for the method
+ * @return this Builder for method chaining
+ * @see Class#forName(String)
+ * @see Class#getMethod(String, Class[])
+ */
+ public Builder impl(String className, Class<?>... argClasses) {
+ impl(className, name, argClasses);
+ return this;
+ }
+
+ /**
+ * Checks for a method implementation.
+ *
+ * @param targetClass a class instance
+ * @param methodName name of a method (different from constructor)
+ * @param argClasses argument classes for the method
+ * @return this Builder for method chaining
+ * @see Class#forName(String)
+ * @see Class#getMethod(String, Class[])
+ */
+ public Builder impl(Class<?> targetClass, String methodName, Class<?>... argClasses) {
+ // don't do any work if an implementation has been found
+ if (method != null) {
+ return this;
+ }
+
+ try {
+ this.method = new UnboundMethod(targetClass.getMethod(methodName, argClasses), name);
+ } catch (NoSuchMethodException e) {
+ // not the right implementation
+ }
+ return this;
+ }
+
+ /**
+ * Checks for a method implementation.
+ *
+ * <p>The name passed to the constructor is the method name used.
+ *
+ * @param targetClass a class instance
+ * @param argClasses argument classes for the method
+ * @return this Builder for method chaining
+ * @see Class#forName(String)
+ * @see Class#getMethod(String, Class[])
+ */
+ public Builder impl(Class<?> targetClass, Class<?>... argClasses) {
+ impl(targetClass, name, argClasses);
+ return this;
+ }
+
+ public Builder ctorImpl(Class<?> targetClass, Class<?>... argClasses) {
+ // don't do any work if an implementation has been found
+ if (method != null) {
+ return this;
+ }
+
+ try {
+ this.method = new DynConstructors.Builder().impl(targetClass, argClasses).buildChecked();
+ } catch (NoSuchMethodException e) {
+ // not the right implementation
+ }
+ return this;
+ }
+
+ public Builder ctorImpl(String className, Class<?>... argClasses) {
+ // don't do any work if an implementation has been found
+ if (method != null) {
+ return this;
+ }
+
+ try {
+ this.method = new DynConstructors.Builder().impl(className, argClasses).buildChecked();
+ } catch (NoSuchMethodException e) {
+ // not the right implementation
+ }
+ return this;
+ }
+
+ /**
+ * Checks for an implementation, first finding the given class by name.
+ *
+ * @param className name of a class
+ * @param methodName name of a method (different from constructor)
+ * @param argClasses argument classes for the method
+ * @return this Builder for method chaining
+ * @see Class#forName(String)
+ * @see Class#getMethod(String, Class[])
+ */
+ public Builder hiddenImpl(String className, String methodName, Class<?>... argClasses) {
+ // don't do any work if an implementation has been found
+ if (method != null) {
+ return this;
+ }
+
+ try {
+ Class<?> targetClass = Class.forName(className, true, loader);
+ hiddenImpl(targetClass, methodName, argClasses);
+ } catch (ClassNotFoundException e) {
+ // not the right implementation
+ }
+ return this;
+ }
+
+ /**
+ * Checks for an implementation, first finding the given class by name.
+ *
+ * <p>The name passed to the constructor is the method name used.
+ *
+ * @param className name of a class
+ * @param argClasses argument classes for the method
+ * @return this Builder for method chaining
+ * @see Class#forName(String)
+ * @see Class#getMethod(String, Class[])
+ */
+ public Builder hiddenImpl(String className, Class<?>... argClasses) {
+ hiddenImpl(className, name, argClasses);
+ return this;
+ }
+
+ /**
+ * Checks for a method implementation.
+ *
+ * @param targetClass a class instance
+ * @param methodName name of a method (different from constructor)
+ * @param argClasses argument classes for the method
+ * @return this Builder for method chaining
+ * @see Class#forName(String)
+ * @see Class#getMethod(String, Class[])
+ */
+ public Builder hiddenImpl(Class<?> targetClass, String methodName, Class<?>... argClasses) {
+ // don't do any work if an implementation has been found
+ if (method != null) {
+ return this;
+ }
+
+ try {
+ Method hidden = targetClass.getDeclaredMethod(methodName, argClasses);
+ AccessController.doPrivileged(new MakeAccessible(hidden));
+ this.method = new UnboundMethod(hidden, name);
+ } catch (SecurityException | NoSuchMethodException e) {
+ // unusable or not the right implementation
+ }
+ return this;
+ }
+
+ /**
+ * Checks for a method implementation.
+ *
+ * <p>The name passed to the constructor is the method name used.
+ *
+ * @param targetClass a class instance
+ * @param argClasses argument classes for the method
+ * @return this Builder for method chaining
+ * @see Class#forName(String)
+ * @see Class#getMethod(String, Class[])
+ */
+ public Builder hiddenImpl(Class<?> targetClass, Class<?>... argClasses) {
+ hiddenImpl(targetClass, name, argClasses);
+ return this;
+ }
+
+ /**
+ * Returns the first valid implementation as a UnboundMethod or throws a RuntimeError if there
+ * is none.
+ *
+ * @return a {@link UnboundMethod} with a valid implementation
+ * @throws RuntimeException if no implementation was found
+ */
+ public UnboundMethod build() {
+ if (method != null) {
+ return method;
+ } else {
+ throw new RuntimeException("Cannot find method: " + name);
+ }
+ }
+
+ /**
+ * Returns the first valid implementation as a BoundMethod or throws a RuntimeError if there is
+ * none.
+ *
+ * @param receiver an Object to receive the method invocation
+ * @return a {@link BoundMethod} with a valid implementation and receiver
+ * @throws IllegalStateException if the method is static
+ * @throws IllegalArgumentException if the receiver's class is incompatible
+ * @throws RuntimeException if no implementation was found
+ */
+ public BoundMethod build(Object receiver) {
+ return build().bind(receiver);
+ }
+
+ /**
+ * Returns the first valid implementation as a UnboundMethod or throws a NoSuchMethodException
+ * if there is none.
+ *
+ * @return a {@link UnboundMethod} with a valid implementation
+ * @throws NoSuchMethodException if no implementation was found
+ */
+ public UnboundMethod buildChecked() throws NoSuchMethodException {
+ if (method != null) {
+ return method;
+ } else {
+ throw new NoSuchMethodException("Cannot find method: " + name);
+ }
+ }
+
+ /**
+ * Returns the first valid implementation as a BoundMethod or throws a NoSuchMethodException if
+ * there is none.
+ *
+ * @param receiver an Object to receive the method invocation
+ * @return a {@link BoundMethod} with a valid implementation and receiver
+ * @throws IllegalStateException if the method is static
+ * @throws IllegalArgumentException if the receiver's class is incompatible
+ * @throws NoSuchMethodException if no implementation was found
+ */
+ public BoundMethod buildChecked(Object receiver) throws NoSuchMethodException {
+ return buildChecked().bind(receiver);
+ }
+
+ /**
+ * Returns the first valid implementation as a StaticMethod or throws a NoSuchMethodException if
+ * there is none.
+ *
+ * @return a {@link StaticMethod} with a valid implementation
+ * @throws IllegalStateException if the method is not static
+ * @throws NoSuchMethodException if no implementation was found
+ */
+ public StaticMethod buildStaticChecked() throws NoSuchMethodException {
+ return buildChecked().asStatic();
+ }
+
+ /**
+ * Returns the first valid implementation as a StaticMethod or throws a RuntimeException if
+ * there is none.
+ *
+ * @return a {@link StaticMethod} with a valid implementation
+ * @throws IllegalStateException if the method is not static
+ * @throws RuntimeException if no implementation was found
+ */
+ public StaticMethod buildStatic() {
+ return build().asStatic();
+ }
+ }
+
+ private static class MakeAccessible implements PrivilegedAction<Void> {
+ private final Method hidden;
+
+ MakeAccessible(Method hidden) {
+ this.hidden = hidden;
+ }
+
+ @Override
+ public Void run() {
+ hidden.setAccessible(true);
+ return null;
+ }
+ }
+}
diff --git a/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/HiveCatalogTest.java b/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/HiveCatalogTest.java
new file mode 100644
index 0000000000..bc7fbb1081
--- /dev/null
+++ b/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/HiveCatalogTest.java
@@ -0,0 +1,36 @@
+package com.datastrato.graviton.catalog.hive;
+
+import com.datastrato.graviton.Namespace;
+import com.datastrato.graviton.catalog.hive.miniHMS.MiniHiveMetastoreService;
+import com.datastrato.graviton.meta.AuditInfo;
+import java.time.Instant;
+import java.util.List;
+import org.apache.thrift.TException;
+import org.junit.Assert;
+import org.junit.jupiter.api.Test;
+
+public class HiveCatalogTest extends MiniHiveMetastoreService {
+ @Test
+ public void listDatabases() throws TException, InterruptedException {
+ AuditInfo auditInfo =
+ new AuditInfo.Builder().withCreator("creator").withCreateTime(Instant.now()).build();
+
+ HiveCatalog hiveCatalog =
+ new HiveCatalog.Builder()
+ .withId(1L)
+ .withName("catalog")
+ .withNamespace(Namespace.of("lakehouse"))
+ .withType(HiveCatalog.Type.RELATIONAL)
+ .withLakehouseId(1L)
+ .withAuditInfo(auditInfo)
+ .withHiveConf(metastore.hiveConf())
+ .build();
+
+ hiveCatalog.initialize(null);
+
+ List<String> dbs = hiveCatalog.clientPool.run(client -> client.getAllDatabases());
+ Assert.assertEquals(2, dbs.size());
+ Assert.assertTrue(dbs.contains("default"));
+ Assert.assertTrue(dbs.contains(DB_NAME));
+ }
+}
diff --git a/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/miniHMS/MiniHiveMetastore.java b/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/miniHMS/MiniHiveMetastore.java
new file mode 100644
index 0000000000..6b880546fe
--- /dev/null
+++ b/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/miniHMS/MiniHiveMetastore.java
@@ -0,0 +1,279 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.datastrato.graviton.catalog.hive.miniHMS;
+
+import static java.nio.file.Files.createTempDirectory;
+import static java.nio.file.attribute.PosixFilePermissions.asFileAttribute;
+import static java.nio.file.attribute.PosixFilePermissions.fromString;
+
+import com.datastrato.graviton.catalog.hive.HiveClientPool;
+import com.datastrato.graviton.catalog.hive.dyn.DynConstructors;
+import com.datastrato.graviton.catalog.hive.dyn.DynMethods;
+import java.io.*;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.HiveMetaStore;
+import org.apache.hadoop.hive.metastore.IHMSHandler;
+import org.apache.hadoop.hive.metastore.RetryingHMSHandler;
+import org.apache.hadoop.hive.metastore.TSetIpAddressProcessor;
+import org.apache.thrift.protocol.TBinaryProtocol;
+import org.apache.thrift.server.TServer;
+import org.apache.thrift.server.TThreadPoolServer;
+import org.apache.thrift.transport.TServerSocket;
+import org.apache.thrift.transport.TTransportFactory;
+import org.junit.Assert;
+
+// hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java
+public class MiniHiveMetastore {
+
+ private static final String DEFAULT_DATABASE_NAME = "default";
+ private static final int DEFAULT_POOL_SIZE = 5;
+
+ // create the metastore handlers based on whether we're working with Hive2 or Hive3 dependencies
+ // we need to do this because there is a breaking API change between Hive2 and Hive3
+ private static final DynConstructors.Ctor<HiveMetaStore.HMSHandler> HMS_HANDLER_CTOR =
+ DynConstructors.builder()
+ .impl(HiveMetaStore.HMSHandler.class, String.class, Configuration.class)
+ .impl(HiveMetaStore.HMSHandler.class, String.class, HiveConf.class)
+ .build();
+
+ private static final DynMethods.StaticMethod GET_BASE_HMS_HANDLER =
+ DynMethods.builder("getProxy")
+ .impl(RetryingHMSHandler.class, Configuration.class, IHMSHandler.class, boolean.class)
+ .impl(RetryingHMSHandler.class, HiveConf.class, IHMSHandler.class, boolean.class)
+ .buildStatic();
+
+ // Hive3 introduces background metastore tasks (MetastoreTaskThread) for performing various
+ // cleanup duties. These
+ // threads are scheduled and executed in a static thread pool
+ // (org.apache.hadoop.hive.metastore.ThreadPool).
+ // This thread pool is shut down normally as part of the JVM shutdown hook, but since we're
+ // creating and tearing down
+ // multiple metastore instances within the same JVM, we have to call this cleanup method manually,
+ // otherwise
+ // threads from our previous test suite will be stuck in the pool with stale config, and keep on
+ // being scheduled.
+ // This can lead to issues, e.g. accidental Persistence Manager closure by
+ // ScheduledQueryExecutionsMaintTask.
+ private static final DynMethods.StaticMethod METASTORE_THREADS_SHUTDOWN =
+ DynMethods.builder("shutdown")
+ .impl("org.apache.hadoop.hive.metastore.ThreadPool")
+ .orNoop()
+ .buildStatic();
+
+ // It's tricky to clear all static fields in an HMS instance in order to switch derby root dir.
+ // Therefore, we reuse the same derby root between tests and remove it after JVM exits.
+ private static final File HIVE_LOCAL_DIR;
+ private static final String DERBY_PATH;
+
+ static {
+ try {
+ HIVE_LOCAL_DIR =
+ createTempDirectory("hive", asFileAttribute(fromString("rwxrwxrwx"))).toFile();
+ DERBY_PATH = new File(HIVE_LOCAL_DIR, "metastore_db").getPath();
+ File derbyLogFile = new File(HIVE_LOCAL_DIR, "derby.log");
+ System.setProperty("derby.stream.error.file", derbyLogFile.getAbsolutePath());
+ setupMetastoreDB("jdbc:derby:" + DERBY_PATH + ";create=true");
+ Runtime.getRuntime()
+ .addShutdownHook(
+ new Thread(
+ () -> {
+ Path localDirPath = new Path(HIVE_LOCAL_DIR.getAbsolutePath());
+ FileSystem fs = getFs(localDirPath, new Configuration());
+ String errMsg = "Failed to delete " + localDirPath;
+ try {
+ Assert.assertTrue(errMsg, fs.delete(localDirPath, true));
+ } catch (IOException e) {
+ throw new RuntimeException(errMsg, e);
+ }
+ }));
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to setup local dir for hive metastore", e);
+ }
+ }
+
+ private HiveConf hiveConf;
+ private ExecutorService executorService;
+ private TServer server;
+ private HiveMetaStore.HMSHandler baseHandler;
+ private HiveClientPool clientPool;
+
+ public static FileSystem getFs(Path path, Configuration conf) {
+ try {
+ return path.getFileSystem(conf);
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to get file system for path: " + path, e);
+ }
+ }
+
+ private static void setupMetastoreDB(String dbURL) throws SQLException, IOException {
+ Connection connection = DriverManager.getConnection(dbURL);
+ ScriptRunner scriptRunner = new ScriptRunner(connection, true, true);
+
+ ClassLoader classLoader = ClassLoader.getSystemClassLoader();
+ InputStream inputStream = classLoader.getResourceAsStream("hive-schema-3.1.0.derby.sql");
+ try (Reader reader = new InputStreamReader(inputStream)) {
+ scriptRunner.runScript(reader);
+ }
+ }
+
+ /**
+ * Starts a TestHiveMetastore with the default connection pool size (5) and the default HiveConf.
+ */
+ public void start() {
+ start(new HiveConf(new Configuration(), MiniHiveMetastore.class), DEFAULT_POOL_SIZE);
+ }
+
+ /**
+ * Starts a TestHiveMetastore with the default connection pool size (5) with the provided
+ * HiveConf.
+ *
+ * @param conf The hive configuration to use
+ */
+ public void start(HiveConf conf) {
+ start(conf, DEFAULT_POOL_SIZE);
+ }
+
+ /**
+ * Starts a TestHiveMetastore with a provided connection pool size and HiveConf.
+ *
+ * @param conf The hive configuration to use
+ * @param poolSize The number of threads in the executor pool
+ */
+ public void start(HiveConf conf, int poolSize) {
+ try {
+ TServerSocket socket = new TServerSocket(0);
+ int port = socket.getServerSocket().getLocalPort();
+ initConf(conf, port);
+
+ this.hiveConf = conf;
+ this.server = newThriftServer(socket, poolSize, hiveConf);
+ this.executorService = Executors.newSingleThreadExecutor();
+ this.executorService.submit(() -> server.serve());
+
+ // in Hive3, setting this as a system prop ensures that it will be picked up
+ // whenever a new HiveConf is created
+ System.setProperty(
+ HiveConf.ConfVars.METASTOREURIS.varname,
+ hiveConf.getVar(HiveConf.ConfVars.METASTOREURIS));
+
+ this.clientPool = new HiveClientPool(1, hiveConf);
+ } catch (Exception e) {
+ throw new RuntimeException("Cannot start TestHiveMetastore", e);
+ }
+ }
+
+ public void stop() throws Exception {
+ reset();
+ if (clientPool != null) {
+ clientPool.close();
+ }
+ if (server != null) {
+ server.stop();
+ }
+ if (executorService != null) {
+ executorService.shutdown();
+ }
+ if (baseHandler != null) {
+ baseHandler.shutdown();
+ }
+ METASTORE_THREADS_SHUTDOWN.invoke();
+ }
+
+ public HiveConf hiveConf() {
+ return hiveConf;
+ }
+
+ public String getDatabasePath(String dbName) {
+ File dbDir = new File(HIVE_LOCAL_DIR, dbName + ".db");
+ return dbDir.getPath();
+ }
+
+ public void reset() throws Exception {
+ if (clientPool != null) {
+ for (String dbName : clientPool.run(client -> client.getAllDatabases())) {
+ for (String tblName : clientPool.run(client -> client.getAllTables(dbName))) {
+ clientPool.run(
+ client -> {
+ client.dropTable(dbName, tblName, true, true, true);
+ return null;
+ });
+ }
+
+ if (!DEFAULT_DATABASE_NAME.equals(dbName)) {
+ // Drop cascade, functions dropped by cascade
+ clientPool.run(
+ client -> {
+ client.dropDatabase(dbName, true, true, true);
+ return null;
+ });
+ }
+ }
+ }
+
+ Path warehouseRoot = new Path(HIVE_LOCAL_DIR.getAbsolutePath());
+ FileSystem fs = getFs(warehouseRoot, hiveConf);
+ for (FileStatus fileStatus : fs.listStatus(warehouseRoot)) {
+ if (!fileStatus.getPath().getName().equals("derby.log")
+ && !fileStatus.getPath().getName().equals("metastore_db")) {
+ fs.delete(fileStatus.getPath(), true);
+ }
+ }
+ }
+
+ private TServer newThriftServer(TServerSocket socket, int poolSize, HiveConf conf)
+ throws Exception {
+ HiveConf serverConf = new HiveConf(conf);
+ serverConf.set(
+ HiveConf.ConfVars.METASTORECONNECTURLKEY.varname,
+ "jdbc:derby:" + DERBY_PATH + ";create=true");
+ baseHandler = HMS_HANDLER_CTOR.newInstance("new db based metaserver", serverConf);
+ IHMSHandler handler = GET_BASE_HMS_HANDLER.invoke(serverConf, baseHandler, false);
+
+ TThreadPoolServer.Args args =
+ new TThreadPoolServer.Args(socket)
+ .processor(new TSetIpAddressProcessor<>(handler))
+ .transportFactory(new TTransportFactory())
+ .protocolFactory(new TBinaryProtocol.Factory())
+ .minWorkerThreads(poolSize)
+ .maxWorkerThreads(poolSize);
+
+ return new TThreadPoolServer(args);
+ }
+
+ private void initConf(HiveConf conf, int port) {
+ conf.set(HiveConf.ConfVars.METASTOREURIS.varname, "thrift://localhost:" + port);
+ conf.set(
+ HiveConf.ConfVars.METASTOREWAREHOUSE.varname, "file:" + HIVE_LOCAL_DIR.getAbsolutePath());
+ conf.set(HiveConf.ConfVars.METASTORE_TRY_DIRECT_SQL.varname, "false");
+ conf.set(HiveConf.ConfVars.METASTORE_DISALLOW_INCOMPATIBLE_COL_TYPE_CHANGES.varname, "false");
+ conf.set("iceberg.hive.client-pool-size", "2");
+ // Setting this to avoid thrift exception during running Iceberg tests outside Iceberg.
+ conf.set(
+ HiveConf.ConfVars.HIVE_IN_TEST.varname, HiveConf.ConfVars.HIVE_IN_TEST.getDefaultValue());
+ }
+}
diff --git a/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/miniHMS/MiniHiveMetastoreService.java b/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/miniHMS/MiniHiveMetastoreService.java
new file mode 100644
index 0000000000..d9bac3588f
--- /dev/null
+++ b/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/miniHMS/MiniHiveMetastoreService.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.datastrato.graviton.catalog.hive.miniHMS;
+
+import com.google.common.collect.Maps;
+import java.util.Collections;
+import java.util.Map;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.Database;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// hive-metastore/src/test/java/org/apache/iceberg/hive/HiveMetastoreTest.java
+public abstract class MiniHiveMetastoreService {
+ public static final Logger LOG = LoggerFactory.getLogger(MiniHiveMetastoreService.class);
+ protected static final String DB_NAME = "hivedb";
+
+ protected static HiveMetaStoreClient metastoreClient;
+
+ protected static HiveConf hiveConf;
+ protected static MiniHiveMetastore metastore;
+
+ @BeforeAll
+ public static void startMetastore() throws Exception {
+ startMetastore(Collections.emptyMap());
+ }
+
+ public static void startMetastore(Map<String, String> hiveConfOverride) throws Exception {
+ LOG.info("Starting Hive Metastore");
+ MiniHiveMetastoreService.metastore = new MiniHiveMetastore();
+ HiveConf hiveConfWithOverrides = new HiveConf(MiniHiveMetastore.class);
+ if (hiveConfOverride != null) {
+ for (Map.Entry<String, String> kv : hiveConfOverride.entrySet()) {
+ hiveConfWithOverrides.set(kv.getKey(), kv.getValue());
+ }
+ }
+
+ metastore.start(hiveConfWithOverrides);
+ MiniHiveMetastoreService.hiveConf = metastore.hiveConf();
+ MiniHiveMetastoreService.metastoreClient = new HiveMetaStoreClient(hiveConfWithOverrides);
+ String dbPath = metastore.getDatabasePath(DB_NAME);
+ Database db = new Database(DB_NAME, "description", dbPath, Maps.newHashMap());
+ metastoreClient.createDatabase(db);
+ }
+
+ @AfterAll
+ public static void stopMetastore() throws Exception {
+ LOG.info("Stop Hive Metastore");
+ metastoreClient.close();
+ MiniHiveMetastoreService.metastoreClient = null;
+
+ metastore.stop();
+ MiniHiveMetastoreService.metastore = null;
+ }
+}
diff --git a/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/miniHMS/ScriptRunner.java b/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/miniHMS/ScriptRunner.java
new file mode 100644
index 0000000000..d6fcc7c6fd
--- /dev/null
+++ b/catalog-hive/src/test/java/com/datastrato/graviton/catalog/hive/miniHMS/ScriptRunner.java
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.datastrato.graviton.catalog.hive.miniHMS;
+
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.sql.*;
+
+// hive-metastore/src/test/java/org/apache/iceberg/hive/ScriptRunner.java
+
+/** Tool to run database scripts */
+public class ScriptRunner {
+
+ private static final String DEFAULT_DELIMITER = ";";
+
+ private final Connection connection;
+
+ private final boolean stopOnError;
+ private final boolean autoCommit;
+
+ private final PrintWriter logWriter = new PrintWriter(System.out);
+ private final PrintWriter errorLogWriter = new PrintWriter(System.err);
+
+ private String delimiter = DEFAULT_DELIMITER;
+ private boolean fullLineDelimiter = false;
+
+ /** Default constructor */
+ public ScriptRunner(Connection connection, boolean autoCommit, boolean stopOnError) {
+ this.connection = connection;
+ this.autoCommit = autoCommit;
+ this.stopOnError = stopOnError;
+ }
+
+ public void setDelimiter(String newDelimiter, boolean newFullLineDelimiter) {
+ this.delimiter = newDelimiter;
+ this.fullLineDelimiter = newFullLineDelimiter;
+ }
+
+ /**
+ * Runs an SQL script (read in using the Reader parameter)
+ *
+ * @param reader - the source of the script
+ */
+ public void runScript(Reader reader) throws IOException, SQLException {
+ try {
+ boolean originalAutoCommit = connection.getAutoCommit();
+ try {
+ if (originalAutoCommit != this.autoCommit) {
+ connection.setAutoCommit(this.autoCommit);
+ }
+ runScript(connection, reader);
+ } finally {
+ connection.setAutoCommit(originalAutoCommit);
+ }
+ } catch (IOException | SQLException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new RuntimeException("Error running script. Cause: " + e, e);
+ }
+ }
+
+ /**
+ * Runs an SQL script (read in using the Reader parameter) using the connection passed in
+ *
+ * @param conn - the connection to use for the script
+ * @param reader - the source of the script
+ * @throws SQLException if any SQL errors occur
+ * @throws IOException if there is an error reading from the Reader
+ */
+ @SuppressWarnings("checkstyle:CyclomaticComplexity")
+ private void runScript(Connection conn, Reader reader) throws IOException, SQLException {
+ StringBuilder command = null;
+ try {
+ LineNumberReader lineReader = new LineNumberReader(reader);
+ String line = null;
+ while ((line = lineReader.readLine()) != null) {
+ if (command == null) {
+ command = new StringBuilder();
+ }
+ String trimmedLine = line.trim();
+ if (trimmedLine.startsWith("--")) {
+ println(trimmedLine);
+ } else if (trimmedLine.length() < 1 || trimmedLine.startsWith("//")) {
+ // Do nothing
+ } else if (trimmedLine.length() < 1 || trimmedLine.startsWith("--")) {
+ // Do nothing
+ } else if (!fullLineDelimiter && trimmedLine.endsWith(getDelimiter())
+ || fullLineDelimiter && trimmedLine.equals(getDelimiter())) {
+ command.append(line, 0, line.lastIndexOf(getDelimiter()));
+ command.append(" ");
+ Statement statement = conn.createStatement();
+
+ println(command);
+
+ boolean hasResults = false;
+ if (stopOnError) {
+ hasResults = statement.execute(command.toString());
+ } else {
+ try {
+ statement.execute(command.toString());
+ } catch (SQLException e) {
+ e.fillInStackTrace();
+ printlnError("Error executing: " + command);
+ printlnError(e);
+ }
+ }
+
+ if (autoCommit && !conn.getAutoCommit()) {
+ conn.commit();
+ }
+
+ ResultSet rs = statement.getResultSet();
+ if (hasResults && rs != null) {
+ ResultSetMetaData md = rs.getMetaData();
+ int cols = md.getColumnCount();
+ for (int i = 0; i < cols; i++) {
+ String name = md.getColumnLabel(i);
+ print(name + "\t");
+ }
+ println("");
+ while (rs.next()) {
+ for (int i = 0; i < cols; i++) {
+ String value = rs.getString(i);
+ print(value + "\t");
+ }
+ println("");
+ }
+ }
+
+ command = null;
+ try {
+ statement.close();
+ } catch (Exception e) {
+ // Ignore to workaround a bug in Jakarta DBCP
+ }
+ Thread.yield();
+ } else {
+ command.append(line);
+ command.append(" ");
+ }
+ }
+ if (!autoCommit) {
+ conn.commit();
+ }
+ } catch (IOException | SQLException e) {
+ e.fillInStackTrace();
+ printlnError("Error executing: " + command);
+ printlnError(e);
+ throw e;
+ } finally {
+ conn.rollback();
+ flush();
+ }
+ }
+
+ private String getDelimiter() {
+ return delimiter;
+ }
+
+ private void print(Object obj) {
+ if (logWriter != null) {
+ System.out.print(obj);
+ }
+ }
+
+ private void println(Object obj) {
+ if (logWriter != null) {
+ logWriter.println(obj);
+ }
+ }
+
+ private void printlnError(Object obj) {
+ if (errorLogWriter != null) {
+ errorLogWriter.println(obj);
+ }
+ }
+
+ private void flush() {
+ if (logWriter != null) {
+ logWriter.flush();
+ }
+ if (errorLogWriter != null) {
+ errorLogWriter.flush();
+ }
+ }
+}
diff --git a/catalog-hive/src/test/resources/hive-schema-3.1.0.derby.sql b/catalog-hive/src/test/resources/hive-schema-3.1.0.derby.sql
new file mode 100644
index 0000000000..55097d6639
--- /dev/null
+++ b/catalog-hive/src/test/resources/hive-schema-3.1.0.derby.sql
@@ -0,0 +1,726 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- This file was copied from Apache Hive, at:
+-- https://github.com/apache/hive/blob/master/standalone-metastore/metastore-server/src/main/sql/derby/hive-schema-3.1.0.derby.sql
+--
+-- This has been modified slightly for compatibility with older Hive versions.
+--
+-- Timestamp: 2011-09-22 15:32:02.024
+-- Source database is: /home/carl/Work/repos/hive1/metastore/scripts/upgrade/derby/mdb
+-- Connection URL is: jdbc:derby:/home/carl/Work/repos/hive1/metastore/scripts/upgrade/derby/mdb
+-- Specified schema is: APP
+-- appendLogs: false
+
+-- ----------------------------------------------
+-- DDL Statements for functions
+-- ----------------------------------------------
+
+CREATE FUNCTION "APP"."NUCLEUS_ASCII" (C CHAR(1)) RETURNS INTEGER LANGUAGE JAVA PARAMETER STYLE JAVA READS SQL DATA CALLED ON NULL INPUT EXTERNAL NAME 'org.datanucleus.store.rdbms.adapter.DerbySQLFunction.ascii' ;
+
+CREATE FUNCTION "APP"."NUCLEUS_MATCHES" (TEXT VARCHAR(8000),PATTERN VARCHAR(8000)) RETURNS INTEGER LANGUAGE JAVA PARAMETER STYLE JAVA READS SQL DATA CALLED ON NULL INPUT EXTERNAL NAME 'org.datanucleus.store.rdbms.adapter.DerbySQLFunction.matches' ;
+
+-- ----------------------------------------------
+-- DDL Statements for tables
+-- ----------------------------------------------
+CREATE TABLE "APP"."DBS" (
+ "DB_ID" BIGINT NOT NULL,
+ "DESC" VARCHAR(4000),
+ "DB_LOCATION_URI" VARCHAR(4000) NOT NULL,
+ "NAME" VARCHAR(128),
+ "OWNER_NAME" VARCHAR(128),
+ "OWNER_TYPE" VARCHAR(10),
+ "CTLG_NAME" VARCHAR(256)
+);
+
+CREATE TABLE "APP"."TBL_PRIVS" ("TBL_GRANT_ID" BIGINT NOT NULL, "CREATE_TIME" INTEGER NOT NULL, "GRANT_OPTION" SMALLINT NOT NULL, "GRANTOR" VARCHAR(128), "GRANTOR_TYPE" VARCHAR(128), "PRINCIPAL_NAME" VARCHAR(128), "PRINCIPAL_TYPE" VARCHAR(128), "TBL_PRIV" VARCHAR(128), "TBL_ID" BIGINT, "AUTHORIZER" VARCHAR(128));
+
+CREATE TABLE "APP"."DATABASE_PARAMS" ("DB_ID" BIGINT NOT NULL, "PARAM_KEY" VARCHAR(180) NOT NULL, "PARAM_VALUE" VARCHAR(4000));
+
+CREATE TABLE "APP"."TBL_COL_PRIVS" ("TBL_COLUMN_GRANT_ID" BIGINT NOT NULL, "COLUMN_NAME" VARCHAR(767), "CREATE_TIME" INTEGER NOT NULL, "GRANT_OPTION" SMALLINT NOT NULL, "GRANTOR" VARCHAR(128), "GRANTOR_TYPE" VARCHAR(128), "PRINCIPAL_NAME" VARCHAR(128), "PRINCIPAL_TYPE" VARCHAR(128), "TBL_COL_PRIV" VARCHAR(128), "TBL_ID" BIGINT, "AUTHORIZER" VARCHAR(128));
+
+CREATE TABLE "APP"."SERDE_PARAMS" ("SERDE_ID" BIGINT NOT NULL, "PARAM_KEY" VARCHAR(256) NOT NULL, "PARAM_VALUE" CLOB);
+
+CREATE TABLE "APP"."COLUMNS_V2" ("CD_ID" BIGINT NOT NULL, "COMMENT" VARCHAR(4000), "COLUMN_NAME" VARCHAR(767) NOT NULL, "TYPE_NAME" CLOB, "INTEGER_IDX" INTEGER NOT NULL);
+
+CREATE TABLE "APP"."SORT_COLS" ("SD_ID" BIGINT NOT NULL, "COLUMN_NAME" VARCHAR(767), "ORDER" INTEGER NOT NULL, "INTEGER_IDX" INTEGER NOT NULL);
+
+CREATE TABLE "APP"."CDS" ("CD_ID" BIGINT NOT NULL);
+
+CREATE TABLE "APP"."PARTITION_KEY_VALS" ("PART_ID" BIGINT NOT NULL, "PART_KEY_VAL" VARCHAR(256), "INTEGER_IDX" INTEGER NOT NULL);
+
+CREATE TABLE "APP"."DB_PRIVS" ("DB_GRANT_ID" BIGINT NOT NULL, "CREATE_TIME" INTEGER NOT NULL, "DB_ID" BIGINT, "GRANT_OPTION" SMALLINT NOT NULL, "GRANTOR" VARCHAR(128), "GRANTOR_TYPE" VARCHAR(128), "PRINCIPAL_NAME" VARCHAR(128), "PRINCIPAL_TYPE" VARCHAR(128), "DB_PRIV" VARCHAR(128), "AUTHORIZER" VARCHAR(128));
+
+CREATE TABLE "APP"."IDXS" ("INDEX_ID" BIGINT NOT NULL, "CREATE_TIME" INTEGER NOT NULL, "DEFERRED_REBUILD" CHAR(1) NOT NULL, "INDEX_HANDLER_CLASS" VARCHAR(4000), "INDEX_NAME" VARCHAR(128), "INDEX_TBL_ID" BIGINT, "LAST_ACCESS_TIME" INTEGER NOT NULL, "ORIG_TBL_ID" BIGINT, "SD_ID" BIGINT);
+
+CREATE TABLE "APP"."INDEX_PARAMS" ("INDEX_ID" BIGINT NOT NULL, "PARAM_KEY" VARCHAR(256) NOT NULL, "PARAM_VALUE" VARCHAR(4000));
+
+CREATE TABLE "APP"."PARTITIONS" ("PART_ID" BIGINT NOT NULL, "CREATE_TIME" INTEGER NOT NULL, "LAST_ACCESS_TIME" INTEGER NOT NULL, "PART_NAME" VARCHAR(767), "SD_ID" BIGINT, "TBL_ID" BIGINT);
+
+CREATE TABLE "APP"."SERDES" ("SERDE_ID" BIGINT NOT NULL, "NAME" VARCHAR(128), "SLIB" VARCHAR(4000), "DESCRIPTION" VARCHAR(4000), "SERIALIZER_CLASS" VARCHAR(4000), "DESERIALIZER_CLASS" VARCHAR(4000), SERDE_TYPE INTEGER);
+
+CREATE TABLE "APP"."PART_PRIVS" ("PART_GRANT_ID" BIGINT NOT NULL, "CREATE_TIME" INTEGER NOT NULL, "GRANT_OPTION" SMALLINT NOT NULL, "GRANTOR" VARCHAR(128), "GRANTOR_TYPE" VARCHAR(128), "PART_ID" BIGINT, "PRINCIPAL_NAME" VARCHAR(128), "PRINCIPAL_TYPE" VARCHAR(128), "PART_PRIV" VARCHAR(128), "AUTHORIZER" VARCHAR(128));
+
+CREATE TABLE "APP"."ROLE_MAP" ("ROLE_GRANT_ID" BIGINT NOT NULL, "ADD_TIME" INTEGER NOT NULL, "GRANT_OPTION" SMALLINT NOT NULL, "GRANTOR" VARCHAR(128), "GRANTOR_TYPE" VARCHAR(128), "PRINCIPAL_NAME" VARCHAR(128), "PRINCIPAL_TYPE" VARCHAR(128), "ROLE_ID" BIGINT);
+
+CREATE TABLE "APP"."TYPES" ("TYPES_ID" BIGINT NOT NULL, "TYPE_NAME" VARCHAR(128), "TYPE1" VARCHAR(767), "TYPE2" VARCHAR(767));
+
+CREATE TABLE "APP"."GLOBAL_PRIVS" ("USER_GRANT_ID" BIGINT NOT NULL, "CREATE_TIME" INTEGER NOT NULL, "GRANT_OPTION" SMALLINT NOT NULL, "GRANTOR" VARCHAR(128), "GRANTOR_TYPE" VARCHAR(128), "PRINCIPAL_NAME" VARCHAR(128), "PRINCIPAL_TYPE" VARCHAR(128), "USER_PRIV" VARCHAR(128), "AUTHORIZER" VARCHAR(128));
+
+CREATE TABLE "APP"."PARTITION_PARAMS" ("PART_ID" BIGINT NOT NULL, "PARAM_KEY" VARCHAR(256) NOT NULL, "PARAM_VALUE" VARCHAR(4000));
+
+CREATE TABLE "APP"."PARTITION_EVENTS" (
+ "PART_NAME_ID" BIGINT NOT NULL,
+ "CAT_NAME" VARCHAR(256),
+ "DB_NAME" VARCHAR(128),
+ "EVENT_TIME" BIGINT NOT NULL,
+ "EVENT_TYPE" INTEGER NOT NULL,
+ "PARTITION_NAME" VARCHAR(767),
+ "TBL_NAME" VARCHAR(256)
+);
+
+CREATE TABLE "APP"."COLUMNS" ("SD_ID" BIGINT NOT NULL, "COMMENT" VARCHAR(256), "COLUMN_NAME" VARCHAR(128) NOT NULL, "TYPE_NAME" VARCHAR(4000) NOT NULL, "INTEGER_IDX" INTEGER NOT NULL);
+
+CREATE TABLE "APP"."ROLES" ("ROLE_ID" BIGINT NOT NULL, "CREATE_TIME" INTEGER NOT NULL, "OWNER_NAME" VARCHAR(128), "ROLE_NAME" VARCHAR(128));
+
+CREATE TABLE "APP"."TBLS" ("TBL_ID" BIGINT NOT NULL, "CREATE_TIME" INTEGER NOT NULL, "DB_ID" BIGINT, "LAST_ACCESS_TIME" INTEGER NOT NULL, "OWNER" VARCHAR(767), "OWNER_TYPE" VARCHAR(10), "RETENTION" INTEGER NOT NULL, "SD_ID" BIGINT, "TBL_NAME" VARCHAR(256), "TBL_TYPE" VARCHAR(128), "VIEW_EXPANDED_TEXT" LONG VARCHAR, "VIEW_ORIGINAL_TEXT" LONG VARCHAR, "IS_REWRITE_ENABLED" CHAR(1) NOT NULL DEFAULT 'N');
+
+CREATE TABLE "APP"."PARTITION_KEYS" ("TBL_ID" BIGINT NOT NULL, "PKEY_COMMENT" VARCHAR(4000), "PKEY_NAME" VARCHAR(128) NOT NULL, "PKEY_TYPE" VARCHAR(767) NOT NULL, "INTEGER_IDX" INTEGER NOT NULL);
+
+CREATE TABLE "APP"."PART_COL_PRIVS" ("PART_COLUMN_GRANT_ID" BIGINT NOT NULL, "COLUMN_NAME" VARCHAR(767), "CREATE_TIME" INTEGER NOT NULL, "GRANT_OPTION" SMALLINT NOT NULL, "GRANTOR" VARCHAR(128), "GRANTOR_TYPE" VARCHAR(128), "PART_ID" BIGINT, "PRINCIPAL_NAME" VARCHAR(128), "PRINCIPAL_TYPE" VARCHAR(128), "PART_COL_PRIV" VARCHAR(128), "AUTHORIZER" VARCHAR(128));
+
+CREATE TABLE "APP"."SDS" ("SD_ID" BIGINT NOT NULL, "INPUT_FORMAT" VARCHAR(4000), "IS_COMPRESSED" CHAR(1) NOT NULL, "LOCATION" VARCHAR(4000), "NUM_BUCKETS" INTEGER NOT NULL, "OUTPUT_FORMAT" VARCHAR(4000), "SERDE_ID" BIGINT, "CD_ID" BIGINT, "IS_STOREDASSUBDIRECTORIES" CHAR(1) NOT NULL);
+
+CREATE TABLE "APP"."SEQUENCE_TABLE" ("SEQUENCE_NAME" VARCHAR(256) NOT NULL, "NEXT_VAL" BIGINT NOT NULL);
+
+CREATE TABLE "APP"."TAB_COL_STATS"(
+ "CAT_NAME" VARCHAR(256) NOT NULL,
+ "DB_NAME" VARCHAR(128) NOT NULL,
+ "TABLE_NAME" VARCHAR(256) NOT NULL,
+ "COLUMN_NAME" VARCHAR(767) NOT NULL,
+ "COLUMN_TYPE" VARCHAR(128) NOT NULL,
+ "LONG_LOW_VALUE" BIGINT,
+ "LONG_HIGH_VALUE" BIGINT,
+ "DOUBLE_LOW_VALUE" DOUBLE,
+ "DOUBLE_HIGH_VALUE" DOUBLE,
+ "BIG_DECIMAL_LOW_VALUE" VARCHAR(4000),
+ "BIG_DECIMAL_HIGH_VALUE" VARCHAR(4000),
+ "NUM_DISTINCTS" BIGINT,
+ "NUM_NULLS" BIGINT NOT NULL,
+ "AVG_COL_LEN" DOUBLE,
+ "MAX_COL_LEN" BIGINT,
+ "NUM_TRUES" BIGINT,
+ "NUM_FALSES" BIGINT,
+ "LAST_ANALYZED" BIGINT,
+ "CS_ID" BIGINT NOT NULL,
+ "TBL_ID" BIGINT NOT NULL,
+ "BIT_VECTOR" BLOB
+);
+
+CREATE TABLE "APP"."TABLE_PARAMS" ("TBL_ID" BIGINT NOT NULL, "PARAM_KEY" VARCHAR(256) NOT NULL, "PARAM_VALUE" CLOB);
+
+CREATE TABLE "APP"."BUCKETING_COLS" ("SD_ID" BIGINT NOT NULL, "BUCKET_COL_NAME" VARCHAR(256), "INTEGER_IDX" INTEGER NOT NULL);
+
+CREATE TABLE "APP"."TYPE_FIELDS" ("TYPE_NAME" BIGINT NOT NULL, "COMMENT" VARCHAR(256), "FIELD_NAME" VARCHAR(128) NOT NULL, "FIELD_TYPE" VARCHAR(767) NOT NULL, "INTEGER_IDX" INTEGER NOT NULL);
+
+CREATE TABLE "APP"."NUCLEUS_TABLES" ("CLASS_NAME" VARCHAR(128) NOT NULL, "TABLE_NAME" VARCHAR(128) NOT NULL, "TYPE" VARCHAR(4) NOT NULL, "OWNER" VARCHAR(2) NOT NULL, "VERSION" VARCHAR(20) NOT NULL, "INTERFACE_NAME" VARCHAR(256) DEFAULT NULL);
+
+CREATE TABLE "APP"."SD_PARAMS" ("SD_ID" BIGINT NOT NULL, "PARAM_KEY" VARCHAR(256) NOT NULL, "PARAM_VALUE" CLOB);
+
+CREATE TABLE "APP"."SKEWED_STRING_LIST" ("STRING_LIST_ID" BIGINT NOT NULL);
+
+CREATE TABLE "APP"."SKEWED_STRING_LIST_VALUES" ("STRING_LIST_ID" BIGINT NOT NULL, "STRING_LIST_VALUE" VARCHAR(256), "INTEGER_IDX" INTEGER NOT NULL);
+
+CREATE TABLE "APP"."SKEWED_COL_NAMES" ("SD_ID" BIGINT NOT NULL, "SKEWED_COL_NAME" VARCHAR(256), "INTEGER_IDX" INTEGER NOT NULL);
+
+CREATE TABLE "APP"."SKEWED_COL_VALUE_LOC_MAP" ("SD_ID" BIGINT NOT NULL, "STRING_LIST_ID_KID" BIGINT NOT NULL, "LOCATION" VARCHAR(4000));
+
+CREATE TABLE "APP"."SKEWED_VALUES" ("SD_ID_OID" BIGINT NOT NULL, "STRING_LIST_ID_EID" BIGINT NOT NULL, "INTEGER_IDX" INTEGER NOT NULL);
+
+CREATE TABLE "APP"."MASTER_KEYS" ("KEY_ID" INTEGER NOT NULL generated always as identity (start with 1), "MASTER_KEY" VARCHAR(767));
+
+CREATE TABLE "APP"."DELEGATION_TOKENS" ( "TOKEN_IDENT" VARCHAR(767) NOT NULL, "TOKEN" VARCHAR(767));
+
+CREATE TABLE "APP"."PART_COL_STATS"(
+ "CAT_NAME" VARCHAR(256) NOT NULL,
+ "DB_NAME" VARCHAR(128) NOT NULL,
+ "TABLE_NAME" VARCHAR(256) NOT NULL,
+ "PARTITION_NAME" VARCHAR(767) NOT NULL,
+ "COLUMN_NAME" VARCHAR(767) NOT NULL,
+ "COLUMN_TYPE" VARCHAR(128) NOT NULL,
+ "LONG_LOW_VALUE" BIGINT,
+ "LONG_HIGH_VALUE" BIGINT,
+ "DOUBLE_LOW_VALUE" DOUBLE,
+ "DOUBLE_HIGH_VALUE" DOUBLE,
+ "BIG_DECIMAL_LOW_VALUE" VARCHAR(4000),
+ "BIG_DECIMAL_HIGH_VALUE" VARCHAR(4000),
+ "NUM_DISTINCTS" BIGINT,
+ "BIT_VECTOR" BLOB,
+ "NUM_NULLS" BIGINT NOT NULL,
+ "AVG_COL_LEN" DOUBLE,
+ "MAX_COL_LEN" BIGINT,
+ "NUM_TRUES" BIGINT,
+ "NUM_FALSES" BIGINT,
+ "LAST_ANALYZED" BIGINT,
+ "CS_ID" BIGINT NOT NULL,
+ "PART_ID" BIGINT NOT NULL
+);
+
+CREATE TABLE "APP"."VERSION" ("VER_ID" BIGINT NOT NULL, "SCHEMA_VERSION" VARCHAR(127) NOT NULL, "VERSION_COMMENT" VARCHAR(255));
+
+CREATE TABLE "APP"."FUNCS" ("FUNC_ID" BIGINT NOT NULL, "CLASS_NAME" VARCHAR(4000), "CREATE_TIME" INTEGER NOT NULL, "DB_ID" BIGINT, "FUNC_NAME" VARCHAR(128), "FUNC_TYPE" INTEGER NOT NULL, "OWNER_NAME" VARCHAR(128), "OWNER_TYPE" VARCHAR(10));
+
+CREATE TABLE "APP"."FUNC_RU" ("FUNC_ID" BIGINT NOT NULL, "RESOURCE_TYPE" INTEGER NOT NULL, "RESOURCE_URI" VARCHAR(4000), "INTEGER_IDX" INTEGER NOT NULL);
+
+CREATE TABLE "APP"."NOTIFICATION_LOG" (
+ "NL_ID" BIGINT NOT NULL,
+ "CAT_NAME" VARCHAR(256),
+ "DB_NAME" VARCHAR(128),
+ "EVENT_ID" BIGINT NOT NULL,
+ "EVENT_TIME" INTEGER NOT NULL,
+ "EVENT_TYPE" VARCHAR(32) NOT NULL,
+ "MESSAGE" CLOB,
+ "TBL_NAME" VARCHAR(256),
+ "MESSAGE_FORMAT" VARCHAR(16)
+);
+
+CREATE TABLE "APP"."NOTIFICATION_SEQUENCE" ("NNI_ID" BIGINT NOT NULL, "NEXT_EVENT_ID" BIGINT NOT NULL);
+
+CREATE TABLE "APP"."KEY_CONSTRAINTS" ("CHILD_CD_ID" BIGINT, "CHILD_INTEGER_IDX" INTEGER, "CHILD_TBL_ID" BIGINT, "PARENT_CD_ID" BIGINT , "PARENT_INTEGER_IDX" INTEGER, "PARENT_TBL_ID" BIGINT NOT NULL, "POSITION" BIGINT NOT NULL, "CONSTRAINT_NAME" VARCHAR(400) NOT NULL, "CONSTRAINT_TYPE" SMALLINT NOT NULL, "UPDATE_RULE" SMALLINT, "DELETE_RULE" SMALLINT, "ENABLE_VALIDATE_RELY" SMALLINT NOT NULL, "DEFAULT_VALUE" VARCHAR(400));
+
+CREATE TABLE "APP"."METASTORE_DB_PROPERTIES" ("PROPERTY_KEY" VARCHAR(255) NOT NULL, "PROPERTY_VALUE" VARCHAR(1000) NOT NULL, "DESCRIPTION" VARCHAR(1000));
+
+CREATE TABLE "APP"."WM_RESOURCEPLAN" (RP_ID BIGINT NOT NULL, NAME VARCHAR(128) NOT NULL, QUERY_PARALLELISM INTEGER, STATUS VARCHAR(20) NOT NULL, DEFAULT_POOL_ID BIGINT);
+
+CREATE TABLE "APP"."WM_POOL" (POOL_ID BIGINT NOT NULL, RP_ID BIGINT NOT NULL, PATH VARCHAR(1024) NOT NULL, ALLOC_FRACTION DOUBLE, QUERY_PARALLELISM INTEGER, SCHEDULING_POLICY VARCHAR(1024));
+
+CREATE TABLE "APP"."WM_TRIGGER" (TRIGGER_ID BIGINT NOT NULL, RP_ID BIGINT NOT NULL, NAME VARCHAR(128) NOT NULL, TRIGGER_EXPRESSION VARCHAR(1024), ACTION_EXPRESSION VARCHAR(1024), IS_IN_UNMANAGED INTEGER NOT NULL DEFAULT 0);
+
+CREATE TABLE "APP"."WM_POOL_TO_TRIGGER" (POOL_ID BIGINT NOT NULL, TRIGGER_ID BIGINT NOT NULL);
+
+CREATE TABLE "APP"."WM_MAPPING" (MAPPING_ID BIGINT NOT NULL, RP_ID BIGINT NOT NULL, ENTITY_TYPE VARCHAR(128) NOT NULL, ENTITY_NAME VARCHAR(128) NOT NULL, POOL_ID BIGINT, ORDERING INTEGER);
+
+CREATE TABLE "APP"."MV_CREATION_METADATA" (
+ "MV_CREATION_METADATA_ID" BIGINT NOT NULL,
+ "CAT_NAME" VARCHAR(256) NOT NULL,
+ "DB_NAME" VARCHAR(128) NOT NULL,
+ "TBL_NAME" VARCHAR(256) NOT NULL,
+ "TXN_LIST" CLOB,
+ "MATERIALIZATION_TIME" BIGINT NOT NULL
+);
+
+CREATE TABLE "APP"."MV_TABLES_USED" (
+ "MV_CREATION_METADATA_ID" BIGINT NOT NULL,
+ "TBL_ID" BIGINT NOT NULL
+);
+
+CREATE TABLE "APP"."CTLGS" (
+ "CTLG_ID" BIGINT NOT NULL,
+ "NAME" VARCHAR(256) UNIQUE,
+ "DESC" VARCHAR(4000),
+ "LOCATION_URI" VARCHAR(4000) NOT NULL);
+
+-- ----------------------------------------------
+-- DML Statements
+-- ----------------------------------------------
+
+INSERT INTO "APP"."NOTIFICATION_SEQUENCE" ("NNI_ID", "NEXT_EVENT_ID") SELECT * FROM (VALUES (1,1)) tmp_table WHERE NOT EXISTS ( SELECT "NEXT_EVENT_ID" FROM "APP"."NOTIFICATION_SEQUENCE");
+
+INSERT INTO "APP"."SEQUENCE_TABLE" ("SEQUENCE_NAME", "NEXT_VAL") SELECT * FROM (VALUES ('org.apache.hadoop.hive.metastore.model.MNotificationLog', 1)) tmp_table WHERE NOT EXISTS ( SELECT "NEXT_VAL" FROM "APP"."SEQUENCE_TABLE" WHERE "SEQUENCE_NAME" = 'org.apache.hadoop.hive.metastore.model.MNotificationLog');
+
+-- ----------------------------------------------
+-- DDL Statements for indexes
+-- ----------------------------------------------
+
+CREATE UNIQUE INDEX "APP"."UNIQUEINDEX" ON "APP"."IDXS" ("INDEX_NAME", "ORIG_TBL_ID");
+
+CREATE INDEX "APP"."TABLECOLUMNPRIVILEGEINDEX" ON "APP"."TBL_COL_PRIVS" ("AUTHORIZER", "TBL_ID", "COLUMN_NAME", "PRINCIPAL_NAME", "PRINCIPAL_TYPE", "TBL_COL_PRIV", "GRANTOR", "GRANTOR_TYPE");
+
+CREATE UNIQUE INDEX "APP"."DBPRIVILEGEINDEX" ON "APP"."DB_PRIVS" ("AUTHORIZER", "DB_ID", "PRINCIPAL_NAME", "PRINCIPAL_TYPE", "DB_PRIV", "GRANTOR", "GRANTOR_TYPE");
+
+CREATE INDEX "APP"."PCS_STATS_IDX" ON "APP"."PART_COL_STATS" ("CAT_NAME", "DB_NAME","TABLE_NAME","COLUMN_NAME","PARTITION_NAME");
+
+CREATE INDEX "APP"."TAB_COL_STATS_IDX" ON "APP"."TAB_COL_STATS" ("CAT_NAME", "DB_NAME", "TABLE_NAME", "COLUMN_NAME");
+
+CREATE INDEX "APP"."PARTPRIVILEGEINDEX" ON "APP"."PART_PRIVS" ("AUTHORIZER", "PART_ID", "PRINCIPAL_NAME", "PRINCIPAL_TYPE", "PART_PRIV", "GRANTOR", "GRANTOR_TYPE");
+
+CREATE UNIQUE INDEX "APP"."ROLEENTITYINDEX" ON "APP"."ROLES" ("ROLE_NAME");
+
+CREATE INDEX "APP"."TABLEPRIVILEGEINDEX" ON "APP"."TBL_PRIVS" ("AUTHORIZER", "TBL_ID", "PRINCIPAL_NAME", "PRINCIPAL_TYPE", "TBL_PRIV", "GRANTOR", "GRANTOR_TYPE");
+
+CREATE UNIQUE INDEX "APP"."UNIQUETABLE" ON "APP"."TBLS" ("TBL_NAME", "DB_ID");
+
+CREATE UNIQUE INDEX "APP"."UNIQUE_DATABASE" ON "APP"."DBS" ("NAME", "CTLG_NAME");
+
+CREATE UNIQUE INDEX "APP"."USERROLEMAPINDEX" ON "APP"."ROLE_MAP" ("PRINCIPAL_NAME", "ROLE_ID", "GRANTOR", "GRANTOR_TYPE");
+
+CREATE UNIQUE INDEX "APP"."GLOBALPRIVILEGEINDEX" ON "APP"."GLOBAL_PRIVS" ("AUTHORIZER", "PRINCIPAL_NAME", "PRINCIPAL_TYPE", "USER_PRIV", "GRANTOR", "GRANTOR_TYPE");
+
+CREATE UNIQUE INDEX "APP"."UNIQUE_TYPE" ON "APP"."TYPES" ("TYPE_NAME");
+
+CREATE INDEX "APP"."PARTITIONCOLUMNPRIVILEGEINDEX" ON "APP"."PART_COL_PRIVS" ("AUTHORIZER", "PART_ID", "COLUMN_NAME", "PRINCIPAL_NAME", "PRINCIPAL_TYPE", "PART_COL_PRIV", "GRANTOR", "GRANTOR_TYPE");
+
+CREATE UNIQUE INDEX "APP"."UNIQUEPARTITION" ON "APP"."PARTITIONS" ("PART_NAME", "TBL_ID");
+
+CREATE UNIQUE INDEX "APP"."UNIQUEFUNCTION" ON "APP"."FUNCS" ("FUNC_NAME", "DB_ID");
+
+CREATE INDEX "APP"."FUNCS_N49" ON "APP"."FUNCS" ("DB_ID");
+
+CREATE INDEX "APP"."FUNC_RU_N49" ON "APP"."FUNC_RU" ("FUNC_ID");
+
+CREATE INDEX "APP"."CONSTRAINTS_PARENT_TBL_ID_INDEX" ON "APP"."KEY_CONSTRAINTS"("PARENT_TBL_ID");
+
+CREATE INDEX "APP"."CONSTRAINTS_CONSTRAINT_TYPE_INDEX" ON "APP"."KEY_CONSTRAINTS"("CONSTRAINT_TYPE");
+
+CREATE UNIQUE INDEX "APP"."UNIQUE_WM_RESOURCEPLAN" ON "APP"."WM_RESOURCEPLAN" ("NAME");
+
+CREATE UNIQUE INDEX "APP"."UNIQUE_WM_POOL" ON "APP"."WM_POOL" ("RP_ID", "PATH");
+
+CREATE UNIQUE INDEX "APP"."UNIQUE_WM_TRIGGER" ON "APP"."WM_TRIGGER" ("RP_ID", "NAME");
+
+CREATE UNIQUE INDEX "APP"."UNIQUE_WM_MAPPING" ON "APP"."WM_MAPPING" ("RP_ID", "ENTITY_TYPE", "ENTITY_NAME");
+
+CREATE UNIQUE INDEX "APP"."MV_UNIQUE_TABLE" ON "APP"."MV_CREATION_METADATA" ("TBL_NAME", "DB_NAME");
+
+CREATE UNIQUE INDEX "APP"."UNIQUE_CATALOG" ON "APP"."CTLGS" ("NAME");
+
+
+-- ----------------------------------------------
+-- DDL Statements for keys
+-- ----------------------------------------------
+
+-- primary/unique
+ALTER TABLE "APP"."IDXS" ADD CONSTRAINT "IDXS_PK" PRIMARY KEY ("INDEX_ID");
+
+ALTER TABLE "APP"."TBL_COL_PRIVS" ADD CONSTRAINT "TBL_COL_PRIVS_PK" PRIMARY KEY ("TBL_COLUMN_GRANT_ID");
+
+ALTER TABLE "APP"."CDS" ADD CONSTRAINT "SQL110922153006460" PRIMARY KEY ("CD_ID");
+
+ALTER TABLE "APP"."DB_PRIVS" ADD CONSTRAINT "DB_PRIVS_PK" PRIMARY KEY ("DB_GRANT_ID");
+
+ALTER TABLE "APP"."INDEX_PARAMS" ADD CONSTRAINT "INDEX_PARAMS_PK" PRIMARY KEY ("INDEX_ID", "PARAM_KEY");
+
+ALTER TABLE "APP"."PARTITION_KEYS" ADD CONSTRAINT "PARTITION_KEY_PK" PRIMARY KEY ("TBL_ID", "PKEY_NAME");
+
+ALTER TABLE "APP"."SEQUENCE_TABLE" ADD CONSTRAINT "SEQUENCE_TABLE_PK" PRIMARY KEY ("SEQUENCE_NAME");
+
+ALTER TABLE "APP"."PART_PRIVS" ADD CONSTRAINT "PART_PRIVS_PK" PRIMARY KEY ("PART_GRANT_ID");
+
+ALTER TABLE "APP"."SDS" ADD CONSTRAINT "SDS_PK" PRIMARY KEY ("SD_ID");
+
+ALTER TABLE "APP"."SERDES" ADD CONSTRAINT "SERDES_PK" PRIMARY KEY ("SERDE_ID");
+
+ALTER TABLE "APP"."COLUMNS" ADD CONSTRAINT "COLUMNS_PK" PRIMARY KEY ("SD_ID", "COLUMN_NAME");
+
+ALTER TABLE "APP"."PARTITION_EVENTS" ADD CONSTRAINT "PARTITION_EVENTS_PK" PRIMARY KEY ("PART_NAME_ID");
+
+ALTER TABLE "APP"."TYPE_FIELDS" ADD CONSTRAINT "TYPE_FIELDS_PK" PRIMARY KEY ("TYPE_NAME", "FIELD_NAME");
+
+ALTER TABLE "APP"."ROLES" ADD CONSTRAINT "ROLES_PK" PRIMARY KEY ("ROLE_ID");
+
+ALTER TABLE "APP"."TBL_PRIVS" ADD CONSTRAINT "TBL_PRIVS_PK" PRIMARY KEY ("TBL_GRANT_ID");
+
+ALTER TABLE "APP"."SERDE_PARAMS" ADD CONSTRAINT "SERDE_PARAMS_PK" PRIMARY KEY ("SERDE_ID", "PARAM_KEY");
+
+ALTER TABLE "APP"."NUCLEUS_TABLES" ADD CONSTRAINT "NUCLEUS_TABLES_PK" PRIMARY KEY ("CLASS_NAME");
+
+ALTER TABLE "APP"."TBLS" ADD CONSTRAINT "TBLS_PK" PRIMARY KEY ("TBL_ID");
+
+ALTER TABLE "APP"."SD_PARAMS" ADD CONSTRAINT "SD_PARAMS_PK" PRIMARY KEY ("SD_ID", "PARAM_KEY");
+
+ALTER TABLE "APP"."DATABASE_PARAMS" ADD CONSTRAINT "DATABASE_PARAMS_PK" PRIMARY KEY ("DB_ID", "PARAM_KEY");
+
+ALTER TABLE "APP"."DBS" ADD CONSTRAINT "DBS_PK" PRIMARY KEY ("DB_ID");
+
+ALTER TABLE "APP"."ROLE_MAP" ADD CONSTRAINT "ROLE_MAP_PK" PRIMARY KEY ("ROLE_GRANT_ID");
+
+ALTER TABLE "APP"."GLOBAL_PRIVS" ADD CONSTRAINT "GLOBAL_PRIVS_PK" PRIMARY KEY ("USER_GRANT_ID");
+
+ALTER TABLE "APP"."BUCKETING_COLS" ADD CONSTRAINT "BUCKETING_COLS_PK" PRIMARY KEY ("SD_ID", "INTEGER_IDX");
+
+ALTER TABLE "APP"."SORT_COLS" ADD CONSTRAINT "SORT_COLS_PK" PRIMARY KEY ("SD_ID", "INTEGER_IDX");
+
+ALTER TABLE "APP"."PARTITION_KEY_VALS" ADD CONSTRAINT "PARTITION_KEY_VALS_PK" PRIMARY KEY ("PART_ID", "INTEGER_IDX");
+
+ALTER TABLE "APP"."TYPES" ADD CONSTRAINT "TYPES_PK" PRIMARY KEY ("TYPES_ID");
+
+ALTER TABLE "APP"."COLUMNS_V2" ADD CONSTRAINT "SQL110922153006740" PRIMARY KEY ("CD_ID", "COLUMN_NAME");
+
+ALTER TABLE "APP"."PART_COL_PRIVS" ADD CONSTRAINT "PART_COL_PRIVS_PK" PRIMARY KEY ("PART_COLUMN_GRANT_ID");
+
+ALTER TABLE "APP"."PARTITION_PARAMS" ADD CONSTRAINT "PARTITION_PARAMS_PK" PRIMARY KEY ("PART_ID", "PARAM_KEY");
+
+ALTER TABLE "APP"."PARTITIONS" ADD CONSTRAINT "PARTITIONS_PK" PRIMARY KEY ("PART_ID");
+
+ALTER TABLE "APP"."TABLE_PARAMS" ADD CONSTRAINT "TABLE_PARAMS_PK" PRIMARY KEY ("TBL_ID", "PARAM_KEY");
+
+ALTER TABLE "APP"."SKEWED_STRING_LIST" ADD CONSTRAINT "SKEWED_STRING_LIST_PK" PRIMARY KEY ("STRING_LIST_ID");
+
+ALTER TABLE "APP"."SKEWED_STRING_LIST_VALUES" ADD CONSTRAINT "SKEWED_STRING_LIST_VALUES_PK" PRIMARY KEY ("STRING_LIST_ID", "INTEGER_IDX");
+
+ALTER TABLE "APP"."SKEWED_COL_NAMES" ADD CONSTRAINT "SKEWED_COL_NAMES_PK" PRIMARY KEY ("SD_ID", "INTEGER_IDX");
+
+ALTER TABLE "APP"."SKEWED_COL_VALUE_LOC_MAP" ADD CONSTRAINT "SKEWED_COL_VALUE_LOC_MAP_PK" PRIMARY KEY ("SD_ID", "STRING_LIST_ID_KID");
+
+ALTER TABLE "APP"."SKEWED_VALUES" ADD CONSTRAINT "SKEWED_VALUES_PK" PRIMARY KEY ("SD_ID_OID", "INTEGER_IDX");
+
+ALTER TABLE "APP"."TAB_COL_STATS" ADD CONSTRAINT "TAB_COL_STATS_PK" PRIMARY KEY ("CS_ID");
+
+ALTER TABLE "APP"."PART_COL_STATS" ADD CONSTRAINT "PART_COL_STATS_PK" PRIMARY KEY ("CS_ID");
+
+ALTER TABLE "APP"."FUNCS" ADD CONSTRAINT "FUNCS_PK" PRIMARY KEY ("FUNC_ID");
+
+ALTER TABLE "APP"."FUNC_RU" ADD CONSTRAINT "FUNC_RU_PK" PRIMARY KEY ("FUNC_ID", "INTEGER_IDX");
+
+ALTER TABLE "APP"."NOTIFICATION_LOG" ADD CONSTRAINT "NOTIFICATION_LOG_PK" PRIMARY KEY ("NL_ID");
+
+ALTER TABLE "APP"."NOTIFICATION_SEQUENCE" ADD CONSTRAINT "NOTIFICATION_SEQUENCE_PK" PRIMARY KEY ("NNI_ID");
+
+ALTER TABLE "APP"."KEY_CONSTRAINTS" ADD CONSTRAINT "CONSTRAINTS_PK" PRIMARY KEY ("CONSTRAINT_NAME", "POSITION");
+
+ALTER TABLE "APP"."METASTORE_DB_PROPERTIES" ADD CONSTRAINT "PROPERTY_KEY_PK" PRIMARY KEY ("PROPERTY_KEY");
+
+ALTER TABLE "APP"."MV_CREATION_METADATA" ADD CONSTRAINT "MV_CREATION_METADATA_PK" PRIMARY KEY ("MV_CREATION_METADATA_ID");
+
+ALTER TABLE "APP"."CTLGS" ADD CONSTRAINT "CTLG_PK" PRIMARY KEY ("CTLG_ID");
+
+
+-- foreign
+ALTER TABLE "APP"."IDXS" ADD CONSTRAINT "IDXS_FK1" FOREIGN KEY ("ORIG_TBL_ID") REFERENCES "APP"."TBLS" ("TBL_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."IDXS" ADD CONSTRAINT "IDXS_FK2" FOREIGN KEY ("SD_ID") REFERENCES "APP"."SDS" ("SD_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."IDXS" ADD CONSTRAINT "IDXS_FK3" FOREIGN KEY ("INDEX_TBL_ID") REFERENCES "APP"."TBLS" ("TBL_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."TBL_COL_PRIVS" ADD CONSTRAINT "TBL_COL_PRIVS_FK1" FOREIGN KEY ("TBL_ID") REFERENCES "APP"."TBLS" ("TBL_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."DB_PRIVS" ADD CONSTRAINT "DB_PRIVS_FK1" FOREIGN KEY ("DB_ID") REFERENCES "APP"."DBS" ("DB_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."INDEX_PARAMS" ADD CONSTRAINT "INDEX_PARAMS_FK1" FOREIGN KEY ("INDEX_ID") REFERENCES "APP"."IDXS" ("INDEX_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."PARTITION_KEYS" ADD CONSTRAINT "PARTITION_KEYS_FK1" FOREIGN KEY ("TBL_ID") REFERENCES "APP"."TBLS" ("TBL_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."PART_PRIVS" ADD CONSTRAINT "PART_PRIVS_FK1" FOREIGN KEY ("PART_ID") REFERENCES "APP"."PARTITIONS" ("PART_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."SDS" ADD CONSTRAINT "SDS_FK1" FOREIGN KEY ("SERDE_ID") REFERENCES "APP"."SERDES" ("SERDE_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."SDS" ADD CONSTRAINT "SDS_FK2" FOREIGN KEY ("CD_ID") REFERENCES "APP"."CDS" ("CD_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."COLUMNS" ADD CONSTRAINT "COLUMNS_FK1" FOREIGN KEY ("SD_ID") REFERENCES "APP"."SDS" ("SD_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."TYPE_FIELDS" ADD CONSTRAINT "TYPE_FIELDS_FK1" FOREIGN KEY ("TYPE_NAME") REFERENCES "APP"."TYPES" ("TYPES_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."TBL_PRIVS" ADD CONSTRAINT "TBL_PRIVS_FK1" FOREIGN KEY ("TBL_ID") REFERENCES "APP"."TBLS" ("TBL_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."SERDE_PARAMS" ADD CONSTRAINT "SERDE_PARAMS_FK1" FOREIGN KEY ("SERDE_ID") REFERENCES "APP"."SERDES" ("SERDE_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."TBLS" ADD CONSTRAINT "TBLS_FK2" FOREIGN KEY ("SD_ID") REFERENCES "APP"."SDS" ("SD_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."TBLS" ADD CONSTRAINT "TBLS_FK1" FOREIGN KEY ("DB_ID") REFERENCES "APP"."DBS" ("DB_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."DBS" ADD CONSTRAINT "DBS_FK1" FOREIGN KEY ("CTLG_NAME") REFERENCES "APP"."CTLGS" ("NAME") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."SD_PARAMS" ADD CONSTRAINT "SD_PARAMS_FK1" FOREIGN KEY ("SD_ID") REFERENCES "APP"."SDS" ("SD_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."DATABASE_PARAMS" ADD CONSTRAINT "DATABASE_PARAMS_FK1" FOREIGN KEY ("DB_ID") REFERENCES "APP"."DBS" ("DB_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."ROLE_MAP" ADD CONSTRAINT "ROLE_MAP_FK1" FOREIGN KEY ("ROLE_ID") REFERENCES "APP"."ROLES" ("ROLE_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."BUCKETING_COLS" ADD CONSTRAINT "BUCKETING_COLS_FK1" FOREIGN KEY ("SD_ID") REFERENCES "APP"."SDS" ("SD_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."SORT_COLS" ADD CONSTRAINT "SORT_COLS_FK1" FOREIGN KEY ("SD_ID") REFERENCES "APP"."SDS" ("SD_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."PARTITION_KEY_VALS" ADD CONSTRAINT "PARTITION_KEY_VALS_FK1" FOREIGN KEY ("PART_ID") REFERENCES "APP"."PARTITIONS" ("PART_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."COLUMNS_V2" ADD CONSTRAINT "COLUMNS_V2_FK1" FOREIGN KEY ("CD_ID") REFERENCES "APP"."CDS" ("CD_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."PART_COL_PRIVS" ADD CONSTRAINT "PART_COL_PRIVS_FK1" FOREIGN KEY ("PART_ID") REFERENCES "APP"."PARTITIONS" ("PART_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."PARTITION_PARAMS" ADD CONSTRAINT "PARTITION_PARAMS_FK1" FOREIGN KEY ("PART_ID") REFERENCES "APP"."PARTITIONS" ("PART_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."PARTITIONS" ADD CONSTRAINT "PARTITIONS_FK1" FOREIGN KEY ("TBL_ID") REFERENCES "APP"."TBLS" ("TBL_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."PARTITIONS" ADD CONSTRAINT "PARTITIONS_FK2" FOREIGN KEY ("SD_ID") REFERENCES "APP"."SDS" ("SD_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."TABLE_PARAMS" ADD CONSTRAINT "TABLE_PARAMS_FK1" FOREIGN KEY ("TBL_ID") REFERENCES "APP"."TBLS" ("TBL_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."SKEWED_STRING_LIST_VALUES" ADD CONSTRAINT "SKEWED_STRING_LIST_VALUES_FK1" FOREIGN KEY ("STRING_LIST_ID") REFERENCES "APP"."SKEWED_STRING_LIST" ("STRING_LIST_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."SKEWED_COL_NAMES" ADD CONSTRAINT "SKEWED_COL_NAMES_FK1" FOREIGN KEY ("SD_ID") REFERENCES "APP"."SDS" ("SD_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."SKEWED_COL_VALUE_LOC_MAP" ADD CONSTRAINT "SKEWED_COL_VALUE_LOC_MAP_FK1" FOREIGN KEY ("SD_ID") REFERENCES "APP"."SDS" ("SD_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."SKEWED_COL_VALUE_LOC_MAP" ADD CONSTRAINT "SKEWED_COL_VALUE_LOC_MAP_FK2" FOREIGN KEY ("STRING_LIST_ID_KID") REFERENCES "APP"."SKEWED_STRING_LIST" ("STRING_LIST_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."SKEWED_VALUES" ADD CONSTRAINT "SKEWED_VALUES_FK1" FOREIGN KEY ("SD_ID_OID") REFERENCES "APP"."SDS" ("SD_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."SKEWED_VALUES" ADD CONSTRAINT "SKEWED_VALUES_FK2" FOREIGN KEY ("STRING_LIST_ID_EID") REFERENCES "APP"."SKEWED_STRING_LIST" ("STRING_LIST_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."TAB_COL_STATS" ADD CONSTRAINT "TAB_COL_STATS_FK" FOREIGN KEY ("TBL_ID") REFERENCES TBLS("TBL_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."PART_COL_STATS" ADD CONSTRAINT "PART_COL_STATS_FK" FOREIGN KEY ("PART_ID") REFERENCES PARTITIONS("PART_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."VERSION" ADD CONSTRAINT "VERSION_PK" PRIMARY KEY ("VER_ID");
+
+ALTER TABLE "APP"."FUNCS" ADD CONSTRAINT "FUNCS_FK1" FOREIGN KEY ("DB_ID") REFERENCES "APP"."DBS" ("DB_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."FUNC_RU" ADD CONSTRAINT "FUNC_RU_FK1" FOREIGN KEY ("FUNC_ID") REFERENCES "APP"."FUNCS" ("FUNC_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."WM_RESOURCEPLAN" ADD CONSTRAINT "WM_RESOURCEPLAN_PK" PRIMARY KEY ("RP_ID");
+
+ALTER TABLE "APP"."WM_POOL" ADD CONSTRAINT "WM_POOL_PK" PRIMARY KEY ("POOL_ID");
+
+ALTER TABLE "APP"."WM_POOL" ADD CONSTRAINT "WM_POOL_FK1" FOREIGN KEY ("RP_ID") REFERENCES "APP"."WM_RESOURCEPLAN" ("RP_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."WM_RESOURCEPLAN" ADD CONSTRAINT "WM_RESOURCEPLAN_FK1" FOREIGN KEY ("DEFAULT_POOL_ID") REFERENCES "APP"."WM_POOL" ("POOL_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."WM_TRIGGER" ADD CONSTRAINT "WM_TRIGGER_PK" PRIMARY KEY ("TRIGGER_ID");
+
+ALTER TABLE "APP"."WM_TRIGGER" ADD CONSTRAINT "WM_TRIGGER_FK1" FOREIGN KEY ("RP_ID") REFERENCES "APP"."WM_RESOURCEPLAN" ("RP_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."WM_POOL_TO_TRIGGER" ADD CONSTRAINT "WM_POOL_TO_TRIGGER_FK1" FOREIGN KEY ("POOL_ID") REFERENCES "APP"."WM_POOL" ("POOL_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."WM_POOL_TO_TRIGGER" ADD CONSTRAINT "WM_POOL_TO_TRIGGER_FK2" FOREIGN KEY ("TRIGGER_ID") REFERENCES "APP"."WM_TRIGGER" ("TRIGGER_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."WM_MAPPING" ADD CONSTRAINT "WM_MAPPING_PK" PRIMARY KEY ("MAPPING_ID");
+
+ALTER TABLE "APP"."WM_MAPPING" ADD CONSTRAINT "WM_MAPPING_FK1" FOREIGN KEY ("RP_ID") REFERENCES "APP"."WM_RESOURCEPLAN" ("RP_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."WM_MAPPING" ADD CONSTRAINT "WM_MAPPING_FK2" FOREIGN KEY ("POOL_ID") REFERENCES "APP"."WM_POOL" ("POOL_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."MV_TABLES_USED" ADD CONSTRAINT "MV_TABLES_USED_FK1" FOREIGN KEY ("MV_CREATION_METADATA_ID") REFERENCES "APP"."MV_CREATION_METADATA" ("MV_CREATION_METADATA_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."MV_TABLES_USED" ADD CONSTRAINT "MV_TABLES_USED_FK2" FOREIGN KEY ("TBL_ID") REFERENCES "APP"."TBLS" ("TBL_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+ALTER TABLE "APP"."DBS" ADD CONSTRAINT "DBS_CTLG_FK" FOREIGN KEY ("CTLG_NAME") REFERENCES "APP"."CTLGS" ("NAME") ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+-- ----------------------------------------------
+-- DDL Statements for checks
+-- ----------------------------------------------
+
+ALTER TABLE "APP"."IDXS" ADD CONSTRAINT "SQL110318025504980" CHECK (DEFERRED_REBUILD IN ('Y','N'));
+
+ALTER TABLE "APP"."SDS" ADD CONSTRAINT "SQL110318025505550" CHECK (IS_COMPRESSED IN ('Y','N'));
+
+-- ----------------------------
+-- Transaction and Lock Tables
+-- ----------------------------
+CREATE TABLE TXNS (
+ TXN_ID bigint PRIMARY KEY,
+ TXN_STATE char(1) NOT NULL,
+ TXN_STARTED bigint NOT NULL,
+ TXN_LAST_HEARTBEAT bigint NOT NULL,
+ TXN_USER varchar(128) NOT NULL,
+ TXN_HOST varchar(128) NOT NULL,
+ TXN_AGENT_INFO varchar(128),
+ TXN_META_INFO varchar(128),
+ TXN_HEARTBEAT_COUNT integer,
+ TXN_TYPE integer
+);
+
+CREATE TABLE TXN_COMPONENTS (
+ TC_TXNID bigint NOT NULL REFERENCES TXNS (TXN_ID),
+ TC_DATABASE varchar(128) NOT NULL,
+ TC_TABLE varchar(128),
+ TC_PARTITION varchar(767),
+ TC_OPERATION_TYPE char(1) NOT NULL,
+ TC_WRITEID bigint
+);
+
+CREATE INDEX TC_TXNID_INDEX ON TXN_COMPONENTS (TC_TXNID);
+
+CREATE TABLE COMPLETED_TXN_COMPONENTS (
+ CTC_TXNID bigint NOT NULL,
+ CTC_DATABASE varchar(128) NOT NULL,
+ CTC_TABLE varchar(256),
+ CTC_PARTITION varchar(767),
+ CTC_TIMESTAMP timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ CTC_WRITEID bigint,
+ CTC_UPDATE_DELETE char(1) NOT NULL
+);
+
+CREATE INDEX COMPLETED_TXN_COMPONENTS_IDX ON COMPLETED_TXN_COMPONENTS (CTC_DATABASE, CTC_TABLE, CTC_PARTITION);
+
+CREATE TABLE NEXT_TXN_ID (
+ NTXN_NEXT bigint NOT NULL
+);
+INSERT INTO NEXT_TXN_ID VALUES(1);
+
+CREATE TABLE HIVE_LOCKS (
+ HL_LOCK_EXT_ID bigint NOT NULL,
+ HL_LOCK_INT_ID bigint NOT NULL,
+ HL_TXNID bigint NOT NULL,
+ HL_DB varchar(128) NOT NULL,
+ HL_TABLE varchar(128),
+ HL_PARTITION varchar(767),
+ HL_LOCK_STATE char(1) NOT NULL,
+ HL_LOCK_TYPE char(1) NOT NULL,
+ HL_LAST_HEARTBEAT bigint NOT NULL,
+ HL_ACQUIRED_AT bigint,
+ HL_USER varchar(128) NOT NULL,
+ HL_HOST varchar(128) NOT NULL,
+ HL_HEARTBEAT_COUNT integer,
+ HL_AGENT_INFO varchar(128),
+ HL_BLOCKEDBY_EXT_ID bigint,
+ HL_BLOCKEDBY_INT_ID bigint,
+ PRIMARY KEY(HL_LOCK_EXT_ID, HL_LOCK_INT_ID)
+);
+
+CREATE INDEX HL_TXNID_INDEX ON HIVE_LOCKS (HL_TXNID);
+
+CREATE TABLE NEXT_LOCK_ID (
+ NL_NEXT bigint NOT NULL
+);
+INSERT INTO NEXT_LOCK_ID VALUES(1);
+
+CREATE TABLE COMPACTION_QUEUE (
+ CQ_ID bigint PRIMARY KEY,
+ CQ_DATABASE varchar(128) NOT NULL,
+ CQ_TABLE varchar(128) NOT NULL,
+ CQ_PARTITION varchar(767),
+ CQ_STATE char(1) NOT NULL,
+ CQ_TYPE char(1) NOT NULL,
+ CQ_TBLPROPERTIES varchar(2048),
+ CQ_WORKER_ID varchar(128),
+ CQ_START bigint,
+ CQ_RUN_AS varchar(128),
+ CQ_HIGHEST_WRITE_ID bigint,
+ CQ_META_INFO varchar(2048) for bit data,
+ CQ_HADOOP_JOB_ID varchar(32)
+);
+
+CREATE TABLE NEXT_COMPACTION_QUEUE_ID (
+ NCQ_NEXT bigint NOT NULL
+);
+INSERT INTO NEXT_COMPACTION_QUEUE_ID VALUES(1);
+
+CREATE TABLE COMPLETED_COMPACTIONS (
+ CC_ID bigint PRIMARY KEY,
+ CC_DATABASE varchar(128) NOT NULL,
+ CC_TABLE varchar(128) NOT NULL,
+ CC_PARTITION varchar(767),
+ CC_STATE char(1) NOT NULL,
+ CC_TYPE char(1) NOT NULL,
+ CC_TBLPROPERTIES varchar(2048),
+ CC_WORKER_ID varchar(128),
+ CC_START bigint,
+ CC_END bigint,
+ CC_RUN_AS varchar(128),
+ CC_HIGHEST_WRITE_ID bigint,
+ CC_META_INFO varchar(2048) for bit data,
+ CC_HADOOP_JOB_ID varchar(32)
+);
+
+CREATE TABLE AUX_TABLE (
+ MT_KEY1 varchar(128) NOT NULL,
+ MT_KEY2 bigint NOT NULL,
+ MT_COMMENT varchar(255),
+ PRIMARY KEY(MT_KEY1, MT_KEY2)
+);
+
+--1st 4 cols make up a PK but since WS_PARTITION is nullable we can't declare such PK
+--This is a good candidate for Index orgainzed table
+CREATE TABLE WRITE_SET (
+ WS_DATABASE varchar(128) NOT NULL,
+ WS_TABLE varchar(128) NOT NULL,
+ WS_PARTITION varchar(767),
+ WS_TXNID bigint NOT NULL,
+ WS_COMMIT_ID bigint NOT NULL,
+ WS_OPERATION_TYPE char(1) NOT NULL
+);
+
+CREATE TABLE TXN_TO_WRITE_ID (
+ T2W_TXNID bigint NOT NULL,
+ T2W_DATABASE varchar(128) NOT NULL,
+ T2W_TABLE varchar(256) NOT NULL,
+ T2W_WRITEID bigint NOT NULL
+);
+
+CREATE UNIQUE INDEX TBL_TO_TXN_ID_IDX ON TXN_TO_WRITE_ID (T2W_DATABASE, T2W_TABLE, T2W_TXNID);
+CREATE UNIQUE INDEX TBL_TO_WRITE_ID_IDX ON TXN_TO_WRITE_ID (T2W_DATABASE, T2W_TABLE, T2W_WRITEID);
+
+CREATE TABLE NEXT_WRITE_ID (
+ NWI_DATABASE varchar(128) NOT NULL,
+ NWI_TABLE varchar(256) NOT NULL,
+ NWI_NEXT bigint NOT NULL
+);
+
+CREATE UNIQUE INDEX NEXT_WRITE_ID_IDX ON NEXT_WRITE_ID (NWI_DATABASE, NWI_TABLE);
+
+CREATE TABLE MIN_HISTORY_LEVEL (
+ MHL_TXNID bigint NOT NULL,
+ MHL_MIN_OPEN_TXNID bigint NOT NULL,
+ PRIMARY KEY(MHL_TXNID)
+);
+
+CREATE INDEX MIN_HISTORY_LEVEL_IDX ON MIN_HISTORY_LEVEL (MHL_MIN_OPEN_TXNID);
+
+CREATE TABLE MATERIALIZATION_REBUILD_LOCKS (
+ MRL_TXN_ID BIGINT NOT NULL,
+ MRL_DB_NAME VARCHAR(128) NOT NULL,
+ MRL_TBL_NAME VARCHAR(256) NOT NULL,
+ MRL_LAST_HEARTBEAT BIGINT NOT NULL,
+ PRIMARY KEY(MRL_TXN_ID)
+);
+
+CREATE TABLE "APP"."I_SCHEMA" (
+ "SCHEMA_ID" bigint primary key,
+ "SCHEMA_TYPE" integer not null,
+ "NAME" varchar(256) unique,
+ "DB_ID" bigint references "APP"."DBS" ("DB_ID"),
+ "COMPATIBILITY" integer not null,
+ "VALIDATION_LEVEL" integer not null,
+ "CAN_EVOLVE" char(1) not null,
+ "SCHEMA_GROUP" varchar(256),
+ "DESCRIPTION" varchar(4000)
+);
+
+CREATE TABLE "APP"."SCHEMA_VERSION" (
+ "SCHEMA_VERSION_ID" bigint primary key,
+ "SCHEMA_ID" bigint references "APP"."I_SCHEMA" ("SCHEMA_ID"),
+ "VERSION" integer not null,
+ "CREATED_AT" bigint not null,
+ "CD_ID" bigint references "APP"."CDS" ("CD_ID"),
+ "STATE" integer not null,
+ "DESCRIPTION" varchar(4000),
+ "SCHEMA_TEXT" clob,
+ "FINGERPRINT" varchar(256),
+ "SCHEMA_VERSION_NAME" varchar(256),
+ "SERDE_ID" bigint references "APP"."SERDES" ("SERDE_ID")
+);
+
+CREATE UNIQUE INDEX "APP"."UNIQUE_SCHEMA_VERSION" ON "APP"."SCHEMA_VERSION" ("SCHEMA_ID", "VERSION");
+
+CREATE TABLE REPL_TXN_MAP (
+ RTM_REPL_POLICY varchar(256) NOT NULL,
+ RTM_SRC_TXN_ID bigint NOT NULL,
+ RTM_TARGET_TXN_ID bigint NOT NULL,
+ PRIMARY KEY (RTM_REPL_POLICY, RTM_SRC_TXN_ID)
+);
+
+CREATE TABLE "APP"."RUNTIME_STATS" (
+ "RS_ID" bigint primary key,
+ "CREATE_TIME" integer not null,
+ "WEIGHT" integer not null,
+ "PAYLOAD" BLOB
+);
+
+CREATE INDEX IDX_RUNTIME_STATS_CREATE_TIME ON RUNTIME_STATS(CREATE_TIME);
+
+-- -----------------------------------------------------------------
+-- Record schema version. Should be the last step in the init script
+-- -----------------------------------------------------------------
+INSERT INTO "APP"."VERSION" (VER_ID, SCHEMA_VERSION, VERSION_COMMENT) VALUES (1, '3.1.0', 'Hive release version 3.1.0');
diff --git a/core/src/main/java/com/datastrato/graviton/EntityNotEmptyException.java b/core/src/main/java/com/datastrato/graviton/EntityNotEmptyException.java
new file mode 100644
index 0000000000..ac32c086a5
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/EntityNotEmptyException.java
@@ -0,0 +1,11 @@
+package com.datastrato.graviton;
+
+public class EntityNotEmptyException extends RuntimeException {
+ public EntityNotEmptyException(String message) {
+ super(message);
+ }
+
+ public EntityNotEmptyException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/catalog/SupportsNamespaces.java b/core/src/main/java/com/datastrato/graviton/meta/catalog/SupportsNamespaces.java
index 82aacd45a5..10759f13ec 100644
--- a/core/src/main/java/com/datastrato/graviton/meta/catalog/SupportsNamespaces.java
+++ b/core/src/main/java/com/datastrato/graviton/meta/catalog/SupportsNamespaces.java
@@ -75,6 +75,15 @@ public interface SupportsNamespaces {
void createNamespace(Namespace namespace, Map<String, String> metadata)
throws NamespaceAlreadyExistsException;
+ /**
+ * Load metadata properties for a namespace.
+ *
+ * @param namespace a namespace. {@link Namespace}
+ * @return a string map of properties for the given namespace
+ * @throws NoSuchNamespaceException If the namespace does not exist (optional)
+ */
+ Map<String, String> loadNamespaceMetadata(Namespace namespace) throws NoSuchNamespaceException;
+
/**
* Apply the metadata change to a namespace in the catalog.
*
diff --git a/core/src/main/java/com/datastrato/graviton/util/ClientPool.java b/core/src/main/java/com/datastrato/graviton/util/ClientPool.java
new file mode 100644
index 0000000000..f3d09ba6d5
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/util/ClientPool.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.datastrato.graviton.util;
+
+// core/src/main/java/org/apache/iceberg/ClientPool.java
+public interface ClientPool<C, E extends Exception> {
+ <R> R run(Action<R, C, E> action) throws E, InterruptedException;
+
+ <R> R run(Action<R, C, E> action, boolean retry) throws E, InterruptedException;
+
+ interface Action<R, C, E extends Exception> {
+ R run(C client) throws E;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/util/ClientPoolImpl.java b/core/src/main/java/com/datastrato/graviton/util/ClientPoolImpl.java
new file mode 100644
index 0000000000..bf344eb9b6
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/util/ClientPoolImpl.java
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.datastrato.graviton.util;
+
+import com.google.common.base.Preconditions;
+import java.io.Closeable;
+import java.util.ArrayDeque;
+import java.util.Deque;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// core/src/main/java/org/apache/iceberg/ClientPoolImpl.java
+public abstract class ClientPoolImpl<C, E extends Exception>
+ implements Closeable, ClientPool<C, E> {
+ private static final Logger LOG = LoggerFactory.getLogger(ClientPoolImpl.class);
+
+ private final int poolSize;
+ private final Deque<C> clients;
+ private final Class<? extends E> reconnectExc;
+ private final Object signal = new Object();
+ private final boolean retryByDefault;
+ private volatile int currentSize;
+ private boolean closed;
+
+ public ClientPoolImpl(int poolSize, Class<? extends E> reconnectExc, boolean retryByDefault) {
+ this.poolSize = poolSize;
+ this.reconnectExc = reconnectExc;
+ this.clients = new ArrayDeque<>(poolSize);
+ this.currentSize = 0;
+ this.closed = false;
+ this.retryByDefault = retryByDefault;
+ }
+
+ @Override
+ public <R> R run(Action<R, C, E> action) throws E, InterruptedException {
+ return run(action, retryByDefault);
+ }
+
+ @Override
+ public <R> R run(Action<R, C, E> action, boolean retry) throws E, InterruptedException {
+ C client = get();
+ try {
+ return action.run(client);
+
+ } catch (Exception exc) {
+ if (retry && isConnectionException(exc)) {
+ try {
+ client = reconnect(client);
+ } catch (Exception ignored) {
+ // if reconnection throws any exception, rethrow the original failure
+ throw reconnectExc.cast(exc);
+ }
+
+ return action.run(client);
+ }
+
+ throw exc;
+
+ } finally {
+ release(client);
+ }
+ }
+
+ protected abstract C newClient();
+
+ protected abstract C reconnect(C client);
+
+ protected boolean isConnectionException(Exception exc) {
+ return reconnectExc.isInstance(exc);
+ }
+
+ protected abstract void close(C client);
+
+ @Override
+ public void close() {
+ this.closed = true;
+ try {
+ while (currentSize > 0) {
+ if (!clients.isEmpty()) {
+ synchronized (this) {
+ if (!clients.isEmpty()) {
+ C client = clients.removeFirst();
+ close(client);
+ currentSize -= 1;
+ }
+ }
+ }
+ if (clients.isEmpty() && currentSize > 0) {
+ // wake every second in case this missed the signal
+ synchronized (signal) {
+ signal.wait(1000);
+ }
+ }
+ }
+
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ LOG.warn("Interrupted while shutting down pool. Some clients may not be closed.", e);
+ }
+ }
+
+ private C get() throws InterruptedException {
+ Preconditions.checkState(!closed, "Cannot get a client from a closed pool");
+ while (true) {
+ if (!clients.isEmpty() || currentSize < poolSize) {
+ synchronized (this) {
+ if (!clients.isEmpty()) {
+ return clients.removeFirst();
+ } else if (currentSize < poolSize) {
+ C client = newClient();
+ currentSize += 1;
+ return client;
+ }
+ }
+ }
+ synchronized (signal) {
+ // wake every second in case this missed the signal
+ signal.wait(1000);
+ }
+ }
+ }
+
+ private void release(C client) {
+ synchronized (this) {
+ clients.addFirst(client);
+ }
+ synchronized (signal) {
+ signal.notify();
+ }
+ }
+
+ public int poolSize() {
+ return poolSize;
+ }
+
+ public boolean isClosed() {
+ return closed;
+ }
+}
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index f060cc1d14..9838ac3382 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -10,12 +10,17 @@ log4j = "2.20.0"
jetty = "9.4.51.v20230217"
jersey = "2.39.1"
mockito = "3.12.4"
+airlift-units = "1.8"
+airlift-log = "231"
+hive2 = "2.3.9"
+hadoop2 = "2.7.3"
protobuf-plugin = "0.9.2"
spotless-plugin = '6.11.0'
gradle-extensions-plugin = '1.74'
publish-plugin = '1.1.0'
+
[libraries]
protobuf-java = { group = "com.google.protobuf", name = "protobuf-java", version.ref = "protoc" }
protobuf-java-util = { group = "com.google.protobuf", name = "protobuf-java-util", version.ref = "protoc" }
@@ -30,6 +35,7 @@ junit-jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", v
junit-jupiter-params = { group = "org.junit.jupiter", name = "junit-jupiter-params", version.ref = "junit" }
junit-jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine"}
slf4j-api = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" }
+slf4j-jdk14 = { group = "org.slf4j", name = "slf4j-jdk14", version = "1.7.30" }
log4j-slf4j2-impl = { group = "org.apache.logging.log4j", name = "log4j-slf4j2-impl", version.ref = "log4j" }
log4j-api = { group = "org.apache.logging.log4j", name = "log4j-api", version.ref = "log4j" }
log4j-core = { group = "org.apache.logging.log4j", name = "log4j-core", version.ref = "log4j" }
@@ -44,6 +50,12 @@ jersey-hk2 = { group = "org.glassfish.jersey.inject", name = "jersey-hk2", versi
jersey-test-framework-core = { group = "org.glassfish.jersey.test-framework", name = "jersey-test-framework-core", version.ref = "jersey" }
jersey-test-framework-provider-jetty = { group = "org.glassfish.jersey.test-framework.providers", name = "jersey-test-framework-provider-jetty", version.ref = "jersey" }
mockito-core = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" }
+hive2-metastore = { group = "org.apache.hive", name = "hive-metastore", version.ref = "hive2"}
+hive2-exec = { group = "org.apache.hive", name = "hive-exec", version.ref = "hive2"}
+airlift-units = { group = "io.airlift", name = "units", version.ref = "airlift-units"}
+airlift-log = { group = "io.airlift", name = "log", version.ref = "airlift-log"}
+hadoop2-common = { group = "org.apache.hadoop", name = "hadoop-common", version.ref = "hadoop2"}
+hadoop2-mapreduce-client-core = { group = "org.apache.hadoop", name = "hadoop-mapreduce-client-core", version.ref = "hadoop2"}
[bundles]
log4j = ["slf4j-api", "log4j-slf4j2-impl", "log4j-api", "log4j-core", "log4j-12-api"]
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 6f51454930..4c5bfd1f39 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -1,3 +1,3 @@
rootProject.name = "Graviton"
-include("core", "meta", "server")
+include("core", "meta", "server", "catalog-hive")