[JavaUDF](loader) Fix compatible problem for JAVA 11 (#14519)
This commit is contained in:
@ -307,9 +307,7 @@ Status UserFunctionCache::_load_cache_entry(const std::string& url, UserFunction
|
||||
|
||||
if (entry->type == LibType::SO) {
|
||||
RETURN_IF_ERROR(_load_cache_entry_internal(entry));
|
||||
} else if (entry->type == LibType::JAR) {
|
||||
RETURN_IF_ERROR(_add_to_classpath(entry));
|
||||
} else {
|
||||
} else if (entry->type != LibType::JAR) {
|
||||
return Status::InvalidArgument(
|
||||
"Unsupported lib type! Make sure your lib type is one of 'so' and 'jar'!");
|
||||
}
|
||||
@ -376,33 +374,6 @@ Status UserFunctionCache::_load_cache_entry_internal(UserFunctionCacheEntry* ent
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status UserFunctionCache::_add_to_classpath(UserFunctionCacheEntry* entry) {
|
||||
if (config::enable_java_support) {
|
||||
const std::string path = "file://" + entry->lib_file;
|
||||
LOG(INFO) << "Add jar " << path << " to classpath";
|
||||
JNIEnv* env;
|
||||
RETURN_IF_ERROR(JniUtil::GetJNIEnv(&env));
|
||||
jclass class_class_loader = env->FindClass("java/lang/ClassLoader");
|
||||
jmethodID method_get_system_class_loader = env->GetStaticMethodID(
|
||||
class_class_loader, "getSystemClassLoader", "()Ljava/lang/ClassLoader;");
|
||||
jobject class_loader =
|
||||
env->CallStaticObjectMethod(class_class_loader, method_get_system_class_loader);
|
||||
jclass class_url_class_loader = env->FindClass("java/net/URLClassLoader");
|
||||
jmethodID method_add_url =
|
||||
env->GetMethodID(class_url_class_loader, "addURL", "(Ljava/net/URL;)V");
|
||||
jclass class_url = env->FindClass("java/net/URL");
|
||||
jmethodID url_ctor = env->GetMethodID(class_url, "<init>", "(Ljava/lang/String;)V");
|
||||
jobject urlInstance = env->NewObject(class_url, url_ctor, env->NewStringUTF(path.c_str()));
|
||||
env->CallVoidMethod(class_loader, method_add_url, urlInstance);
|
||||
entry->is_loaded.store(true);
|
||||
return Status::OK();
|
||||
} else {
|
||||
return Status::InternalError(
|
||||
"Java UDF is not enabled, you can change be config enable_java_support to true and "
|
||||
"restart be.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string UserFunctionCache::_make_lib_file(int64_t function_id, const std::string& checksum,
|
||||
LibType type) {
|
||||
int shard = function_id % kLibShardNum;
|
||||
|
||||
Reference in New Issue
Block a user