be/src/format/parquet/level_decoder.h
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 | | #pragma once |
19 | | |
20 | | #include <gen_cpp/parquet_types.h> |
21 | | #include <stddef.h> |
22 | | |
23 | | #include <cstdint> |
24 | | |
25 | | #include "common/status.h" |
26 | | #include "format/parquet/parquet_common.h" |
27 | | #include "util/bit_stream_utils.h" |
28 | | #include "util/rle_encoding.h" |
29 | | #include "util/slice.h" |
30 | | |
31 | | namespace doris { |
32 | | class LevelDecoder { |
33 | | public: |
34 | 346k | LevelDecoder() = default; |
35 | | ~LevelDecoder() = default; |
36 | | |
37 | | Status init(Slice* slice, tparquet::Encoding::type encoding, level_t max_level, |
38 | | uint32_t num_levels); |
39 | | |
40 | | Status init_v2(const Slice& levels, level_t max_level, uint32_t num_levels); |
41 | | |
42 | | inline bool has_levels() const { return _num_levels > 0; } |
43 | | |
44 | | size_t get_levels(level_t* levels, size_t n); |
45 | | |
46 | 1.85M | inline size_t get_next_run(level_t* val, size_t max_run) { |
47 | 1.85M | return _rle_decoder.GetNextRun(val, max_run); |
48 | 1.85M | } |
49 | | |
50 | 118M | inline level_t get_next() { |
51 | 118M | level_t next = -1; |
52 | 118M | _rle_decoder.Get(&next); |
53 | 118M | return next; |
54 | 118M | } |
55 | | |
56 | 32.8k | inline void rewind_one() { _rle_decoder.RewindOne(); } |
57 | | |
58 | 1 | const RleDecoder<level_t>& rle_decoder() const { return _rle_decoder; } |
59 | | |
60 | | private: |
61 | | tparquet::Encoding::type _encoding; |
62 | | level_t _bit_width = 0; |
63 | | level_t _max_level = 0; |
64 | | uint32_t _num_levels = 0; |
65 | | RleDecoder<level_t> _rle_decoder; |
66 | | BitReader _bit_packed_decoder; |
67 | | }; |
68 | | |
69 | | } // namespace doris |