Coverage Report

Created: 2026-04-11 13:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format/parquet/decoder.cpp
Line
Count
Source
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
18
#include "format/parquet/decoder.h"
19
20
#include <cctz/time_zone.h>
21
#include <gen_cpp/parquet_types.h>
22
23
#include "format/parquet/bool_plain_decoder.h"
24
#include "format/parquet/bool_rle_decoder.h"
25
#include "format/parquet/byte_array_dict_decoder.h"
26
#include "format/parquet/byte_array_plain_decoder.h"
27
#include "format/parquet/byte_stream_split_decoder.h"
28
#include "format/parquet/delta_bit_pack_decoder.h"
29
#include "format/parquet/fix_length_dict_decoder.hpp"
30
#include "format/parquet/fix_length_plain_decoder.h"
31
32
namespace doris {
33
Status Decoder::get_decoder(tparquet::Type::type type, tparquet::Encoding::type encoding,
34
160k
                            std::unique_ptr<Decoder>& decoder) {
35
160k
    switch (encoding) {
36
71.1k
    case tparquet::Encoding::PLAIN:
37
71.1k
        switch (type) {
38
5.22k
        case tparquet::Type::BOOLEAN:
39
5.22k
            decoder.reset(new BoolPlainDecoder());
40
5.22k
            break;
41
22.7k
        case tparquet::Type::BYTE_ARRAY:
42
22.7k
            decoder.reset(new ByteArrayPlainDecoder());
43
22.7k
            break;
44
21.2k
        case tparquet::Type::INT32:
45
31.7k
        case tparquet::Type::INT64:
46
31.8k
        case tparquet::Type::INT96:
47
34.1k
        case tparquet::Type::FLOAT:
48
38.2k
        case tparquet::Type::DOUBLE:
49
43.1k
        case tparquet::Type::FIXED_LEN_BYTE_ARRAY:
50
43.1k
            decoder.reset(new FixLengthPlainDecoder());
51
43.1k
            break;
52
0
        default:
53
0
            return Status::InternalError("Unsupported type {}(encoding={}) in parquet decoder",
54
0
                                         tparquet::to_string(type), tparquet::to_string(encoding));
55
71.1k
        }
56
71.1k
        break;
57
88.1k
    case tparquet::Encoding::RLE_DICTIONARY:
58
88.1k
        switch (type) {
59
0
        case tparquet::Type::BOOLEAN:
60
0
            return Status::InternalError("Bool type can't has dictionary page");
61
27.1k
        case tparquet::Type::BYTE_ARRAY:
62
27.1k
            decoder.reset(new ByteArrayDictDecoder());
63
27.1k
            break;
64
26.5k
        case tparquet::Type::INT32:
65
26.5k
            decoder.reset(new FixLengthDictDecoder<tparquet::Type::INT32>());
66
26.5k
            break;
67
12.1k
        case tparquet::Type::INT64:
68
12.1k
            decoder.reset(new FixLengthDictDecoder<tparquet::Type::INT64>());
69
12.1k
            break;
70
1.71k
        case tparquet::Type::INT96:
71
1.71k
            decoder.reset(new FixLengthDictDecoder<tparquet::Type::INT96>());
72
1.71k
            break;
73
3.24k
        case tparquet::Type::FLOAT:
74
3.24k
            decoder.reset(new FixLengthDictDecoder<tparquet::Type::FLOAT>());
75
3.24k
            break;
76
7.71k
        case tparquet::Type::DOUBLE:
77
7.71k
            decoder.reset(new FixLengthDictDecoder<tparquet::Type::DOUBLE>());
78
7.71k
            break;
79
9.68k
        case tparquet::Type::FIXED_LEN_BYTE_ARRAY:
80
9.68k
            decoder.reset(new FixLengthDictDecoder<tparquet::Type::FIXED_LEN_BYTE_ARRAY>());
81
9.68k
            break;
82
0
        default:
83
0
            return Status::InternalError("Unsupported type {}(encoding={}) in parquet decoder",
84
0
                                         tparquet::to_string(type), tparquet::to_string(encoding));
85
88.1k
        }
86
88.1k
        break;
87
88.1k
    case tparquet::Encoding::RLE:
88
384
        switch (type) {
89
384
        case tparquet::Type::BOOLEAN:
90
384
            decoder.reset(new BoolRLEDecoder());
91
384
            break;
92
0
        default:
93
0
            return Status::InternalError("Unsupported type {}(encoding={}) in parquet decoder",
94
0
                                         tparquet::to_string(type), tparquet::to_string(encoding));
95
384
        }
96
384
        break;
97
898
    case tparquet::Encoding::DELTA_BINARY_PACKED:
98
        // Supports only INT32 and INT64.
99
898
        switch (type) {
100
50
        case tparquet::Type::INT32:
101
50
            decoder.reset(new DeltaBitPackDecoder<int32_t>());
102
50
            break;
103
848
        case tparquet::Type::INT64:
104
848
            decoder.reset(new DeltaBitPackDecoder<int64_t>());
105
848
            break;
106
0
        default:
107
0
            return Status::InternalError("DELTA_BINARY_PACKED only supports INT32 and INT64");
108
898
        }
109
898
        break;
110
898
    case tparquet::Encoding::DELTA_BYTE_ARRAY:
111
146
        switch (type) {
112
146
        case tparquet::Type::BYTE_ARRAY:
113
146
        case tparquet::Type::FIXED_LEN_BYTE_ARRAY:
114
146
            decoder.reset(new DeltaByteArrayDecoder());
115
146
            break;
116
0
        default:
117
0
            return Status::InternalError(
118
0
                    "DELTA_BYTE_ARRAY only supports BYTE_ARRAY, FIXED_LEN_BYTE_ARRAY.");
119
146
        }
120
146
        break;
121
146
    case tparquet::Encoding::DELTA_LENGTH_BYTE_ARRAY:
122
4
        switch (type) {
123
4
        case tparquet::Type::BYTE_ARRAY:
124
4
            decoder.reset(new DeltaLengthByteArrayDecoder());
125
4
            break;
126
0
        default:
127
0
            return Status::InternalError("DELTA_LENGTH_BYTE_ARRAY only supports BYTE_ARRAY.");
128
4
        }
129
4
        break;
130
18
    case tparquet::Encoding::BYTE_STREAM_SPLIT:
131
18
        switch (type) {
132
2
        case tparquet::Type::INT32:
133
4
        case tparquet::Type::INT64:
134
4
        case tparquet::Type::INT96:
135
8
        case tparquet::Type::FLOAT:
136
12
        case tparquet::Type::DOUBLE:
137
18
        case tparquet::Type::FIXED_LEN_BYTE_ARRAY:
138
18
            decoder.reset(new ByteStreamSplitDecoder());
139
18
            break;
140
0
        default:
141
0
            return Status::InternalError("Unsupported type {}(encoding={}) in parquet decoder",
142
0
                                         tparquet::to_string(type), tparquet::to_string(encoding));
143
18
        }
144
18
        break;
145
18
    default:
146
0
        return Status::InternalError("Unsupported encoding {}(type={}) in parquet decoder",
147
0
                                     tparquet::to_string(encoding), tparquet::to_string(type));
148
160k
    }
149
160k
    return Status::OK();
150
160k
}
151
152
} // namespace doris