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 WindowSpan(String),
22 DuplicateName(String),
24 ColumnCount {
26 expected: usize,
28 found: usize,
30 },
31 ColumnMismatch {
33 column: usize,
35 },
36 NullKey {
38 row: usize,
40 },
41 KeyType,
43 TooManyRows,
45 Arrow(String),
47}
48
49impl fmt::Display for DataError {
50 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51 match self {
52 Self::UnknownColumn(name) => write!(f, "there is no column named {name:?}"),
53 Self::UnsupportedKey(name) => {
54 write!(f, "key column {name:?} must hold integers or strings")
55 }
56 Self::UnsupportedColumn(name) => {
57 write!(
58 f,
59 "views and groups cannot read column {name:?} of this type"
60 )
61 }
62 Self::LiteralMismatch(name) => {
63 write!(f, "the filter does not fit the type of column {name:?}")
64 }
65 Self::NotNumeric(name) => {
66 write!(f, "column {name:?} is not numeric: it cannot be summed")
67 }
68 Self::WindowSpan(name) => {
69 write!(
70 f,
71 "the window's span does not fit the type of column {name:?}"
72 )
73 }
74 Self::DuplicateName(name) => write!(f, "two result columns are named {name:?}"),
75 Self::ColumnCount { expected, found } => {
76 write!(f, "the batch has {found} columns, the table {expected}")
77 }
78 Self::ColumnMismatch { column } => {
79 write!(
80 f,
81 "column {column} of the batch has another name or data type"
82 )
83 }
84 Self::NullKey { row } => write!(f, "row {row} of the batch has a null key"),
85 Self::KeyType => f.write_str("the keys are not of the key column's kind"),
86 Self::TooManyRows => f.write_str("more than 2^32 live keys, or rows in one batch"),
87 Self::Arrow(message) => write!(f, "Arrow could not build a batch: {message}"),
88 }
89 }
90}
91
92impl std::error::Error for DataError {}
93
94impl DataError {
95 pub(crate) fn arrow(error: arrow_schema::ArrowError) -> Self {
96 Self::Arrow(error.to_string())
97 }
98}