orc_rust/
error.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use 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::proto;
27use crate::schema::DataType;
28
29// TODO: consolidate error types? better to have a smaller set?
30#[derive(Debug, Snafu)]
31#[snafu(visibility(pub))]
32pub enum OrcError {
33    #[snafu(display("Failed to read, source: {}", source))]
34    IoError {
35        source: std::io::Error,
36        #[snafu(implicit)]
37        location: Location,
38    },
39
40    #[snafu(display("Empty file"))]
41    EmptyFile {
42        #[snafu(implicit)]
43        location: Location,
44    },
45
46    #[snafu(display("Out of spec, message: {}", msg))]
47    OutOfSpec {
48        msg: String,
49        #[snafu(implicit)]
50        location: Location,
51    },
52
53    #[snafu(display("Failed to decode float, source: {}", source))]
54    DecodeFloat {
55        #[snafu(implicit)]
56        location: Location,
57        source: std::io::Error,
58    },
59
60    #[snafu(display(
61        "Overflow while decoding timestamp (seconds={}, nanoseconds={}) to {:?}",
62        seconds,
63        nanoseconds,
64        to_time_unit,
65    ))]
66    DecodeTimestamp {
67        #[snafu(implicit)]
68        location: Location,
69        seconds: i64,
70        nanoseconds: u64,
71        to_time_unit: TimeUnit,
72    },
73
74    #[snafu(display("Failed to decode proto, source: {}", source))]
75    DecodeProto {
76        #[snafu(implicit)]
77        location: Location,
78        source: prost::DecodeError,
79    },
80
81    #[snafu(display("No types found"))]
82    NoTypes {
83        #[snafu(implicit)]
84        location: Location,
85    },
86
87    #[snafu(display("unsupported type variant: {}", msg))]
88    UnsupportedTypeVariant {
89        #[snafu(implicit)]
90        location: Location,
91        msg: &'static str,
92    },
93
94    #[snafu(display(
95        "Cannot decode ORC type {:?} into Arrow type {:?}",
96        orc_type,
97        arrow_type,
98    ))]
99    MismatchedSchema {
100        #[snafu(implicit)]
101        location: Location,
102        orc_type: DataType,
103        arrow_type: ArrowDataType,
104    },
105
106    #[snafu(display("Invalid encoding for column '{}': {:?}", name, encoding))]
107    InvalidColumnEncoding {
108        #[snafu(implicit)]
109        location: Location,
110        name: String,
111        encoding: proto::column_encoding::Kind,
112    },
113
114    #[snafu(display("Failed to convert to record batch: {}", source))]
115    ConvertRecordBatch {
116        #[snafu(implicit)]
117        location: Location,
118        source: ArrowError,
119    },
120
121    #[snafu(display("Varint being decoded is too large"))]
122    VarintTooLarge {
123        #[snafu(implicit)]
124        location: Location,
125    },
126
127    #[snafu(display("unexpected: {}", msg))]
128    Unexpected {
129        #[snafu(implicit)]
130        location: Location,
131        msg: String,
132    },
133
134    #[snafu(display("Failed to build zstd decoder: {}", source))]
135    BuildZstdDecoder {
136        #[snafu(implicit)]
137        location: Location,
138        source: io::Error,
139    },
140
141    #[snafu(display("Failed to build snappy decoder: {}", source))]
142    BuildSnappyDecoder {
143        #[snafu(implicit)]
144        location: Location,
145        source: snap::Error,
146    },
147
148    #[snafu(display("Failed to build lzo decoder: {}", source))]
149    BuildLzoDecoder {
150        #[snafu(implicit)]
151        location: Location,
152        source: lzokay_native::Error,
153    },
154
155    #[snafu(display("Failed to build lz4 decoder: {}", source))]
156    BuildLz4Decoder {
157        #[snafu(implicit)]
158        location: Location,
159        source: lz4_flex::block::DecompressError,
160    },
161
162    #[snafu(display("Arrow error: {}", source))]
163    Arrow {
164        source: arrow::error::ArrowError,
165        #[snafu(implicit)]
166        location: Location,
167    },
168}
169
170pub type Result<T, E = OrcError> = std::result::Result<T, E>;
171
172impl From<OrcError> for ArrowError {
173    fn from(value: OrcError) -> Self {
174        ArrowError::ExternalError(Box::new(value))
175    }
176}