Skip to content
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
31 changes: 1 addition & 30 deletions be/src/runtime/user_function_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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'!");
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions be/src/runtime/user_function_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ class UserFunctionCache {
Status _download_lib(const std::string& url, UserFunctionCacheEntry* entry);
Status _load_cache_entry_internal(UserFunctionCacheEntry* entry);

Status _add_to_classpath(UserFunctionCacheEntry* entry);

std::string _make_lib_file(int64_t function_id, const std::string& checksum, LibType type);
void _destroy_cache_entry(UserFunctionCacheEntry* entry);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ private void init(String jarPath, String udfPath, Type funcRetType, Type... para
classLoader = UdfUtils.getClassLoader(jarPath, parent);
loader = classLoader;
} else {
// for test
loader = ClassLoader.getSystemClassLoader();
}
Class<?> c = Class.forName(udfPath, true, loader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ private void init(String jarPath, String udfPath, Type funcRetType, Type... para
classLoader = UdfUtils.getClassLoader(jarPath, parent);
loader = classLoader;
} else {
// for test
loader = ClassLoader.getSystemClassLoader();
}
Class<?> c = Class.forName(udfPath, true, loader);
Expand Down