use std::fmt;
use arrow_schema::{ArrowError, DataType};
#[derive(Debug)]
pub enum Error {
Core(runlength::Error),
Arrow(ArrowError),
InvalidFill {
expected: DataType,
actual: DataType,
len: usize,
},
WrongLength { expected: usize, actual: usize },
KeySchemaMismatch,
UnsupportedType(DataType),
UnexpectedNulls,
MissingValues,
NoInputs,
InKey { position: usize, source: Box<Error> },
}
impl Error {
pub(crate) fn in_key(self, position: usize) -> Self {
Error::InKey {
position,
source: Box::new(self),
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Core(e) => write!(f, "{e}"),
Error::Arrow(e) => write!(f, "{e}"),
Error::InvalidFill {
expected,
actual,
len,
} => write!(
f,
"fill must be one value of type {expected}, got {len} value(s) of type {actual}"
),
Error::WrongLength { expected, actual } => write!(
f,
"operation returned {actual} values for {expected} segments"
),
Error::KeySchemaMismatch => {
write!(f, "the batches' key columns have different names or types")
}
Error::UnsupportedType(t) => write!(f, "unsupported value type {t}"),
Error::UnexpectedNulls => write!(f, "values must not contain nulls"),
Error::MissingValues => write!(f, "this aggregation needs values"),
Error::NoInputs => write!(f, "this operation needs at least one input"),
Error::InKey { position, source } => {
write!(f, "key at output position {position}: {source}")
}
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Core(e) => Some(e),
Error::Arrow(e) => Some(e),
Error::InKey { source, .. } => Some(source.as_ref()),
_ => None,
}
}
}
impl From<runlength::Error> for Error {
fn from(e: runlength::Error) -> Self {
Error::Core(e)
}
}
impl From<ArrowError> for Error {
fn from(e: ArrowError) -> Self {
Error::Arrow(e)
}
}
pub type Result<T> = std::result::Result<T, Error>;