Coverage Report

Created: 2026-06-04 07:44

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
80.9k
                            std::unique_ptr<Decoder>& decoder) {
35
80.9k
    switch (encoding) {
36
35.2k
    case tparquet::Encoding::PLAIN:
37
35.2k
        switch (type) {
38
2.58k
        case tparquet::Type::BOOLEAN:
39
2.58k
            decoder.reset(new BoolPlainDecoder());
40
2.58k
            break;
41
11.2k
        case tparquet::Type::BYTE_ARRAY:
42
11.2k
            decoder.reset(new ByteArrayPlainDecoder());
43
11.2k
            break;
44
10.5k
        case tparquet::Type::INT32:
45
15.6k
        case tparquet::Type::INT64:
46
15.6k
        case tparquet::Type::INT96:
47
16.7k
        case tparquet::Type::FLOAT:
48
18.8k
        case tparquet::Type::DOUBLE:
49
21.3k
        case tparquet::Type::FIXED_LEN_BYTE_ARRAY:
50
21.3k
            decoder.reset(new FixLengthPlainDecoder());
51
21.3k
            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
35.2k
        }
56
35.2k
        break;
57
44.8k
    case tparquet::Encoding::RLE_DICTIONARY:
58
44.8k
        switch (type) {
59
0
        case tparquet::Type::BOOLEAN:
60
0
            return Status::InternalError("Bool type can't has dictionary page");
61
13.8k
        case tparquet::Type::BYTE_ARRAY:
62
13.8k
            decoder.reset(new ByteArrayDictDecoder());
63
13.8k
            break;
64
13.4k
        case tparquet::Type::INT32:
65
13.4k
            decoder.reset(new FixLengthDictDecoder<tparquet::Type::INT32>());
66
13.4k
            break;
67
6.22k
        case tparquet::Type::INT64:
68
6.22k
            decoder.reset(new FixLengthDictDecoder<tparquet::Type::INT64>());
69
6.22k
            break;
70
893
        case tparquet::Type::INT96:
71
893
            decoder.reset(new FixLengthDictDecoder<tparquet::Type::INT96>());
72
893
            break;
73
1.64k
        case tparquet::Type::FLOAT:
74
1.64k
            decoder.reset(new FixLengthDictDecoder<tparquet::Type::FLOAT>());
75
1.64k
            break;
76
3.95k
        case tparquet::Type::DOUBLE:
77
3.95k
            decoder.reset(new FixLengthDictDecoder<tparquet::Type::DOUBLE>());
78
3.95k
            break;
79
4.88k
        case tparquet::Type::FIXED_LEN_BYTE_ARRAY:
80
4.88k
            decoder.reset(new FixLengthDictDecoder<tparquet::Type::FIXED_LEN_BYTE_ARRAY>());
81
4.88k
            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
44.8k
        }
86
44.8k
        break;
87
44.8k
    case tparquet::Encoding::RLE:
88
179
        switch (type) {
89
179
        case tparquet::Type::BOOLEAN:
90
179
            decoder.reset(new BoolRLEDecoder());
91
179
            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
179
        }
96
179
        break;
97
525
    case tparquet::Encoding::DELTA_BINARY_PACKED:
98
        // Supports only INT32 and INT64.
99
525
        switch (type) {
100
36
        case tparquet::Type::INT32:
101
36
            decoder.reset(new DeltaBitPackDecoder<int32_t>());
102
36
            break;
103
489
        case tparquet::Type::INT64:
104
489
            decoder.reset(new DeltaBitPackDecoder<int64_t>());
105
489
            break;
106
0
        default:
107
0
            return Status::InternalError("DELTA_BINARY_PACKED only supports INT32 and INT64");
108
525
        }
109
525
        break;
110
525
    case tparquet::Encoding::DELTA_BYTE_ARRAY:
111
90
        switch (type) {
112
90
        case tparquet::Type::BYTE_ARRAY:
113
90
        case tparquet::Type::FIXED_LEN_BYTE_ARRAY:
114
90
            decoder.reset(new DeltaByteArrayDecoder());
115
90
            break;
116
0
        default:
117
0
            return Status::InternalError(
118
0
                    "DELTA_BYTE_ARRAY only supports BYTE_ARRAY, FIXED_LEN_BYTE_ARRAY.");
119
90
        }
120
90
        break;
121
90
    case tparquet::Encoding::DELTA_LENGTH_BYTE_ARRAY:
122
14
        switch (type) {
123
14
        case tparquet::Type::BYTE_ARRAY:
124
14
            decoder.reset(new DeltaLengthByteArrayDecoder());
125
14
            break;
126
0
        default:
127
0
            return Status::InternalError("DELTA_LENGTH_BYTE_ARRAY only supports BYTE_ARRAY.");
128
14
        }
129
14
        break;
130
14
    case tparquet::Encoding::BYTE_STREAM_SPLIT:
131
11
        switch (type) {
132
1
        case tparquet::Type::INT32:
133
2
        case tparquet::Type::INT64:
134
2
        case tparquet::Type::INT96:
135
5
        case tparquet::Type::FLOAT:
136
8
        case tparquet::Type::DOUBLE:
137
11
        case tparquet::Type::FIXED_LEN_BYTE_ARRAY:
138
11
            decoder.reset(new ByteStreamSplitDecoder());
139
11
            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
11
        }
144
11
        break;
145
11
    default:
146
0
        return Status::InternalError("Unsupported encoding {}(type={}) in parquet decoder",
147
0
                                     tparquet::to_string(encoding), tparquet::to_string(type));
148
80.9k
    }
149
80.9k
    return Status::OK();
150
80.9k
}
151
152
} // namespace doris