1use std::io;
19
20use arrow::datatypes::DataType as ArrowDataType;
21use arrow::datatypes::TimeUnit;
22use arrow::error::ArrowError;
23use snafu::prelude::*;
24use snafu::Location;
25
26use crate::schema::DataType;
27
28#[derive(Debug, Snafu)]
30#[snafu(visibility(pub))]
31pub enum OrcError {
32 #[snafu(display("Failed to read, source: {}", source))]
33 IoError {
34 source: std::io::Error,
35 #[snafu(implicit)]
36 location: Location,
37 },
38
39 #[snafu(display("Empty file"))]
40 EmptyFile {
41 #[snafu(implicit)]
42 location: Location,
43 },
44
45 #[snafu(display("Out of spec, message: {}", msg))]
46 OutOfSpec {
47 msg: String,
48 #[snafu(implicit)]
49 location: Location,
50 },
51
52 #[snafu(display("Failed to decode float, source: {}", source))]
53 DecodeFloat {
54 #[snafu(implicit)]
55 location: Location,
56 source: std::io::Error,
57 },
58
59 #[snafu(display(
60 "Overflow while decoding timestamp (seconds={}, nanoseconds={}) to {:?}",
61 seconds,
62 nanoseconds,
63 to_time_unit,
64 ))]
65 DecodeTimestamp {
66 #[snafu(implicit)]
67 location: Location,
68 seconds: i64,
69 nanoseconds: u64,
70 to_time_unit: TimeUnit,
71 },
72
73 #[snafu(display(
74 "Cannot encode timestamp value {} in {:?} as an ORC timestamp",
75 value,
76 time_unit,
77 ))]
78 EncodeTimestamp {
79 #[snafu(implicit)]
80 location: Location,
81 value: i64,
82 time_unit: TimeUnit,
83 },
84
85 #[snafu(display(
86 "String/Binary data size ({} bytes) exceeds maximum offset size ({}) \
87 with current batch size {}. Please reduce the batch size to avoid offset overflow.",
88 total_length,
89 max_size,
90 batch_size,
91 ))]
92 OffsetOverflow {
93 #[snafu(implicit)]
94 location: Location,
95 total_length: i64,
96 max_size: i32,
97 batch_size: usize,
98 },
99
100 #[snafu(display("Failed to decode proto, source: {}", source))]
101 DecodeProto {
102 #[snafu(implicit)]
103 location: Location,
104 source: prost::DecodeError,
105 },
106
107 #[snafu(display("No types found"))]
108 NoTypes {
109 #[snafu(implicit)]
110 location: Location,
111 },
112
113 #[snafu(display("unsupported type variant: {}", msg))]
114 UnsupportedTypeVariant {
115 #[snafu(implicit)]
116 location: Location,
117 msg: &'static str,
118 },
119
120 #[snafu(display(
121 "Cannot decode ORC type {:?} into Arrow type {:?}",
122 orc_type,
123 arrow_type,
124 ))]
125 MismatchedSchema {
126 #[snafu(implicit)]
127 location: Location,
128 orc_type: DataType,
129 arrow_type: ArrowDataType,
130 },
131
132 #[snafu(display("Failed to convert to record batch: {}", source))]
133 ConvertRecordBatch {
134 #[snafu(implicit)]
135 location: Location,
136 source: ArrowError,
137 },
138
139 #[snafu(display("Varint being decoded is too large"))]
140 VarintTooLarge {
141 #[snafu(implicit)]
142 location: Location,
143 },
144
145 #[snafu(display("unexpected: {}", msg))]
146 Unexpected {
147 #[snafu(implicit)]
148 location: Location,
149 msg: String,
150 },
151
152 #[snafu(display("Failed to build zstd decoder: {}", source))]
153 BuildZstdDecoder {
154 #[snafu(implicit)]
155 location: Location,
156 source: io::Error,
157 },
158
159 #[snafu(display("Failed to build snappy decoder: {}", source))]
160 BuildSnappyDecoder {
161 #[snafu(implicit)]
162 location: Location,
163 source: snap::Error,
164 },
165
166 #[snafu(display("Failed to build lzo decoder: {}", source))]
167 BuildLzoDecoder {
168 #[snafu(implicit)]
169 location: Location,
170 source: lzokay_native::Error,
171 },
172
173 #[snafu(display("Failed to build lz4 decoder: {}", source))]
174 BuildLz4Decoder {
175 #[snafu(implicit)]
176 location: Location,
177 source: lz4_flex::block::DecompressError,
178 },
179
180 #[snafu(display("Failed to compress Snappy block: {}", source))]
181 CompressSnappy {
182 #[snafu(implicit)]
183 location: Location,
184 source: snap::Error,
185 },
186
187 #[snafu(display("Failed to compress LZ4 block: {}", source))]
188 CompressLz4 {
189 #[snafu(implicit)]
190 location: Location,
191 source: lz4_flex::block::CompressError,
192 },
193
194 #[snafu(display("Arrow error: {}", source))]
195 Arrow {
196 source: arrow::error::ArrowError,
197 #[snafu(implicit)]
198 location: Location,
199 },
200}
201
202pub type Result<T, E = OrcError> = std::result::Result<T, E>;
203
204impl From<OrcError> for ArrowError {
205 fn from(value: OrcError) -> Self {
206 ArrowError::ExternalError(Box::new(value))
207 }
208}