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