17 #include <boost/thread.hpp>
28 using namespace impala;
29 using namespace impala::extdatasource;
32 DCHECK(!is_initialized_);
36 const string& class_name,
const string& api_version) {
37 DCHECK(!is_initialized_);
38 string local_jar_path;
44 {
"<init>",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", &ctor_},
45 {
"open",
"([B)[B", &open_id_},
46 {
"getNext",
"([B)[B", &get_next_id_},
47 {
"close",
"([B)[B", &close_id_}};
55 jclass cl = jni_env->FindClass(
56 "com/cloudera/impala/extdatasource/ExternalDataSourceExecutor");
58 executor_class_ =
reinterpret_cast<jclass
>(jni_env->NewGlobalRef(cl));
60 uint32_t num_methods =
sizeof(methods) /
sizeof(methods[0]);
61 for (
int i = 0; i < num_methods; ++i) {
65 jstring jar_path_jstr = jni_env->NewStringUTF(local_jar_path.c_str());
67 jstring class_name_jstr = jni_env->NewStringUTF(class_name.c_str());
69 jstring api_version_jstr = jni_env->NewStringUTF(api_version.c_str());
72 jobject local_exec = jni_env->NewObject(executor_class_, ctor_, jar_path_jstr,
73 class_name_jstr, api_version_jstr);
75 executor_ = jni_env->NewGlobalRef(local_exec);
77 is_initialized_ =
true;
85 template <
typename T,
typename R>
89 jbyteArray request_bytes;
93 jbyteArray result_bytes =
static_cast<jbyteArray
>(
94 jni_env->CallObjectMethod(obj, method, request_bytes));
101 DCHECK(is_initialized_);
106 TGetNextResult* result) {
107 DCHECK(is_initialized_);
112 TCloseResult* result) {
113 DCHECK(is_initialized_);
121 if (executor_class_ != NULL) {
122 env->DeleteGlobalRef(executor_class_);
125 is_initialized_ =
false;
virtual ~ExternalDataSourceExecutor()
Status Init(const std::string &jar_path, const std::string &class_name, const std::string &api_version)
#define RETURN_IF_ERROR(stmt)
some generally useful macros
static Status LoadJniMethod(JNIEnv *jni_env, const jclass &jni_class, JniMethodDescriptor *descriptor)
void MergeStatus(const Status &status)
Status CallJniMethod(const jobject &obj, const jmethodID &method, const T &arg, R *response)
static Status GetJniExceptionMsg(JNIEnv *env, bool log_stack=true, const std::string &prefix="")
static LibCache * instance()
Status push(JNIEnv *env, int max_local_ref=10)
Describes one method to look up in a Java object.
#define RETURN_ERROR_IF_EXC(env)
Status Open(const impala::extdatasource::TOpenParams ¶ms, impala::extdatasource::TOpenResult *result)
Calls ExternalDataSource.open()
Status DeserializeThriftMsg(JNIEnv *env, jbyteArray serialized_msg, T *deserialized_msg)
ImpaladQueryExecutor * executor_
execution state of coordinator fragment
Status SerializeThriftMsg(JNIEnv *env, T *msg, jbyteArray *serialized_msg)
Status Close(const impala::extdatasource::TCloseParams ¶ms, impala::extdatasource::TCloseResult *result)
JNIEnv * getJNIEnv(void)
C linkage for helper functions in hdfsJniHelper.h.
Status GetNext(const impala::extdatasource::TGetNextParams ¶ms, impala::extdatasource::TGetNextResult *result)
Calls ExternalDataSource.getNext()