Skip to main content

densa_data/
error.rs

1use std::fmt;
2
3/// Why a table or view operation was refused. Nothing changes when one is returned.
4#[derive(Debug, Clone, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum DataError {
7    /// No column has this name.
8    UnknownColumn(String),
9    /// The key column must hold integers or strings.
10    UnsupportedKey(String),
11    /// Views and groups cannot read this column's data type (lists, structs, binary, ...).
12    UnsupportedColumn(String),
13    /// A filter's value or operation does not fit this column's type (text compared with a
14    /// number, `contains` on a number).
15    LiteralMismatch(String),
16    /// Sums and means need an integer, decimal or float column; this one holds something
17    /// else (text, booleans, dates, times).
18    NotNumeric(String),
19    /// A window's span does not fit its column: a `Duration` goes with dates, times and
20    /// timestamps, a number (zero or more) with integers, decimals and floats.
21    WindowSpan(String),
22    /// Two columns of a group spec's result would have this name.
23    DuplicateName(String),
24    /// The batch has a different number of columns.
25    ColumnCount {
26        /// Columns in the table.
27        expected: usize,
28        /// Columns in the batch.
29        found: usize,
30    },
31    /// The batch's column at this index has another name or data type.
32    ColumnMismatch {
33        /// Index of the first differing column.
34        column: usize,
35    },
36    /// A row of the batch has no key.
37    NullKey {
38        /// The row, within the batch.
39        row: usize,
40    },
41    /// Keys to delete or find are not of the key column's kind (text for a number key).
42    KeyType,
43    /// More than 2^32 live keys, or rows in one batch.
44    TooManyRows,
45    /// Arrow could not build a batch: compacting a table, or assembling groups.
46    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}