Coverage Report

Created: 2026-03-13 09:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exec/table_connector.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 <fmt/format.h>
21
#include <gen_cpp/Types_types.h>
22
#include <stdint.h>
23
24
#include <string>
25
#include <vector>
26
27
#include "common/status.h"
28
#include "core/data_type/data_type.h"
29
#include "exprs/aggregate/aggregate_function.h"
30
#include "exprs/vexpr_fwd.h"
31
#include "runtime/runtime_profile.h"
32
33
namespace doris {
34
class RuntimeState;
35
class TupleDescriptor;
36
37
class Block;
38
39
// Table Connector for scan data from JDBC
40
class TableConnector {
41
public:
42
    TableConnector(const TupleDescriptor* tuple_desc, bool use_transaction,
43
                   std::string_view table_name, const std::string& sql_str);
44
2.71k
    virtual ~TableConnector() = default;
45
46
    virtual Status init_to_write(RuntimeProfile*) = 0;
47
    // exec query for table
48
    virtual Status query() = 0;
49
50
    // use in JDBC transaction
51
    virtual Status begin_trans() = 0;  // should be call after connect and before query
52
    virtual Status abort_trans() = 0;  // should be call after transaction abort
53
    virtual Status finish_trans() = 0; // should be call after transaction commit
54
55
    virtual Status close(Status) = 0;
56
57
    virtual Status exec_stmt_write(Block* block, const VExprContextSPtrs& _output_vexpr_ctxs,
58
                                   uint32_t* num_rows_sent) = 0;
59
60
    //write data into table vectorized
61
    virtual Status append(Block* block, const VExprContextSPtrs& _output_vexpr_ctxs,
62
                          uint32_t start_send_row, uint32_t* num_rows_sent,
63
                          TOdbcTableType::type table_type = TOdbcTableType::MYSQL) = 0;
64
65
    void init_profile(RuntimeProfile*);
66
67
    std::u16string utf8_to_u16string(const char* first, const char* last);
68
69
    // Default max buffer size use in insert to: 50MB, normally a batch is smaller than the size
70
    static constexpr uint32_t INSERT_BUFFER_SIZE = 1024l * 1024 * 50;
71
72
protected:
73
    bool _is_open;
74
    bool _use_tranaction;
75
    bool _is_in_transaction;
76
    std::string_view _table_name;
77
    const TupleDescriptor* _tuple_desc = nullptr;
78
    // only use in query
79
    std::string _sql_str;
80
    // only use in write
81
    fmt::memory_buffer _insert_stmt_buffer;
82
83
    // profile use in write
84
    // tuple convert timer, child timer of _append_row_batch_timer
85
    RuntimeProfile::Counter* _convert_tuple_timer = nullptr;
86
    // file write timer, child timer of _append_row_batch_timer
87
    RuntimeProfile::Counter* _result_send_timer = nullptr;
88
    // number of sent rows
89
    RuntimeProfile::Counter* _sent_rows_counter = nullptr;
90
};
91
92
} // namespace doris