Coverage Report

Created: 2026-04-10 12:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exec/sink/vtablet_finder.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 <cstdint>
21
#include <map>
22
23
#include "common/status.h"
24
#include "core/block/block.h"
25
#include "exec/common/hash_table/phmap_fwd_decl.h"
26
#include "storage/tablet_info.h"
27
#include "util/bitmap.h"
28
29
namespace doris {
30
31
class OlapTabletFinder {
32
public:
33
    // FIND_TABLET_EVERY_ROW is used for hash distribution info, which indicates that we
34
    // should compute tablet index for every row
35
    // FIND_TABLET_EVERY_BATCH is used for random distribution info, which indicates that we should
36
    // compute tablet index for every row batch
37
    // FIND_TABLET_EVERY_SINK is used for random distribution info when load_to_single_tablet set to true,
38
    // which indicates that we should only compute tablet index in the corresponding partition once for the
39
    // whole time in olap table sink
40
    enum FindTabletMode { FIND_TABLET_EVERY_ROW, FIND_TABLET_EVERY_BATCH, FIND_TABLET_EVERY_SINK };
41
42
    OlapTabletFinder(VOlapTablePartitionParam* vpartition, FindTabletMode mode)
43
59.8k
            : _vpartition(vpartition), _find_tablet_mode(mode), _filter_bitmap(1024) {};
44
45
    Status find_tablets(RuntimeState* state, Block* block, int rows,
46
                        std::vector<VOlapTablePartition*>& partitions,
47
                        std::vector<uint32_t>& tablet_index, std::vector<bool>& skip,
48
                        std::vector<uint32_t>* miss_rows = nullptr);
49
50
0
    bool is_find_tablet_every_sink() {
51
0
        return _find_tablet_mode == FindTabletMode::FIND_TABLET_EVERY_SINK;
52
0
    }
53
54
0
    bool is_single_tablet() { return _partition_to_tablet_map.size() == 1; }
55
56
    // all partitions for multi find-processes of its relative writer.
57
156k
    const flat_hash_set<int64_t>& partition_ids() { return _partition_ids; }
58
59
121k
    int64_t num_filtered_rows() const { return _num_filtered_rows; }
60
61
59.9k
    int64_t num_immutable_partition_filtered_rows() const {
62
59.9k
        return _num_immutable_partition_filtered_rows;
63
59.9k
    }
64
65
38.4k
    Bitmap& filter_bitmap() { return _filter_bitmap; }
66
67
private:
68
    VOlapTablePartitionParam* _vpartition = nullptr;
69
    FindTabletMode _find_tablet_mode;
70
    std::map<VOlapTablePartition*, int64_t> _partition_to_tablet_map;
71
    flat_hash_set<int64_t> _partition_ids;
72
73
    int64_t _num_filtered_rows = 0;
74
    int64_t _num_immutable_partition_filtered_rows = 0;
75
    Bitmap _filter_bitmap;
76
};
77
78
} // namespace doris