Coverage Report

Created: 2026-10-22 01:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/rowset/beta_rowset_reader.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/olap_file.pb.h>
21
#include <stdint.h>
22
23
#include <memory>
24
#include <utility>
25
#include <vector>
26
27
#include "common/status.h"
28
#include "core/block/block.h"
29
#include "storage/iterators.h"
30
#include "storage/olap_common.h"
31
#include "storage/rowset/beta_rowset.h"
32
#include "storage/rowset/rowset.h"
33
#include "storage/rowset/rowset_reader.h"
34
#include "storage/schema.h"
35
#include "storage/segment/segment_loader.h"
36
#include "util/once.h"
37
38
namespace doris {
39
class RuntimeProfile;
40
class ReadSchema;
41
struct RowsetReaderContext;
42
43
class BetaRowsetReader : public RowsetReader {
44
public:
45
    BetaRowsetReader(BetaRowsetSharedPtr rowset);
46
47
1.25k
    ~BetaRowsetReader() override { _rowset->release(); }
48
49
    Status init(RowsetReaderContext* read_context, const RowSetSplits& rs_splits) override;
50
51
    Status get_segment_iterators(RowsetReaderContext* read_context,
52
                                 std::vector<RowwiseIteratorUPtr>* out_iters,
53
                                 bool use_cache = false) override;
54
    void reset_read_options() override;
55
6.84k
    Status next_batch(Block* block) override { return _next_batch(block); }
56
0
    Status next_batch(BlockView* block_view) override { return _next_batch(block_view); }
57
209
    Status next_batch(BlockWithSameBit* block_with_same_bit) override {
58
209
        return _next_batch(block_with_same_bit);
59
209
    }
60
61
559
    bool is_merge_iterator() const override {
62
559
        return _read_context->need_ordered_result && _get_segment_num() > 1 &&
63
559
               _rowset->rowset_meta()->is_segments_overlapping();
64
559
    }
65
66
0
    bool delete_flag() override { return _rowset->delete_flag(); }
67
68
1.03M
    Version version() override { return _rowset->version(); }
69
70
41
    int64_t newest_write_timestamp() override { return _rowset->newest_write_timestamp(); }
71
72
5.28k
    RowsetSharedPtr rowset() override { return std::dynamic_pointer_cast<Rowset>(_rowset); }
73
74
0
    const ReadSchema& read_schema() const override { return *_read_context->read_schema; }
75
76
    // Return the total number of filtered rows, will be used for validation of schema change
77
0
    int64_t filtered_rows() override {
78
0
        return _stats->rows_del_filtered + _stats->rows_del_by_bitmap +
79
0
               _stats->rows_conditions_filtered + _stats->rows_vec_del_cond_filtered +
80
0
               _stats->rows_vec_cond_filtered + _stats->rows_short_circuit_cond_filtered;
81
0
    }
82
83
0
    uint64_t merged_rows() override { return *(_read_context->merged_rows); }
84
85
154
    RowsetTypePB type() const override { return RowsetTypePB::BETA_ROWSET; }
86
87
    void update_profile(RuntimeProfile* profile) override;
88
89
    RowsetReaderSharedPtr clone() override;
90
91
0
    void set_topn_limit(size_t topn_limit) override { _topn_limit = topn_limit; }
92
93
0
    OlapReaderStatistics* get_stats() { return _stats; }
94
95
private:
96
    template <typename T>
97
7.05k
    Status _next_batch(T* block) {
98
7.05k
        RETURN_IF_ERROR(_init_iterator_once());
99
7.05k
        SCOPED_RAW_TIMER(&_stats->block_fetch_ns);
100
7.05k
        if (_empty) {
101
0
            return Status::Error<ErrorCode::END_OF_FILE>("BetaRowsetReader is empty");
102
0
        }
103
104
7.05k
        RuntimeState* runtime_state = nullptr;
105
7.05k
        if (_read_context != nullptr) {
106
7.05k
            runtime_state = _read_context->runtime_state;
107
7.05k
        }
108
109
7.07k
        do {
110
7.07k
            Status s = _iterator->next_batch(block);
111
7.07k
            if (!s.ok()) {
112
405
                if (!s.is<ErrorCode::END_OF_FILE>()) {
113
0
                    LOG(WARNING) << "failed to read next block: " << s.to_string();
114
0
                }
115
405
                return s;
116
405
            }
117
118
6.67k
            if (runtime_state != nullptr && runtime_state->is_cancelled()) [[unlikely]] {
119
0
                return runtime_state->cancel_reason();
120
0
            }
121
6.67k
        } while (block->empty());
122
123
6.65k
        return Status::OK();
124
7.05k
    }
_ZN5doris16BetaRowsetReader11_next_batchINS_5BlockEEENS_6StatusEPT_
Line
Count
Source
97
6.84k
    Status _next_batch(T* block) {
98
6.84k
        RETURN_IF_ERROR(_init_iterator_once());
99
6.84k
        SCOPED_RAW_TIMER(&_stats->block_fetch_ns);
100
6.84k
        if (_empty) {
101
0
            return Status::Error<ErrorCode::END_OF_FILE>("BetaRowsetReader is empty");
102
0
        }
103
104
6.84k
        RuntimeState* runtime_state = nullptr;
105
6.84k
        if (_read_context != nullptr) {
106
6.84k
            runtime_state = _read_context->runtime_state;
107
6.84k
        }
108
109
6.86k
        do {
110
6.86k
            Status s = _iterator->next_batch(block);
111
6.86k
            if (!s.ok()) {
112
397
                if (!s.is<ErrorCode::END_OF_FILE>()) {
113
0
                    LOG(WARNING) << "failed to read next block: " << s.to_string();
114
0
                }
115
397
                return s;
116
397
            }
117
118
6.47k
            if (runtime_state != nullptr && runtime_state->is_cancelled()) [[unlikely]] {
119
0
                return runtime_state->cancel_reason();
120
0
            }
121
6.47k
        } while (block->empty());
122
123
6.45k
        return Status::OK();
124
6.84k
    }
Unexecuted instantiation: _ZN5doris16BetaRowsetReader11_next_batchISt6vectorINS_14IteratorRowRefESaIS3_EEEENS_6StatusEPT_
_ZN5doris16BetaRowsetReader11_next_batchINS_16BlockWithSameBitEEENS_6StatusEPT_
Line
Count
Source
97
209
    Status _next_batch(T* block) {
98
209
        RETURN_IF_ERROR(_init_iterator_once());
99
209
        SCOPED_RAW_TIMER(&_stats->block_fetch_ns);
100
209
        if (_empty) {
101
0
            return Status::Error<ErrorCode::END_OF_FILE>("BetaRowsetReader is empty");
102
0
        }
103
104
209
        RuntimeState* runtime_state = nullptr;
105
209
        if (_read_context != nullptr) {
106
209
            runtime_state = _read_context->runtime_state;
107
209
        }
108
109
209
        do {
110
209
            Status s = _iterator->next_batch(block);
111
209
            if (!s.ok()) {
112
8
                if (!s.is<ErrorCode::END_OF_FILE>()) {
113
0
                    LOG(WARNING) << "failed to read next block: " << s.to_string();
114
0
                }
115
8
                return s;
116
8
            }
117
118
201
            if (runtime_state != nullptr && runtime_state->is_cancelled()) [[unlikely]] {
119
0
                return runtime_state->cancel_reason();
120
0
            }
121
201
        } while (block->empty());
122
123
201
        return Status::OK();
124
209
    }
125
126
    [[nodiscard]] Status _init_iterator_once();
127
    [[nodiscard]] Status _init_iterator();
128
    bool _should_push_down_value_predicates() const;
129
130
350
    int64_t _get_segment_num() const {
131
350
        auto [seg_start, seg_end] = _segment_offsets;
132
350
        if (seg_start == seg_end) {
133
344
            seg_start = 0;
134
344
            seg_end = _rowset->num_segments();
135
344
        }
136
350
        return seg_end - seg_start;
137
350
    }
138
139
    DorisCallOnce<Status> _init_iter_once;
140
141
    std::pair<int64_t, int64_t> _segment_offsets;
142
    std::vector<RowRanges> _segment_row_ranges;
143
144
    RowsetReaderContext* _read_context = nullptr;
145
    BetaRowsetSharedPtr _rowset;
146
147
    OlapReaderStatistics _owned_stats;
148
    OlapReaderStatistics* _stats = nullptr;
149
150
    std::unique_ptr<RowwiseIterator> _iterator;
151
152
    StorageReadOptions _read_options;
153
154
    bool _empty = false;
155
    size_t _topn_limit = 0;
156
    uint64_t _merged_rows = 0;
157
};
158
159
} // namespace doris