Coverage Report

Created: 2026-04-16 16:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format/parquet/bool_plain_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_plain_decoder.h"
19
20
#include <glog/logging.h>
21
22
#include <algorithm>
23
24
#include "core/column/column_vector.h"
25
#include "core/types.h"
26
#include "format/parquet/parquet_common.h"
27
#include "util/bit_util.h"
28
29
namespace doris {
30
11
Status BoolPlainDecoder::skip_values(size_t num_values) {
31
11
    int skip_cached =
32
11
            std::min(num_unpacked_values_ - unpacked_value_idx_, cast_set<int>(num_values));
33
11
    unpacked_value_idx_ += skip_cached;
34
11
    if (skip_cached == num_values) {
35
3
        return Status::OK();
36
3
    }
37
8
    int num_remaining = cast_set<int>(num_values - skip_cached);
38
8
    int num_to_skip = BitUtil::RoundDownToPowerOf2(num_remaining, 32);
39
8
    if (num_to_skip > 0) {
40
0
        bool_values_.SkipBatch(1, num_to_skip);
41
0
    }
42
8
    num_remaining -= num_to_skip;
43
8
    if (num_remaining > 0) {
44
8
        DCHECK_LE(num_remaining, UNPACKED_BUFFER_LEN);
45
8
        num_unpacked_values_ =
46
8
                bool_values_.UnpackBatch(1, UNPACKED_BUFFER_LEN, &unpacked_values_[0]);
47
8
        if (UNLIKELY(num_unpacked_values_ < num_remaining)) {
48
0
            return Status::IOError("Can't skip enough booleans in plain decoder");
49
0
        }
50
8
        unpacked_value_idx_ = num_remaining;
51
8
    }
52
8
    return Status::OK();
53
8
}
54
55
Status BoolPlainDecoder::decode_values(MutableColumnPtr& doris_column, DataTypePtr& data_type,
56
18
                                       ColumnSelectVector& select_vector, bool is_dict_filter) {
57
18
    if (select_vector.has_filter()) {
58
2
        return _decode_values<true>(doris_column, data_type, select_vector, is_dict_filter);
59
16
    } else {
60
16
        return _decode_values<false>(doris_column, data_type, select_vector, is_dict_filter);
61
16
    }
62
18
}
63
64
template <bool has_filter>
65
Status BoolPlainDecoder::_decode_values(MutableColumnPtr& doris_column, DataTypePtr& data_type,
66
18
                                        ColumnSelectVector& select_vector, bool is_dict_filter) {
67
18
    auto& column_data = assert_cast<ColumnUInt8*>(doris_column.get())->get_data();
68
18
    size_t data_index = column_data.size();
69
18
    column_data.resize(data_index + select_vector.num_values() - select_vector.num_filtered());
70
71
18
    ColumnSelectVector::DataReadType read_type;
72
49
    while (size_t run_length = select_vector.get_next_run<has_filter>(&read_type)) {
73
31
        switch (read_type) {
74
23
        case ColumnSelectVector::CONTENT: {
75
23
            bool value;
76
93
            for (size_t i = 0; i < run_length; ++i) {
77
70
                if (UNLIKELY(!_decode_value(&value))) {
78
0
                    return Status::IOError("Can't read enough booleans in plain decoder");
79
0
                }
80
70
                column_data[data_index++] = (UInt8)value;
81
70
            }
82
23
            break;
83
23
        }
84
23
        case ColumnSelectVector::NULL_DATA: {
85
2
            data_index += run_length;
86
2
            break;
87
23
        }
88
6
        case ColumnSelectVector::FILTERED_CONTENT: {
89
6
            bool value;
90
12
            for (int i = 0; i < run_length; ++i) {
91
6
                if (UNLIKELY(!_decode_value(&value))) {
92
0
                    return Status::IOError("Can't read enough booleans in plain decoder");
93
0
                }
94
6
            }
95
6
            break;
96
6
        }
97
6
        case ColumnSelectVector::FILTERED_NULL: {
98
            // do nothing
99
0
            break;
100
6
        }
101
31
        }
102
31
    }
103
18
    return Status::OK();
104
18
}
_ZN5doris16BoolPlainDecoder14_decode_valuesILb1EEENS_6StatusERNS_3COWINS_7IColumnEE11mutable_ptrIS4_EERSt10shared_ptrIKNS_9IDataTypeEERNS_18ColumnSelectVectorEb
Line
Count
Source
66
2
                                        ColumnSelectVector& select_vector, bool is_dict_filter) {
67
2
    auto& column_data = assert_cast<ColumnUInt8*>(doris_column.get())->get_data();
68
2
    size_t data_index = column_data.size();
69
2
    column_data.resize(data_index + select_vector.num_values() - select_vector.num_filtered());
70
71
2
    ColumnSelectVector::DataReadType read_type;
72
17
    while (size_t run_length = select_vector.get_next_run<has_filter>(&read_type)) {
73
15
        switch (read_type) {
74
7
        case ColumnSelectVector::CONTENT: {
75
7
            bool value;
76
14
            for (size_t i = 0; i < run_length; ++i) {
77
7
                if (UNLIKELY(!_decode_value(&value))) {
78
0
                    return Status::IOError("Can't read enough booleans in plain decoder");
79
0
                }
80
7
                column_data[data_index++] = (UInt8)value;
81
7
            }
82
7
            break;
83
7
        }
84
7
        case ColumnSelectVector::NULL_DATA: {
85
2
            data_index += run_length;
86
2
            break;
87
7
        }
88
6
        case ColumnSelectVector::FILTERED_CONTENT: {
89
6
            bool value;
90
12
            for (int i = 0; i < run_length; ++i) {
91
6
                if (UNLIKELY(!_decode_value(&value))) {
92
0
                    return Status::IOError("Can't read enough booleans in plain decoder");
93
0
                }
94
6
            }
95
6
            break;
96
6
        }
97
6
        case ColumnSelectVector::FILTERED_NULL: {
98
            // do nothing
99
0
            break;
100
6
        }
101
15
        }
102
15
    }
103
2
    return Status::OK();
104
2
}
_ZN5doris16BoolPlainDecoder14_decode_valuesILb0EEENS_6StatusERNS_3COWINS_7IColumnEE11mutable_ptrIS4_EERSt10shared_ptrIKNS_9IDataTypeEERNS_18ColumnSelectVectorEb
Line
Count
Source
66
16
                                        ColumnSelectVector& select_vector, bool is_dict_filter) {
67
16
    auto& column_data = assert_cast<ColumnUInt8*>(doris_column.get())->get_data();
68
16
    size_t data_index = column_data.size();
69
16
    column_data.resize(data_index + select_vector.num_values() - select_vector.num_filtered());
70
71
16
    ColumnSelectVector::DataReadType read_type;
72
32
    while (size_t run_length = select_vector.get_next_run<has_filter>(&read_type)) {
73
16
        switch (read_type) {
74
16
        case ColumnSelectVector::CONTENT: {
75
16
            bool value;
76
79
            for (size_t i = 0; i < run_length; ++i) {
77
63
                if (UNLIKELY(!_decode_value(&value))) {
78
0
                    return Status::IOError("Can't read enough booleans in plain decoder");
79
0
                }
80
63
                column_data[data_index++] = (UInt8)value;
81
63
            }
82
16
            break;
83
16
        }
84
16
        case ColumnSelectVector::NULL_DATA: {
85
0
            data_index += run_length;
86
0
            break;
87
16
        }
88
0
        case ColumnSelectVector::FILTERED_CONTENT: {
89
0
            bool value;
90
0
            for (int i = 0; i < run_length; ++i) {
91
0
                if (UNLIKELY(!_decode_value(&value))) {
92
0
                    return Status::IOError("Can't read enough booleans in plain decoder");
93
0
                }
94
0
            }
95
0
            break;
96
0
        }
97
0
        case ColumnSelectVector::FILTERED_NULL: {
98
            // do nothing
99
0
            break;
100
0
        }
101
16
        }
102
16
    }
103
16
    return Status::OK();
104
16
}
105
106
} // namespace doris