1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum DataError {
7 UnknownColumn(String),
9 UnsupportedKey(String),
11 UnsupportedColumn(String),
13 LiteralMismatch(String),
16 NotNumeric(String),
19 DuplicateName(String),
21 ColumnCount {
23 expected: usize,
25 found: usize,
27 },
28 ColumnMismatch {
30 column: usize,
32 },
33 NullKey {
35 row: usize,
37 },
38 KeyType,
40 TooManyRows,
42 Arrow(String),
44}
45
46impl fmt::Display for DataError {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 match self {
49 Self::UnknownColumn(name) => write!(f, "there is no column named {name:?}"),
50 Self::UnsupportedKey(name) => {
51 write!(f, "key column {name:?} must hold integers or strings")
52 }
53 Self::UnsupportedColumn(name) => {
54 write!(
55 f,
56 "views and groups cannot read column {name:?} of this type"
57 )
58 }
59 Self::LiteralMismatch(name) => {
60 write!(f, "the filter does not fit the type of column {name:?}")
61 }
62 Self::NotNumeric(name) => {
63 write!(f, "column {name:?} is not numeric: it cannot be summed")
64 }
65 Self::DuplicateName(name) => write!(f, "two result columns are named {name:?}"),
66 Self::ColumnCount { expected, found } => {
67 write!(f, "the batch has {found} columns, the table {expected}")
68 }
69 Self::ColumnMismatch { column } => {
70 write!(
71 f,
72 "column {column} of the batch has another name or data type"
73 )
74 }
75 Self::NullKey { row } => write!(f, "row {row} of the batch has a null key"),
76 Self::KeyType => f.write_str("the keys are not of the key column's kind"),
77 Self::TooManyRows => f.write_str("more than 2^32 live keys, or rows in one batch"),
78 Self::Arrow(message) => write!(f, "Arrow could not build a batch: {message}"),
79 }
80 }
81}
82
83impl std::error::Error for DataError {}
84
85impl DataError {
86 pub(crate) fn arrow(error: arrow_schema::ArrowError) -> Self {
87 Self::Arrow(error.to_string())
88 }
89}