Coverage Report

Created: 2026-03-16 17:53

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
75
private:
76
    // Build JDBC params from TupleDescriptor for JdbcJniReader
77
    std::map<std::string, std::string> _build_jdbc_params(const TupleDescriptor* tuple_desc);
78
79
    // Convert TOdbcTableType enum to string for JdbcTypeHandlerFactory
80
0
    static std::string _odbc_table_type_to_string(TOdbcTableType::type type) {
81
0
        switch (type) {
82
0
        case TOdbcTableType::MYSQL:
83
0
            return "MYSQL";
84
0
        case TOdbcTableType::ORACLE:
85
0
            return "ORACLE";
86
0
        case TOdbcTableType::POSTGRESQL:
87
0
            return "POSTGRESQL";
88
0
        case TOdbcTableType::SQLSERVER:
89
0
            return "SQLSERVER";
90
0
        case TOdbcTableType::CLICKHOUSE:
91
0
            return "CLICKHOUSE";
92
0
        case TOdbcTableType::SAP_HANA:
93
0
            return "SAP_HANA";
94
0
        case TOdbcTableType::TRINO:
95
0
            return "TRINO";
96
0
        case TOdbcTableType::PRESTO:
97
0
            return "PRESTO";
98
0
        case TOdbcTableType::OCEANBASE:
99
0
            return "OCEANBASE";
100
0
        case TOdbcTableType::OCEANBASE_ORACLE:
101
0
            return "OCEANBASE_ORACLE";
102
0
        case TOdbcTableType::DB2:
103
0
            return "DB2";
104
0
        case TOdbcTableType::GBASE:
105
0
            return "GBASE";
106
0
        default:
107
0
            return "MYSQL";
108
0
        }
109
0
    }
110
111
    bool _jdbc_eos;
112
113
    // Tuple id resolved in prepare() to set _tuple_desc;
114
    TupleId _tuple_id;
115
    // SQL
116
    std::string _query_string;
117
    // Descriptor of tuples read from JDBC table.
118
    const TupleDescriptor* _tuple_desc = nullptr;
119
    // the sql query database type: like mysql, PG..
120
    TOdbcTableType::type _table_type;
121
    bool _is_tvf;
122
    // Unified JNI reader
123
    std::unique_ptr<JdbcJniReader> _jni_reader;
124
};
125
} // namespace doris