Coverage Report

Created: 2026-03-16 13:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/jdbc_utils.cpp
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
#include "util/jdbc_utils.h"
19
20
#include <filesystem>
21
22
#include "cloud/config.h"
23
#include "common/config.h"
24
#include "runtime/plugin/cloud_plugin_downloader.h"
25
26
namespace doris {
27
28
2.73k
Status JdbcUtils::resolve_driver_url(const std::string& url, std::string* result_url) {
29
    // Already a full URL (e.g. "file:///path/to/driver.jar" or "hdfs://...")
30
2.73k
    if (url.find(":/") != std::string::npos) {
31
2.71k
        *result_url = url;
32
2.71k
        return Status::OK();
33
2.71k
    }
34
35
14
    const char* doris_home = std::getenv("DORIS_HOME");
36
14
    if (doris_home == nullptr) {
37
0
        return Status::InternalError("DORIS_HOME environment variable is not set");
38
0
    }
39
40
14
    std::string default_url = std::string(doris_home) + "/plugins/jdbc_drivers";
41
14
    std::string default_old_url = std::string(doris_home) + "/jdbc_drivers";
42
43
14
    if (config::jdbc_drivers_dir == default_url) {
44
7
        std::string target_path = default_url + "/" + url;
45
7
        std::string old_target_path = default_old_url + "/" + url;
46
7
        if (std::filesystem::exists(target_path)) {
47
5
            *result_url = "file://" + target_path;
48
5
        } else if (std::filesystem::exists(old_target_path)) {
49
2
            *result_url = "file://" + old_target_path;
50
2
        } else if (config::is_cloud_mode()) {
51
            // In cloud/elastic deployments, BEs are ephemeral and driver JARs
52
            // may not exist locally. Try downloading from cloud storage.
53
0
            std::string downloaded_path;
54
0
            RETURN_IF_ERROR(CloudPluginDownloader::download_from_cloud(
55
0
                    CloudPluginDownloader::PluginType::JDBC_DRIVERS, url, target_path,
56
0
                    &downloaded_path));
57
0
            *result_url = "file://" + downloaded_path;
58
0
        } else {
59
0
            return Status::InternalError("JDBC driver file does not exist: " + url);
60
0
        }
61
7
    } else {
62
7
        *result_url = "file://" + config::jdbc_drivers_dir + "/" + url;
63
7
    }
64
14
    return Status::OK();
65
14
}
66
67
} // namespace doris