Coverage Report

Created: 2024-11-22 11:49

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