Skip to content

Commit

Permalink
fix: Spark-4.0 SparkArithmeticException
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuyukitanimura committed Jul 19, 2024
1 parent 94afd51 commit 11cd4b1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
package org.apache.spark.sql.comet

import org.apache.spark.SparkArithmeticException
import org.apache.spark.sql.errors.QueryExecutionErrors.toSQLConf
import org.apache.spark.sql.internal.SQLConf

class CometArithmeticException(message: String)
extends SparkArithmeticException("CAST_OVERFLOW", Map(), Array(), message) {}
class CometCastOverflowException(t: String, from: String, to: String)
extends SparkArithmeticException(
"CAST_OVERFLOW",
Map(
"value" -> t,
"sourceType" -> from,
"targetType" -> to,
"ansiConfig" -> toSQLConf(SQLConf.ANSI_ENABLED.key)),
Array.empty,
"") {}
36 changes: 28 additions & 8 deletions native/core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use jni::sys::{jboolean, jbyte, jchar, jdouble, jfloat, jint, jlong, jobject, js

use crate::execution::operators::ExecutionError;
use datafusion_comet_spark_expr::SparkError;
use jni::objects::{GlobalRef, JThrowable};
use jni::objects::{GlobalRef, JThrowable, JValue};
use jni::JNIEnv;
use lazy_static::lazy_static;
use parquet::errors::ParquetError;
Expand Down Expand Up @@ -234,13 +234,6 @@ impl jni::errors::ToException for CometError {
class: "org/apache/comet/ParquetRuntimeException".to_string(),
msg: self.to_string(),
},
CometError::DataFusion {
msg: _,
source: DataFusionError::External(e),
} if matches!(e.downcast_ref(), Some(SparkError::CastOverFlow { .. })) => Exception {
class: "org/apache/spark/sql/comet/CometArithmeticException".to_string(),
msg: self.to_string(),
},
_other => Exception {
class: "org/apache/comet/CometNativeException".to_string(),
msg: self.to_string(),
Expand Down Expand Up @@ -390,6 +383,33 @@ fn throw_exception(env: &mut JNIEnv, error: &CometError, backtrace: Option<Strin
throwable,
},
} => env.throw(<&JThrowable>::from(throwable.as_obj())),
CometError::DataFusion {
msg: _,
source: DataFusionError::External(e),
} if matches!(e.downcast_ref(), Some(SparkError::CastOverFlow { .. })) => {
match e.downcast_ref() {
Some(SparkError::CastOverFlow {
value,
from_type,
to_type,
}) => {
let throwable: JThrowable = env
.new_object(
"org/apache/spark/sql/comet/CometCastOverflowException",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
&[
JValue::Object(&env.new_string(value).unwrap()),
JValue::Object(&env.new_string(from_type).unwrap()),
JValue::Object(&env.new_string(to_type).unwrap()),
],
)
.unwrap()
.into();
env.throw(throwable)
}
_ => unreachable!(),
}
}
_ => {
let exception = error.to_exception();
match backtrace {
Expand Down

0 comments on commit 11cd4b1

Please sign in to comment.