Skip to content

Commit 351d0ff

Browse files
compheadandygrove
andauthored
feat: Fix Comet error message (#544)
* fix error message Co-authored-by: Andy Grove <[email protected]> --------- Co-authored-by: Andy Grove <[email protected]>
1 parent 0c9f79a commit 351d0ff

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

core/src/errors.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ pub enum CometError {
152152
#[error("{msg}")]
153153
Panic { msg: String },
154154

155-
#[error(transparent)]
155+
#[error("{msg}")]
156156
DataFusion {
157-
#[from]
157+
msg: String,
158+
#[source]
158159
source: DataFusionError,
159160
},
160161

@@ -185,10 +186,19 @@ impl convert::From<Box<dyn Any + Send>> for CometError {
185186
}
186187
}
187188

189+
impl From<DataFusionError> for CometError {
190+
fn from(value: DataFusionError) -> Self {
191+
CometError::DataFusion {
192+
msg: value.message().to_string(),
193+
source: value,
194+
}
195+
}
196+
}
197+
188198
impl From<CometError> for DataFusionError {
189199
fn from(value: CometError) -> Self {
190200
match value {
191-
CometError::DataFusion { source } => source,
201+
CometError::DataFusion { msg: _, source } => source,
192202
_ => DataFusionError::Execution(value.to_string()),
193203
}
194204
}

core/src/execution/datafusion/planner.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ impl PhysicalPlanner {
13911391

13921392
impl From<DataFusionError> for ExecutionError {
13931393
fn from(value: DataFusionError) -> Self {
1394-
ExecutionError::DataFusionError(value.to_string())
1394+
ExecutionError::DataFusionError(value.message().to_string())
13951395
}
13961396
}
13971397

@@ -1563,6 +1563,7 @@ mod tests {
15631563
spark_operator,
15641564
};
15651565

1566+
use crate::execution::operators::ExecutionError;
15661567
use spark_expression::expr::ExprStruct::*;
15671568
use spark_operator::{operator::OpStruct, Operator};
15681569

@@ -1752,6 +1753,14 @@ mod tests {
17521753
assert!(output.is_empty());
17531754
}
17541755

1756+
#[tokio::test()]
1757+
async fn from_datafusion_error_to_comet() {
1758+
let err_msg = "exec error";
1759+
let err = datafusion_common::DataFusionError::Execution(err_msg.to_string());
1760+
let comet_err: ExecutionError = err.into();
1761+
assert_eq!(comet_err.to_string(), "Error from DataFusion: exec error.");
1762+
}
1763+
17551764
// Creates a filter operator which takes an `Int32Array` and selects rows that are equal to
17561765
// `value`.
17571766
fn create_filter(child_op: spark_operator::Operator, value: i32) -> spark_operator::Operator {

core/src/execution/operators/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ pub use copy::*;
3838
pub enum ExecutionError {
3939
/// Simple error
4040
#[allow(dead_code)]
41-
#[error("General execution error with reason {0}.")]
41+
#[error("General execution error with reason: {0}.")]
4242
GeneralError(String),
4343

4444
/// Error when deserializing an operator.
45-
#[error("Fail to deserialize to native operator with reason {0}.")]
45+
#[error("Fail to deserialize to native operator with reason: {0}.")]
4646
DeserializeError(String),
4747

4848
/// Error when processing Arrow array.
49-
#[error("Fail to process Arrow array with reason {0}.")]
49+
#[error("Fail to process Arrow array with reason: {0}.")]
5050
ArrowError(String),
5151

5252
/// DataFusion error
53-
#[error("Error from DataFusion {0}.")]
53+
#[error("Error from DataFusion: {0}.")]
5454
DataFusionError(String),
5555
}
5656

spark/src/test/scala/org/apache/comet/CometCastSuite.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -984,9 +984,7 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
984984
// both systems threw an exception so we make sure they are the same
985985
val sparkMessage =
986986
if (sparkException.getCause != null) sparkException.getCause.getMessage else null
987-
// We have to workaround https://github.com/apache/datafusion-comet/issues/293 here by
988-
// removing the "Execution error: " error message prefix that is added by DataFusion
989-
val cometMessage = cometException.getCause.getMessage.replace("Execution error: ", "")
987+
val cometMessage = cometException.getCause.getMessage
990988
if (CometSparkSessionExtensions.isSpark40Plus) {
991989
// for Spark 4 we expect to sparkException carries the message
992990
assert(

0 commit comments

Comments
 (0)