Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions datafusion/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub enum DataFusionError {

impl DataFusionError {
/// Wraps this [DataFusionError] as an [arrow::error::ArrowError].
///
/// TODO this can be removed in favor if the conversion below

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #1645

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// TODO this can be removed in favor if the conversion below
/// TODO this can be removed in favor of the conversion below

Why not remove this now? If we want to keep it, then it would be better to add a deprecated attribute.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry -- I removed it in #1645 (probably wasn't worth leaving a TODO) 🤔

pub fn into_arrow_external_error(self) -> ArrowError {
ArrowError::from_external_error(Box::new(self))
}
Expand All @@ -91,6 +93,16 @@ impl From<ArrowError> for DataFusionError {
}
}

impl From<DataFusionError> for ArrowError {
fn from(e: DataFusionError) -> Self {
match e {
DataFusionError::ArrowError(e) => e,
DataFusionError::External(e) => ArrowError::ExternalError(e),
other => ArrowError::ExternalError(Box::new(other)),
}
}
}

impl From<ParquetError> for DataFusionError {
fn from(e: ParquetError) -> Self {
DataFusionError::ParquetError(e)
Expand Down Expand Up @@ -155,3 +167,42 @@ impl Display for DataFusionError {
}

impl error::Error for DataFusionError {}

#[cfg(test)]
mod test {
use crate::error::DataFusionError;
use arrow::error::ArrowError;

#[test]
fn arrow_error_to_datafusion() {
let res = return_arrow_error().unwrap_err();
assert_eq!(
res.to_string(),
"External error: Error during planning: foo"
);
}

#[test]
fn datafusion_error_to_arrow() {
let res = return_datafusion_error().unwrap_err();
assert_eq!(res.to_string(), "Arrow error: Schema error: bar");
}

/// Model what happens when implementing SendableRecrordBatchStream:
/// DataFusion code needs to return an ArrowError
#[allow(clippy::try_err)]
fn return_arrow_error() -> arrow::error::Result<()> {
// Expect the '?' to work
let _foo = Err(DataFusionError::Plan("foo".to_string()))?;
Ok(())
}

/// Model what happens when using arrow kernels in DataFusion
/// code: need to turn an ArrowError into a DataFusionError
#[allow(clippy::try_err)]
fn return_datafusion_error() -> crate::error::Result<()> {
// Expect the '?' to work
let _bar = Err(ArrowError::SchemaError("bar".to_string()))?;
Ok(())
}
}