Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hive] Fix wrong construct for dlf metastore #4387

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Class<?>> 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) {
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading