Coverage Report

Created: 2026-03-24 20:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format/parquet/bool_rle_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/bool_rle_decoder.h"
19
20
#include <glog/logging.h>
21
22
#include <algorithm>
23
#include <ostream>
24
#include <string>
25
26
#include "core/column/column_vector.h"
27
#include "core/types.h"
28
#include "format/parquet/parquet_common.h"
29
#include "util/coding.h"
30
#include "util/slice.h"
31
32
namespace doris {
33
#include "common/compile_check_begin.h"
34
12
Status BoolRLEDecoder::set_data(Slice* slice) {
35
12
    _data = slice;
36
12
    _num_bytes = slice->size;
37
12
    _offset = 0;
38
12
    if (_num_bytes < 4) {
39
2
        return Status::IOError("Received invalid length : " + std::to_string(_num_bytes) +
40
2
                               " (corrupt data page?)");
41
2
    }
42
    // Load the first 4 bytes in little-endian, which indicates the length
43
10
    const auto* data = reinterpret_cast<const uint8_t*>(_data->data);
44
10
    uint32_t num_bytes = decode_fixed32_le(data);
45
10
    if (num_bytes > static_cast<uint32_t>(_num_bytes - 4)) {
46
0
        return Status::IOError("Received invalid number of bytes : " + std::to_string(num_bytes) +
47
0
                               " (corrupt data page?)");
48
0
    }
49
10
    _num_bytes = num_bytes;
50
10
    auto decoder_data = data + 4;
51
10
    _decoder = RleDecoder<uint8_t>(decoder_data, num_bytes, 1);
52
10
    return Status::OK();
53
10
}
54
55
2
Status BoolRLEDecoder::skip_values(size_t num_values) {
56
2
    _decoder.Skip(num_values);
57
2
    return Status::OK();
58
2
}
59
60
Status BoolRLEDecoder::decode_values(MutableColumnPtr& doris_column, DataTypePtr& data_type,
61
10
                                     ColumnSelectVector& select_vector, bool is_dict_filter) {
62
10
    if (select_vector.has_filter()) {
63
4
        return _decode_values<true>(doris_column, data_type, select_vector, is_dict_filter);
64
6
    } else {
65
6
        return _decode_values<false>(doris_column, data_type, select_vector, is_dict_filter);
66
6
    }
67
10
}
68
69
template <bool has_filter>
70
Status BoolRLEDecoder::_decode_values(MutableColumnPtr& doris_column, DataTypePtr& data_type,
71
10
                                      ColumnSelectVector& select_vector, bool is_dict_filter) {
72
10
    auto& column_data = assert_cast<ColumnUInt8*>(doris_column.get())->get_data();
73
10
    size_t data_index = column_data.size();
74
10
    column_data.resize(data_index + select_vector.num_values() - select_vector.num_filtered());
75
10
    size_t max_values = select_vector.num_values() - select_vector.num_nulls();
76
10
    _values.resize(max_values);
77
10
    if (!_decoder.get_values(_values.data(), max_values)) {
78
0
        return Status::IOError("Can't read enough booleans in rle decoder");
79
0
    }
80
10
    size_t current_value_idx = 0;
81
10
    ColumnSelectVector::DataReadType read_type;
82
48
    while (size_t run_length = select_vector.get_next_run<has_filter>(&read_type)) {
83
38
        switch (read_type) {
84
18
        case ColumnSelectVector::CONTENT: {
85
18
            bool value; // Can't use uint8_t directly, we should correct it.
86
72
            for (size_t i = 0; i < run_length; ++i) {
87
54
                DCHECK(current_value_idx < max_values)
88
0
                        << current_value_idx << " vs. " << max_values;
89
54
                value = _values[current_value_idx++];
90
54
                column_data[data_index++] = (UInt8)value;
91
54
            }
92
18
            break;
93
0
        }
94
4
        case ColumnSelectVector::NULL_DATA: {
95
4
            data_index += run_length;
96
4
            break;
97
0
        }
98
16
        case ColumnSelectVector::FILTERED_CONTENT: {
99
16
            current_value_idx += run_length;
100
16
            break;
101
0
        }
102
0
        case ColumnSelectVector::FILTERED_NULL: {
103
0
            break;
104
0
        }
105
38
        }
106
38
    }
107
10
    return Status::OK();
108
10
}
_ZN5doris14BoolRLEDecoder14_decode_valuesILb1EEENS_6StatusERNS_3COWINS_7IColumnEE11mutable_ptrIS4_EERSt10shared_ptrIKNS_9IDataTypeEERNS_18ColumnSelectVectorEb
Line
Count
Source
71
4
                                      ColumnSelectVector& select_vector, bool is_dict_filter) {
72
4
    auto& column_data = assert_cast<ColumnUInt8*>(doris_column.get())->get_data();
73
4
    size_t data_index = column_data.size();
74
4
    column_data.resize(data_index + select_vector.num_values() - select_vector.num_filtered());
75
4
    size_t max_values = select_vector.num_values() - select_vector.num_nulls();
76
4
    _values.resize(max_values);
77
4
    if (!_decoder.get_values(_values.data(), max_values)) {
78
0
        return Status::IOError("Can't read enough booleans in rle decoder");
79
0
    }
80
4
    size_t current_value_idx = 0;
81
4
    ColumnSelectVector::DataReadType read_type;
82
36
    while (size_t run_length = select_vector.get_next_run<has_filter>(&read_type)) {
83
32
        switch (read_type) {
84
12
        case ColumnSelectVector::CONTENT: {
85
12
            bool value; // Can't use uint8_t directly, we should correct it.
86
24
            for (size_t i = 0; i < run_length; ++i) {
87
12
                DCHECK(current_value_idx < max_values)
88
0
                        << current_value_idx << " vs. " << max_values;
89
12
                value = _values[current_value_idx++];
90
12
                column_data[data_index++] = (UInt8)value;
91
12
            }
92
12
            break;
93
0
        }
94
4
        case ColumnSelectVector::NULL_DATA: {
95
4
            data_index += run_length;
96
4
            break;
97
0
        }
98
16
        case ColumnSelectVector::FILTERED_CONTENT: {
99
16
            current_value_idx += run_length;
100
16
            break;
101
0
        }
102
0
        case ColumnSelectVector::FILTERED_NULL: {
103
0
            break;
104
0
        }
105
32
        }
106
32
    }
107
4
    return Status::OK();
108
4
}
_ZN5doris14BoolRLEDecoder14_decode_valuesILb0EEENS_6StatusERNS_3COWINS_7IColumnEE11mutable_ptrIS4_EERSt10shared_ptrIKNS_9IDataTypeEERNS_18ColumnSelectVectorEb
Line
Count
Source
71
6
                                      ColumnSelectVector& select_vector, bool is_dict_filter) {
72
6
    auto& column_data = assert_cast<ColumnUInt8*>(doris_column.get())->get_data();
73
6
    size_t data_index = column_data.size();
74
6
    column_data.resize(data_index + select_vector.num_values() - select_vector.num_filtered());
75
6
    size_t max_values = select_vector.num_values() - select_vector.num_nulls();
76
6
    _values.resize(max_values);
77
6
    if (!_decoder.get_values(_values.data(), max_values)) {
78
0
        return Status::IOError("Can't read enough booleans in rle decoder");
79
0
    }
80
6
    size_t current_value_idx = 0;
81
6
    ColumnSelectVector::DataReadType read_type;
82
12
    while (size_t run_length = select_vector.get_next_run<has_filter>(&read_type)) {
83
6
        switch (read_type) {
84
6
        case ColumnSelectVector::CONTENT: {
85
6
            bool value; // Can't use uint8_t directly, we should correct it.
86
48
            for (size_t i = 0; i < run_length; ++i) {
87
42
                DCHECK(current_value_idx < max_values)
88
0
                        << current_value_idx << " vs. " << max_values;
89
42
                value = _values[current_value_idx++];
90
42
                column_data[data_index++] = (UInt8)value;
91
42
            }
92
6
            break;
93
0
        }
94
0
        case ColumnSelectVector::NULL_DATA: {
95
0
            data_index += run_length;
96
0
            break;
97
0
        }
98
0
        case ColumnSelectVector::FILTERED_CONTENT: {
99
0
            current_value_idx += run_length;
100
0
            break;
101
0
        }
102
0
        case ColumnSelectVector::FILTERED_NULL: {
103
0
            break;
104
0
        }
105
6
        }
106
6
    }
107
6
    return Status::OK();
108
6
}
109
#include "common/compile_check_end.h"
110
111
} // namespace doris