1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
use std::io;
use std::string::FromUtf8Error;

use arrow::error::ArrowError;
pub use snafu::prelude::*;
use snafu::Location;

use crate::proto;
use crate::proto::r#type::Kind;

#[derive(Debug, Snafu)]
#[snafu(visibility(pub))]
pub enum OrcError {
    #[snafu(display("Failed to seek, source: {}", source))]
    SeekError {
        source: std::io::Error,
        location: Location,
    },

    #[snafu(display("Failed to read, source: {}", source))]
    IoError {
        source: std::io::Error,
        location: Location,
    },

    #[snafu(display("Empty file"))]
    EmptyFile { location: Location },

    #[snafu(display("Invalid input, message: {}", msg))]
    InvalidInput { msg: String, location: Location },

    #[snafu(display("Out of spec, message: {}", msg))]
    OutOfSpec { msg: String, location: Location },

    #[snafu(display("Error from map builder: {}", source))]
    MapBuilder {
        source: arrow::error::ArrowError,
        location: Location,
    },

    #[snafu(display("Failed to create new string builder: {}", source))]
    StringBuilder {
        source: arrow::error::ArrowError,
        location: Location,
    },

    #[snafu(display("Failed to decode float, source: {}", source))]
    DecodeFloat {
        location: Location,
        source: std::io::Error,
    },

    #[snafu(display("Failed to decode proto, source: {}", source))]
    DecodeProto {
        location: Location,
        source: prost::DecodeError,
    },

    #[snafu(display("No types found"))]
    NoTypes { location: Location },

    #[snafu(display("unsupported type: {:?}", kind))]
    UnsupportedType { location: Location, kind: Kind },

    #[snafu(display("Field not found: {:?}", name))]
    FieldNotFound { location: Location, name: String },

    #[snafu(display("Invalid column : {:?}", name))]
    InvalidColumn { location: Location, name: String },

    #[snafu(display("Invalid encoding for column '{}': {:?}", name, encoding))]
    InvalidColumnEncoding {
        location: Location,
        name: String,
        encoding: proto::column_encoding::Kind,
    },

    #[snafu(display("Failed to add day to a date"))]
    AddDays { location: Location },

    #[snafu(display("Invalid utf8, source: {}", source))]
    InvalidUft8 {
        location: Location,
        source: FromUtf8Error,
    },

    #[snafu(display("Out of bound at: {}", index))]
    OutOfBound { location: Location, index: usize },

    #[snafu(display("Failed to convert to record batch: {}", source))]
    ConvertRecordBatch {
        location: Location,
        source: ArrowError,
    },

    #[snafu(display("Varint being decoded is too large"))]
    VarintTooLarge { location: Location },

    #[snafu(display("unexpected: {}", msg))]
    Unexpected { location: Location, msg: String },

    #[snafu(display("Failed to build zstd decoder: {}", source))]
    BuildZstdDecoder {
        location: Location,
        source: io::Error,
    },

    #[snafu(display("Failed to build snappy decoder: {}", source))]
    BuildSnappyDecoder {
        location: Location,
        source: snap::Error,
    },

    #[snafu(display("Failed to build lzo decoder: {}", source))]
    BuildLzoDecoder {
        location: Location,
        source: lzokay_native::Error,
    },

    #[snafu(display("Failed to build lz4 decoder: {}", source))]
    BuildLz4Decoder {
        location: Location,
        source: lz4_flex::block::DecompressError,
    },

    #[snafu(display("Arrow error: {}", source))]
    Arrow {
        source: arrow::error::ArrowError,
        location: Location,
    },
}

pub type Result<T> = std::result::Result<T, OrcError>;

impl From<OrcError> for ArrowError {
    fn from(value: OrcError) -> Self {
        ArrowError::ExternalError(Box::new(value))
    }
}