Coverage Report

Created: 2026-03-12 17:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/load/delta_writer/push_handler.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 <butil/macros.h>
21
#include <gen_cpp/AgentService_types.h>
22
#include <gen_cpp/Exprs_types.h>
23
24
#include <cstdint>
25
#include <memory>
26
#include <string>
27
#include <vector>
28
29
#include "common/factory_creator.h"
30
#include "common/object_pool.h"
31
#include "common/status.h"
32
#include "core/block/block.h"
33
#include "format/generic_reader.h"
34
#include "runtime/runtime_state.h"
35
#include "storage/olap_common.h"
36
#include "storage/olap_scan_common.h"
37
#include "storage/rowset/pending_rowset_helper.h"
38
#include "storage/rowset/rowset_fwd.h"
39
#include "storage/tablet/tablet_fwd.h"
40
41
namespace doris {
42
43
class DescriptorTbl;
44
class RuntimeProfile;
45
class TBrokerScanRange;
46
class TDescriptorTable;
47
class TTabletInfo;
48
class StorageEngine;
49
50
class GenericReader;
51
class VExprContext;
52
53
class PushHandler {
54
public:
55
22
    PushHandler(StorageEngine& engine) : _engine(engine) {}
56
22
    ~PushHandler() = default;
57
58
    // Load local data file into specified tablet.
59
    Status process_streaming_ingestion(TabletSharedPtr tablet, const TPushReq& request,
60
                                       PushType push_type,
61
                                       std::vector<TTabletInfo>* tablet_info_vec);
62
63
0
    int64_t write_bytes() const { return _write_bytes; }
64
0
    int64_t write_rows() const { return _write_rows; }
65
66
private:
67
    Status _convert_v2(TabletSharedPtr cur_tablet, RowsetSharedPtr* cur_rowset,
68
                       TabletSchemaSPtr tablet_schema, PushType push_type);
69
70
    Status _do_streaming_ingestion(TabletSharedPtr tablet, const TPushReq& request,
71
                                   PushType push_type, std::vector<TTabletInfo>* tablet_info_vec);
72
73
    StorageEngine& _engine;
74
75
    // mainly tablet_id, version and delta file path
76
    TPushReq _request;
77
78
    ObjectPool _pool;
79
    DescriptorTbl* _desc_tbl = nullptr;
80
81
    int64_t _write_bytes = 0;
82
    int64_t _write_rows = 0;
83
    PendingRowsetGuard _pending_rs_guard;
84
};
85
86
class PushBrokerReader {
87
    ENABLE_FACTORY_CREATOR(PushBrokerReader);
88
89
public:
90
    PushBrokerReader(const TBrokerScanRange& t_scan_range, const TDescriptorTable& t_desc_tbl);
91
0
    ~PushBrokerReader() = default;
92
    Status init();
93
    Status next(Block* block);
94
    void print_profile();
95
96
    Status close();
97
0
    bool eof() const { return _eof; }
98
99
protected:
100
    Status _get_next_reader();
101
    Status _init_src_block();
102
    Status _cast_to_input_block();
103
    Status _convert_to_output_block(Block* block);
104
    Status _init_expr_ctxes();
105
106
private:
107
    bool _ready;
108
    bool _eof;
109
    int _next_range;
110
    Block* _src_block_ptr = nullptr;
111
    Block _src_block;
112
    const TDescriptorTable& _t_desc_tbl;
113
    std::unordered_map<std::string, DataTypePtr> _name_to_col_type;
114
    std::unordered_set<std::string> _missing_cols;
115
    std::unordered_map<std::string, uint32_t> _src_block_name_to_idx;
116
    VExprContextSPtrs _dest_expr_ctxs;
117
    VExprContextSPtr _pre_filter_ctx_ptr;
118
    std::vector<SlotDescriptor*> _src_slot_descs_order_by_dest;
119
    std::unordered_map<int, int> _dest_slot_to_src_slot_index;
120
121
    std::vector<SlotDescriptor*> _src_slot_descs;
122
    std::unique_ptr<RowDescriptor> _row_desc;
123
    const TupleDescriptor* _dest_tuple_desc = nullptr;
124
125
    std::unique_ptr<RuntimeState> _runtime_state;
126
    RuntimeProfile* _runtime_profile = nullptr;
127
    std::unique_ptr<GenericReader> _cur_reader;
128
    bool _cur_reader_eof;
129
    const TBrokerScanRangeParams& _params;
130
    const std::vector<TBrokerRangeDesc>& _ranges;
131
    TFileScanRangeParams _file_params;
132
    std::vector<TFileRangeDesc> _file_ranges;
133
134
    std::unique_ptr<io::FileCacheStatistics> _file_cache_statistics;
135
    std::unique_ptr<io::FileReaderStats> _file_reader_stats;
136
    std::unique_ptr<io::IOContext> _io_ctx;
137
138
    // col names from _slot_descs
139
    std::vector<std::string> _all_col_names;
140
    std::unordered_map<std::string, uint32_t> _col_name_to_block_idx;
141
    VExprContextSPtrs _push_down_exprs;
142
    phmap::flat_hash_map<int, std::vector<std::shared_ptr<ColumnPredicate>>> _slot_id_to_predicates;
143
    const std::unordered_map<std::string, int>* _col_name_to_slot_id;
144
    // single slot filter conjuncts
145
    std::unordered_map<int, VExprContextSPtrs> _slot_id_to_filter_conjuncts;
146
    // not single(zero or multi) slot filter conjuncts
147
    VExprContextSPtrs _not_single_slot_filter_conjuncts;
148
    // File source slot descriptors
149
    std::vector<SlotDescriptor*> _file_slot_descs;
150
    // row desc for default exprs
151
    std::unique_ptr<RowDescriptor> _default_val_row_desc;
152
    const TupleDescriptor* _real_tuple_desc = nullptr;
153
154
    // Not used, just for placeholding
155
    std::vector<TExpr> _pre_filter_texprs;
156
};
157
158
} // namespace doris