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 "String/Binary data size ({} bytes) exceeds maximum offset size ({}) \
75 with current batch size {}. Please reduce the batch size to avoid offset overflow.",
76 total_length,
77 max_size,
78 batch_size,
79 ))]
80 OffsetOverflow {
81 #[snafu(implicit)]
82 location: Location,
83 total_length: i64,
84 max_size: i32,
85 batch_size: usize,
86 },
87
88 #[snafu(display("Failed to decode proto, source: {}", source))]
89 DecodeProto {
90 #[snafu(implicit)]
91 location: Location,
92 source: prost::DecodeError,
93 },
94
95 #[snafu(display("No types found"))]
96 NoTypes {
97 #[snafu(implicit)]
98 location: Location,
99 },
100
101 #[snafu(display("unsupported type variant: {}", msg))]
102 UnsupportedTypeVariant {
103 #[snafu(implicit)]
104 location: Location,
105 msg: &'static str,
106 },
107
108 #[snafu(display(
109 "Cannot decode ORC type {:?} into Arrow type {:?}",
110 orc_type,
111 arrow_type,
112 ))]
113 MismatchedSchema {
114 #[snafu(implicit)]
115 location: Location,
116 orc_type: DataType,
117 arrow_type: ArrowDataType,
118 },
119
120 #[snafu(display("Failed to convert to record batch: {}", source))]
121 ConvertRecordBatch {
122 #[snafu(implicit)]
123 location: Location,
124 source: ArrowError,
125 },
126
127 #[snafu(display("Varint being decoded is too large"))]
128 VarintTooLarge {
129 #[snafu(implicit)]
130 location: Location,
131 },
132
133 #[snafu(display("unexpected: {}", msg))]
134 Unexpected {
135 #[snafu(implicit)]
136 location: Location,
137 msg: String,
138 },
139
140 #[snafu(display("Failed to build zstd decoder: {}", source))]
141 BuildZstdDecoder {
142 #[snafu(implicit)]
143 location: Location,
144 source: io::Error,
145 },
146
147 #[snafu(display("Failed to build snappy decoder: {}", source))]
148 BuildSnappyDecoder {
149 #[snafu(implicit)]
150 location: Location,
151 source: snap::Error,
152 },
153
154 #[snafu(display("Failed to build lzo decoder: {}", source))]
155 BuildLzoDecoder {
156 #[snafu(implicit)]
157 location: Location,
158 source: lzokay_native::Error,
159 },
160
161 #[snafu(display("Failed to build lz4 decoder: {}", source))]
162 BuildLz4Decoder {
163 #[snafu(implicit)]
164 location: Location,
165 source: lz4_flex::block::DecompressError,
166 },
167
168 #[snafu(display("Arrow error: {}", source))]
169 Arrow {
170 source: arrow::error::ArrowError,
171 #[snafu(implicit)]
172 location: Location,
173 },
174}
175
176pub type Result<T, E = OrcError> = std::result::Result<T, E>;
177
178impl From<OrcError> for ArrowError {
179 fn from(value: OrcError) -> Self {
180 ArrowError::ExternalError(Box::new(value))
181 }
182}