Coverage Report

Created: 2025-11-25 22:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/olap/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 "exec/olap_common.h"
33
#include "olap/olap_common.h"
34
#include "olap/rowset/pending_rowset_helper.h"
35
#include "olap/rowset/rowset_fwd.h"
36
#include "olap/tablet_fwd.h"
37
#include "runtime/runtime_state.h"
38
#include "vec/core/block.h"
39
#include "vec/exec/format/generic_reader.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
namespace vectorized {
51
class GenericReader;
52
class VExprContext;
53
} // namespace vectorized
54
55
class PushHandler {
56
public:
57
0
    PushHandler(StorageEngine& engine) : _engine(engine) {}
58
0
    ~PushHandler() = default;
59
60
    // Load local data file into specified tablet.
61
    Status process_streaming_ingestion(TabletSharedPtr tablet, const TPushReq& request,
62
                                       PushType push_type,
63
                                       std::vector<TTabletInfo>* tablet_info_vec);
64
65
0
    int64_t write_bytes() const { return _write_bytes; }
66
0
    int64_t write_rows() const { return _write_rows; }
67
68
private:
69
    Status _convert_v2(TabletSharedPtr cur_tablet, RowsetSharedPtr* cur_rowset,
70
                       TabletSchemaSPtr tablet_schema, PushType push_type);
71
72
    Status _do_streaming_ingestion(TabletSharedPtr tablet, const TPushReq& request,
73
                                   PushType push_type, std::vector<TTabletInfo>* tablet_info_vec);
74
75
    StorageEngine& _engine;
76
77
    // mainly tablet_id, version and delta file path
78
    TPushReq _request;
79
80
    ObjectPool _pool;
81
    DescriptorTbl* _desc_tbl = nullptr;
82
83
    int64_t _write_bytes = 0;
84
    int64_t _write_rows = 0;
85
    PendingRowsetGuard _pending_rs_guard;
86
};
87
88
class PushBrokerReader {
89
    ENABLE_FACTORY_CREATOR(PushBrokerReader);
90
91
public:
92
    PushBrokerReader(const TBrokerScanRange& t_scan_range, const TDescriptorTable& t_desc_tbl);
93
0
    ~PushBrokerReader() = default;
94
    Status init();
95
    Status next(vectorized::Block* block);
96
    void print_profile();
97
98
    Status close();
99
0
    bool eof() const { return _eof; }
100
101
protected:
102
    Status _get_next_reader();
103
    Status _init_src_block();
104
    Status _cast_to_input_block();
105
    Status _convert_to_output_block(vectorized::Block* block);
106
    Status _init_expr_ctxes();
107
108
private:
109
    bool _ready;
110
    bool _eof;
111
    int _next_range;
112
    vectorized::Block* _src_block_ptr = nullptr;
113
    vectorized::Block _src_block;
114
    const TDescriptorTable& _t_desc_tbl;
115
    std::unordered_map<std::string, vectorized::DataTypePtr> _name_to_col_type;
116
    std::unordered_set<std::string> _missing_cols;
117
    std::unordered_map<std::string, uint32_t> _src_block_name_to_idx;
118
    vectorized::VExprContextSPtrs _dest_expr_ctxs;
119
    vectorized::VExprContextSPtr _pre_filter_ctx_ptr;
120
    std::vector<SlotDescriptor*> _src_slot_descs_order_by_dest;
121
    std::unordered_map<int, int> _dest_slot_to_src_slot_index;
122
123
    std::vector<SlotDescriptor*> _src_slot_descs;
124
    std::unique_ptr<RowDescriptor> _row_desc;
125
    const TupleDescriptor* _dest_tuple_desc = nullptr;
126
127
    std::unique_ptr<RuntimeState> _runtime_state;
128
    RuntimeProfile* _runtime_profile = nullptr;
129
    std::unique_ptr<vectorized::GenericReader> _cur_reader;
130
    bool _cur_reader_eof;
131
    const TBrokerScanRangeParams& _params;
132
    const std::vector<TBrokerRangeDesc>& _ranges;
133
    TFileScanRangeParams _file_params;
134
    std::vector<TFileRangeDesc> _file_ranges;
135
136
    std::unique_ptr<io::FileCacheStatistics> _file_cache_statistics;
137
    std::unique_ptr<io::FileReaderStats> _file_reader_stats;
138
    std::unique_ptr<io::IOContext> _io_ctx;
139
140
    // col names from _slot_descs
141
    std::vector<std::string> _all_col_names;
142
    vectorized::VExprContextSPtrs _push_down_exprs;
143
    const std::unordered_map<std::string, int>* _col_name_to_slot_id;
144
    // single slot filter conjuncts
145
    std::unordered_map<int, vectorized::VExprContextSPtrs> _slot_id_to_filter_conjuncts;
146
    // not single(zero or multi) slot filter conjuncts
147
    vectorized::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