diff --git a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/RetryingMetaStoreClientFactory.java b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/RetryingMetaStoreClientFactory.java index 2d62f56bc20f..0ac665fa4e11 100644 --- a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/RetryingMetaStoreClientFactory.java +++ b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/RetryingMetaStoreClientFactory.java @@ -32,6 +32,7 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; @@ -182,25 +183,30 @@ private static IMetaStoreClient constructorDetectedHiveMetastoreProxySupplier( Class baseClass = Class.forName(clientClassName, false, JavaUtils.getClassLoader()); // Configuration.class or HiveConf.class - Class firstParamType = getProxyMethod.getParameterTypes()[0]; - - Class[] fullParams = - new Class[] {firstParamType, HiveMetaHookLoader.class, Boolean.TYPE}; - Object[] fullParamValues = - new Object[] {hiveConf, (HiveMetaHookLoader) (tbl -> null), Boolean.TRUE}; - - for (int i = fullParams.length; i >= 1; i--) { - try { - baseClass.getConstructor(Arrays.copyOfRange(fullParams, 0, i)); - return (IMetaStoreClient) - getProxyMethod.invoke( - null, - hiveConf, - Arrays.copyOfRange(fullParams, 0, i), - Arrays.copyOfRange(fullParamValues, 0, i), - new ConcurrentHashMap<>(), - clientClassName); - } catch (NoSuchMethodException ignored) { + List> possibleFirstParamTypes = + Arrays.asList(getProxyMethod.getParameterTypes()[0], hiveConf.getClass()); + + for (Class possibleFirstParamType : possibleFirstParamTypes) { + Class[] fullParams = + new Class[] { + possibleFirstParamType, HiveMetaHookLoader.class, Boolean.TYPE + }; + Object[] fullParamValues = + new Object[] {hiveConf, (HiveMetaHookLoader) (tbl -> null), Boolean.TRUE}; + + for (int i = fullParams.length; i >= 1; i--) { + try { + baseClass.getConstructor(Arrays.copyOfRange(fullParams, 0, i)); + return (IMetaStoreClient) + getProxyMethod.invoke( + null, + hiveConf, + Arrays.copyOfRange(fullParams, 0, i), + Arrays.copyOfRange(fullParamValues, 0, i), + new ConcurrentHashMap<>(), + clientClassName); + } catch (NoSuchMethodException ignored) { + } } } diff --git a/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/CustomConstructorMetastoreClient.java b/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/CustomConstructorMetastoreClient.java index 35ff3f8bb778..6b08f16d4ab6 100644 --- a/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/CustomConstructorMetastoreClient.java +++ b/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/CustomConstructorMetastoreClient.java @@ -19,6 +19,7 @@ package org.apache.paimon.hive; 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; @@ -28,7 +29,7 @@ public class CustomConstructorMetastoreClient { /** - * A {@link HiveMetaStoreClient} to test custom Hive metastore client with (HiveConf, + * A {@link HiveMetaStoreClient} to test custom Hive metastore client with (Configuration, * HiveMetaHookLoader) constructor. */ public static class TwoParameterConstructorMetastoreClient extends HiveMetaStoreClient @@ -41,7 +42,7 @@ public TwoParameterConstructorMetastoreClient( } /** - * A {@link HiveMetaStoreClient} to test custom Hive metastore client with (HiveConf) + * A {@link HiveMetaStoreClient} to test custom Hive metastore client with (Configuration) * constructor. */ public static class OneParameterConstructorMetastoreClient extends HiveMetaStoreClient @@ -51,4 +52,16 @@ public OneParameterConstructorMetastoreClient(Configuration conf) throws MetaExc super(conf); } } + + /** + * A {@link HiveMetaStoreClient} to test custom Hive metastore client with (HiveConf) + * constructor. + */ + public static class OtherParameterConstructorMetastoreClient extends HiveMetaStoreClient + implements IMetaStoreClient { + + public OtherParameterConstructorMetastoreClient(HiveConf conf) throws MetaException { + super(conf); + } + } } diff --git a/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/Hive31CatalogITCase.java b/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/Hive31CatalogITCase.java index 7b3ab5626078..1a77723e948e 100644 --- a/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/Hive31CatalogITCase.java +++ b/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/Hive31CatalogITCase.java @@ -89,7 +89,8 @@ public void testCustomConstructorMetastoreClient() throws Exception { EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build(); Class[] customConstructorMetastoreClientClass = { CustomConstructorMetastoreClient.TwoParameterConstructorMetastoreClient.class, - CustomConstructorMetastoreClient.OneParameterConstructorMetastoreClient.class + CustomConstructorMetastoreClient.OneParameterConstructorMetastoreClient.class, + CustomConstructorMetastoreClient.OtherParameterConstructorMetastoreClient.class }; for (Class clazz : customConstructorMetastoreClientClass) {