refactor: Refactor usage of BoxedError (#48)

* feat: Define a general boxed error

* refactor: common_function use Error in common_query

* feat: Add tests to define_opaque_error macro

* refactor: Refactor table and table engine error

* refactor: recordbatch remove arrow dev-dependency

* refactor: datanode crate use common_error::BoxedError

* chore: Fix clippy

* feat: Returning source status code when using BoxedError

* test: Fix opaque error test

* test: Add tests for table::Error & table_engine::Error

* test: Add test for RecordBatch::new()

* test: Remove generated tests from define_opaque_error

* chore: Address cr comment
This commit is contained in:
evenyag
2022-06-21 15:24:45 +08:00
committed by GitHub
parent 4071b0cff2
commit 6ec870625f
18 changed files with 268 additions and 191 deletions

View File

@@ -1,13 +1,8 @@
use std::any::Any;
use common_error::prelude::*;
use common_query::error::Error as QueryError;
pub use common_query::error::{Error, Result};
use datatypes::error::Error as DataTypeError;
use snafu::GenerateImplicitData;
common_error::define_opaque_error!(Error);
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Snafu)]
#[snafu(visibility(pub))]
@@ -35,17 +30,10 @@ impl From<InnerError> for Error {
}
}
impl From<Error> for QueryError {
fn from(err: Error) -> Self {
QueryError::External {
msg: err.to_string(),
backtrace: Backtrace::generate(),
}
}
}
#[cfg(test)]
mod tests {
use snafu::GenerateImplicitData;
use super::*;
fn raise_datatype_error() -> std::result::Result<(), DataTypeError> {
@@ -57,13 +45,11 @@ mod tests {
#[test]
fn test_get_scalar_vector_error() {
let err = raise_datatype_error()
let err: Error = raise_datatype_error()
.context(GetScalarVectorSnafu)
.err()
.unwrap();
.unwrap()
.into();
assert!(err.backtrace_opt().is_some());
let query_error = QueryError::from(Error::from(err));
assert!(matches!(query_error, QueryError::External { .. }));
}
}

View File

@@ -41,13 +41,15 @@ pub fn create_udf(func: FunctionRef) -> ScalarUdf {
let result = func_cloned.eval(func_ctx, &args.context(FromScalarValueSnafu)?);
if len.is_some() {
result.map(ColumnarValue::Vector).map_err(|e| e.into())
let udf = if len.is_some() {
result.map(ColumnarValue::Vector)?
} else {
ScalarValue::try_from_array(&result?.to_arrow_array(), 0)
.map(ColumnarValue::Scalar)
.context(ExecuteFunctionSnafu)
}
.context(ExecuteFunctionSnafu)?
};
Ok(udf)
});
ScalarUdf::new(func.name(), &func.signature(), &return_type, &fun)