Skip to content

Commit

Permalink
upgrade jni and tokio
Browse files Browse the repository at this point in the history
  • Loading branch information
jimexist committed Sep 1, 2023
1 parent cd3b4a7 commit 83f6be1
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public CompletableFuture<ArrowReader> collect(BufferAllocator allocator) {
}

private boolean containsError(String errString) {
return errString != null && !"".equals(errString);
return errString != null && !errString.isEmpty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CompletableFuture<DataFrame> sql(String sql) {
getPointer(),
sql,
(errMessage, dataframeId) -> {
if (null != errMessage && !errMessage.equals("")) {
if (null != errMessage && !errMessage.isEmpty()) {
future.completeExceptionally(new RuntimeException(errMessage));
} else {
DefaultDataFrame frame = new DefaultDataFrame(DefaultSessionContext.this, dataframeId);
Expand Down Expand Up @@ -65,7 +65,7 @@ public CompletableFuture<Void> registerParquet(String name, Path path) {
}

private void voidCallback(CompletableFuture<Void> future, String errMessage) {
if (null != errMessage && !errMessage.equals("")) {
if (null != errMessage && !errMessage.isEmpty()) {
future.completeExceptionally(new RuntimeException(errMessage));
} else {
future.complete(null);
Expand Down
4 changes: 2 additions & 2 deletions datafusion-jni/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ license = "Apache-2.0"
edition = "2021"

[dependencies]
jni = "^0.19.0"
tokio = "^1.18.0"
jni = "^0.21.0"
tokio = "^1.32.0"
arrow = "^22.0"
datafusion = "^12.0"

Expand Down
84 changes: 46 additions & 38 deletions datafusion-jni/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ use jni::JNIEnv;
use tokio::runtime::Runtime;

#[no_mangle]
pub extern "system" fn Java_org_apache_arrow_datafusion_DefaultSessionContext_registerCsv(
env: JNIEnv,
_class: JClass,
pub extern "system" fn Java_org_apache_arrow_datafusion_DefaultSessionContext_registerCsv<
'local,
>(
mut env: JNIEnv<'local>,
_class: &JClass<'local>,
runtime: jlong,
pointer: jlong,
name: JString,
path: JString,
callback: JObject,
name: &JString<'local>,
path: &JString<'local>,
callback: &JObject<'local>,
) {
let runtime = unsafe { &mut *(runtime as *mut Runtime) };
let name: String = env
Expand All @@ -29,29 +31,32 @@ pub extern "system" fn Java_org_apache_arrow_datafusion_DefaultSessionContext_re
let register_result = context
.register_csv(&name, &path, CsvReadOptions::new())
.await;
let err_message: JValue = match register_result {
Ok(_) => JValue::Void,
Err(err) => {
let err_message = env
.new_string(err.to_string())
.expect("Couldn't create java string!");
err_message.into()
}
let err_message = match register_result {
Ok(_) => "".to_string(),
Err(err) => err.to_string(),
};
env.call_method(callback, "accept", "(Ljava/lang/Object;)V", &[err_message])
.expect("failed to callback method");
let err_message = env
.new_string(err_message)
.expect("Couldn't create java string!");
env.call_method(
callback,
"accept",
"(Ljava/lang/Object;)V",
&[(&err_message).into()],
)
.expect("failed to callback method");
});
}

#[no_mangle]
pub extern "system" fn Java_org_apache_arrow_datafusion_DefaultSessionContext_registerParquet(
env: JNIEnv,
_class: JClass,
mut env: JNIEnv,
_class: &JClass,
runtime: jlong,
pointer: jlong,
name: JString,
path: JString,
callback: JObject,
name: &JString,
path: &JString,
callback: &JObject,
) {
let runtime = unsafe { &mut *(runtime as *mut Runtime) };
let name: String = env
Expand All @@ -67,28 +72,31 @@ pub extern "system" fn Java_org_apache_arrow_datafusion_DefaultSessionContext_re
let register_result = context
.register_parquet(&name, &path, ParquetReadOptions::default())
.await;
let err_message: JValue = match register_result {
Ok(_) => JValue::Void,
Err(err) => {
let err_message = env
.new_string(err.to_string())
.expect("Couldn't create java string!");
err_message.into()
}
let err_message = match register_result {
Ok(_) => "".to_string(),
Err(err) => err.to_string(),
};
env.call_method(callback, "accept", "(Ljava/lang/Object;)V", &[err_message])
.expect("failed to callback method");
let err_message = env
.new_string(err_message)
.expect("Couldn't create java string!");
env.call_method(
callback,
"accept",
"(Ljava/lang/Object;)V",
&[(&err_message).into()],
)
.expect("failed to callback method");
});
}

#[no_mangle]
pub extern "system" fn Java_org_apache_arrow_datafusion_DefaultSessionContext_querySql(
env: JNIEnv,
_class: JClass,
mut env: JNIEnv,
_class: &JClass,
runtime: jlong,
pointer: jlong,
sql: JString,
callback: JObject,
sql: &JString,
callback: &JObject,
) {
let runtime = unsafe { &mut *(runtime as *mut Runtime) };
let sql: String = env
Expand Down Expand Up @@ -117,7 +125,7 @@ pub extern "system" fn Java_org_apache_arrow_datafusion_DefaultSessionContext_qu
callback,
"callback",
"(Ljava/lang/String;J)V",
&[err_message.into(), dataframe.into()],
&[(&err_message).into(), dataframe.into()],
)
}
}
Expand All @@ -127,7 +135,7 @@ pub extern "system" fn Java_org_apache_arrow_datafusion_DefaultSessionContext_qu
#[no_mangle]
pub extern "system" fn Java_org_apache_arrow_datafusion_SessionContexts_destroySessionContext(
_env: JNIEnv,
_class: JClass,
_class: &JClass,
pointer: jlong,
) {
let _ = unsafe { Box::from_raw(pointer as *mut SessionContext) };
Expand All @@ -136,7 +144,7 @@ pub extern "system" fn Java_org_apache_arrow_datafusion_SessionContexts_destroyS
#[no_mangle]
pub extern "system" fn Java_org_apache_arrow_datafusion_SessionContexts_createSessionContext(
_env: JNIEnv,
_class: JClass,
_class: &JClass,
) -> jlong {
let context = SessionContext::new();
Box::into_raw(Box::new(context)) as jlong
Expand Down
Loading

0 comments on commit 83f6be1

Please sign in to comment.