From 49364c08918daa0635e63086e43edfdd63a7a710 Mon Sep 17 00:00:00 2001 From: Kazuyuki Tanimura Date: Thu, 30 May 2024 17:27:52 -0700 Subject: [PATCH] build: Enable spark-4.0 Spark tests --- core/src/errors.rs | 30 ++++++++++++++++++++---------- core/src/jvm_bridge/mod.rs | 4 ++++ dev/diffs/4.0.0.diff | 14 +++++++------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/core/src/errors.rs b/core/src/errors.rs index 04a1629d5..b54abe4ef 100644 --- a/core/src/errors.rs +++ b/core/src/errors.rs @@ -38,6 +38,7 @@ use jni::sys::{jboolean, jbyte, jchar, jdouble, jfloat, jint, jlong, jobject, js use crate::execution::operators::ExecutionError; use jni::JNIEnv; +use jni::objects::{GlobalRef, JThrowable}; use lazy_static::lazy_static; use parquet::errors::ParquetError; use thiserror::Error; @@ -156,7 +157,7 @@ pub enum CometError { }, #[error("{class}: {msg}")] - JavaException { class: String, msg: String }, + JavaException { class: String, msg: String, throwable: GlobalRef }, } pub fn init() { @@ -366,19 +367,28 @@ pub fn unwrap_or_throw_default( } } -fn throw_exception(env: &mut JNIEnv, error: &E, backtrace: Option) { +fn throw_exception(env: &mut JNIEnv, error: &CometError, backtrace: Option) { // If there isn't already an exception? if env.exception_check().is_ok() { // ... then throw new exception - let exception = error.to_exception(); - match backtrace { - Some(backtrace_string) => env.throw_new( - exception.class, - to_stacktrace_string(exception.msg, backtrace_string).unwrap(), - ), - _ => env.throw_new(exception.class, exception.msg), + match error { + CometError::JavaException { class: _, msg: _, throwable } => { + let obj = env.new_local_ref(throwable).unwrap(); + // let obj = env.alloc_object(JClass::from(obj)).unwrap(); + env.throw(JThrowable::from(obj)) + } + _ => { + let exception = error.to_exception(); + match backtrace { + Some(backtrace_string) => env.throw_new( + exception.class, + to_stacktrace_string(exception.msg, backtrace_string).unwrap(), + ), + _ => env.throw_new(exception.class, exception.msg), + } + } } - .expect("Thrown exception") + .expect("Thrown exception") } } diff --git a/core/src/jvm_bridge/mod.rs b/core/src/jvm_bridge/mod.rs index 41376f03b..d3eae07ec 100644 --- a/core/src/jvm_bridge/mod.rs +++ b/core/src/jvm_bridge/mod.rs @@ -382,8 +382,12 @@ pub(crate) fn convert_exception( let exception_class_name_str = get_throwable_class_name(env, cache, throwable)?; let message_str = get_throwable_message(env, cache, throwable)?; + // let obj = env.new_local_ref(throwable).unwrap(); + // let obj = env.alloc_object(JClass::from(obj)).unwrap(); + Ok(CometError::JavaException { class: exception_class_name_str, msg: message_str, + throwable: env.new_global_ref(throwable)?, }) } diff --git a/dev/diffs/4.0.0.diff b/dev/diffs/4.0.0.diff index d5d9f0e1b..92a0de0a6 100644 --- a/dev/diffs/4.0.0.diff +++ b/dev/diffs/4.0.0.diff @@ -1,5 +1,5 @@ diff --git a/pom.xml b/pom.xml -index 6bbcf05b59e..59300f94bef 100644 +index 36d12b9b528..4a459825eb2 100644 --- a/pom.xml +++ b/pom.xml @@ -147,6 +147,8 @@ @@ -11,7 +11,7 @@ index 6bbcf05b59e..59300f94bef 100644