Coverage Report

Created: 2026-08-07 05:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exec/scan/jdbc_scanner.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 <gen_cpp/Types_types.h>
21
#include <stdint.h>
22
23
#include <map>
24
#include <memory>
25
#include <string>
26
27
#include "common/factory_creator.h"
28
#include "common/global_types.h"
29
#include "common/status.h"
30
#include "exec/operator/jdbc_scan_operator.h"
31
#include "exec/scan/scanner.h"
32
#include "format/table/jdbc_jni_reader.h"
33
#include "runtime/runtime_profile.h"
34
35
namespace doris {
36
class RuntimeState;
37
class TupleDescriptor;
38
39
class Block;
40
class VExprContext;
41
42
/**
43
 * DEPRECATED: This class is transitional and should be removed once JDBC scanning
44
 * is fully integrated into the FileScanner path.
45
 *
46
 * JdbcScanner is the pipeline-level scanner for JDBC data sources.
47
 * It delegates to JdbcJniReader internally, which uses the unified
48
 * JniReader → JdbcJniScanner (Java) path for data reading.
49
 *
50
 * Prerequisites before deletion:
51
 * 1. FE: Change JdbcScanNode to generate FileScanNode plan with TFileFormatType::FORMAT_JDBC,
52
 *    so JDBC scans flow through FileScanner instead of JDBCScanLocalState → JdbcScanner.
53
 * 2. BE: Add FORMAT_JDBC case in FileScanner::_create_reader() to create JdbcJniReader
54
 *    (similar to Paimon/Hudi/MaxCompute/TrinoConnector).
55
 * 3. BE: Remove JDBCScanLocalState / jdbc_scan_operator.h/cpp which depend on this class.
56
 * 4. After the above, this file (jdbc_scanner.h/cpp) can be safely deleted.
57
 */
58
class JdbcScanner : public Scanner {
59
    ENABLE_FACTORY_CREATOR(JdbcScanner);
60
61
public:
62
    friend class JdbcJniReader;
63
64
    JdbcScanner(RuntimeState* state, doris::JDBCScanLocalState* parent, int64_t limit,
65
                const TupleId& tuple_id, const std::string& query_string,
66
                TOdbcTableType::type table_type, bool is_tvf, RuntimeProfile* profile);
67
    Status _open_impl(RuntimeState* state) override;
68
    Status close(RuntimeState* state) override;
69
70
    Status init(RuntimeState* state, const VExprContextSPtrs& conjuncts) override;
71
72
protected:
73
    Status _get_block_impl(RuntimeState* state, Block* block, bool* eos) override;
74
    void _collect_profile_before_close() override;
75
76
private:
77
    // Build JDBC params from TupleDescriptor for JdbcJniReader
78
    std::map<std::string, std::string> _build_jdbc_params(const TupleDescriptor* tuple_desc);
79
80
    // Convert TOdbcTableType enum to string for JdbcTypeHandlerFactory
81
0
    static std::string _odbc_table_type_to_string(TOdbcTableType::type type) {
82
0
        switch (type) {
83
0
        case TOdbcTableType::MYSQL:
84
0
            return "MYSQL";
85
0
        case TOdbcTableType::ORACLE:
86
0
            return "ORACLE";
87
0
        case TOdbcTableType::POSTGRESQL:
88
0
            return "POSTGRESQL";
89
0
        case TOdbcTableType::SQLSERVER:
90
0
            return "SQLSERVER";
91
0
        case TOdbcTableType::CLICKHOUSE:
92
0
            return "CLICKHOUSE";
93
0
        case TOdbcTableType::SAP_HANA:
94
0
            return "SAP_HANA";
95
0
        case TOdbcTableType::TRINO:
96
0
            return "TRINO";
97
0
        case TOdbcTableType::PRESTO:
98
0
            return "PRESTO";
99
0
        case TOdbcTableType::OCEANBASE:
100
0
            return "OCEANBASE";
101
0
        case TOdbcTableType::OCEANBASE_ORACLE:
102
0
            return "OCEANBASE_ORACLE";
103
0
        case TOdbcTableType::DB2:
104
0
            return "DB2";
105
0
        case TOdbcTableType::GBASE:
106
0
            return "GBASE";
107
0
        default:
108
0
            return "MYSQL";
109
0
        }
110
0
    }
111
112
    bool _jdbc_eos;
113
114
    // Tuple id resolved in prepare() to set _tuple_desc;
115
    TupleId _tuple_id;
116
    // SQL
117
    std::string _query_string;
118
    // Descriptor of tuples read from JDBC table.
119
    const TupleDescriptor* _tuple_desc = nullptr;
120
    // the sql query database type: like mysql, PG..
121
    TOdbcTableType::type _table_type;
122
    bool _is_tvf;
123
    // Unified JNI reader
124
    std::unique_ptr<JdbcJniReader> _jni_reader;
125
};
126
} // namespace doris