Coverage Report

Created: 2026-03-17 00:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format/table/jdbc_jni_reader.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 <cstddef>
21
#include <map>
22
#include <memory>
23
#include <string>
24
#include <unordered_map>
25
#include <unordered_set>
26
#include <vector>
27
28
#include "common/factory_creator.h"
29
#include "common/status.h"
30
#include "format/jni/jni_reader.h"
31
32
namespace doris {
33
class RuntimeProfile;
34
class RuntimeState;
35
class SlotDescriptor;
36
class TupleDescriptor;
37
class Block;
38
39
#include "common/compile_check_begin.h"
40
41
/**
42
 * JdbcJniReader reads data from JDBC data sources via the unified JniReader
43
 * framework. It delegates scanning to Java-side JdbcJniScanner (extends JniScanner).
44
 *
45
 * This reader follows the same pattern as PaimonJniReader, HudiJniReader, etc:
46
 * - Passes Java scanner class path and parameters to JniReader base constructor
47
 * - init_reader() calls open() to start the Java scanner
48
 * - get_next_block() reads data batch by batch (inherited from JniReader)
49
 * - close() releases Java resources (inherited from JniReader)
50
 *
51
 * Special types like bitmap, HLL and quantile_state are handled by:
52
 * 1. Temporarily replacing block columns to string type before reading
53
 * 2. Reading data as strings via JNI
54
 * 3. Casting string columns back to the target special types after reading
55
 */
56
class JdbcJniReader : public JniReader {
57
    ENABLE_FACTORY_CREATOR(JdbcJniReader);
58
59
public:
60
    /**
61
     * Construct a JdbcJniReader.
62
     *
63
     * @param file_slot_descs Slot descriptors for the output columns
64
     * @param state Runtime state
65
     * @param profile Runtime profile for metrics
66
     * @param jdbc_params JDBC connection parameters (jdbc_url, query_sql, etc.)
67
     */
68
    JdbcJniReader(const std::vector<SlotDescriptor*>& file_slot_descs, RuntimeState* state,
69
                  RuntimeProfile* profile, const std::map<std::string, std::string>& jdbc_params);
70
71
0
    ~JdbcJniReader() override = default;
72
73
    Status init_reader();
74
75
    /**
76
     * Override get_next_block to handle special types (bitmap, HLL, quantile_state, JSONB).
77
     * Before reading, replaces block columns of special types with string columns.
78
     * After reading, casts the string data back to the target types.
79
     */
80
    Status get_next_block(Block* block, size_t* read_rows, bool* eof) override;
81
82
private:
83
    std::map<std::string, std::string> _jdbc_params;
84
85
    /**
86
     * Check if a primitive type needs special string-based handling.
87
     * These types (bitmap, HLL, quantile_state, JSONB) are read as strings via JDBC
88
     * and need post-read casting back to their target types.
89
     */
90
    static bool _is_special_type(PrimitiveType type);
91
92
    /**
93
     * Cast a string column back to the target special type using the CAST function.
94
     * Follows the same pattern as the old vjdbc_connector.cpp _cast_string_to_hll/bitmap/json.
95
     */
96
    Status _cast_string_to_special_type(const SlotDescriptor* slot_desc, Block* block,
97
                                        int column_index, int num_rows);
98
};
99
100
#include "common/compile_check_end.h"
101
} // namespace doris