Coverage Report

Created: 2026-09-17 17:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/s3_uri.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 <string>
21
#include <string_view>
22
23
#include "common/status.h"
24
#include "util/string_util.h"
25
26
namespace doris {
27
28
// S3URI can handle following input:
29
// 1. s3://bucket_name/path/to/file.txt
30
//      bucket: bucket_num
31
//      key: path/to/file.txt
32
// 2. path/to/file.txt
33
//      bucket: ""
34
//      key: path/to/file.txt
35
// 3. abfss://container@account.dfs.core.windows.net/path/to/file.txt
36
//      bucket: container
37
//      key: path/to/file.txt
38
//      endpoint: account.dfs.core.windows.net
39
//      account: account
40
//
41
// Azure Data Lake locations intentionally retain their original URI form.  The
42
// object-storage factory uses the parsed endpoint/account to construct the
43
// native Azure client; they are not routed through the Hadoop filesystem.
44
class S3URI {
45
public:
46
1.77M
    S3URI(const std::string& location) : _location(location) {}
47
    // Azure SDK blob-name APIs encode their argument. Iceberg ADLSLocation passes
48
    // ABFS/WASB names literally, so percent-decode only HTTP(S) Azure URL paths.
49
    // Keep the old S3/raw-key contract. The provider flag also covers custom hosts.
50
    Status parse(bool azure_provider = false);
51
4.14k
    const std::string& get_bucket() const { return _bucket; }
52
1.77M
    const std::string& get_key() const { return _key; }
53
    // The authority host, when present.  For Azure ABFS/WASB paths this is the
54
    // account host (for example account.dfs.core.windows.net).
55
98
    const std::string& get_endpoint() const { return _endpoint; }
56
    // The storage account name parsed from an Azure authority.
57
32
    const std::string& get_account() const { return _account; }
58
216
    const std::string& get_scheme() const { return _scheme; }
59
1.34k
    bool is_azure() const { return _is_azure; }
60
    static bool is_azure_endpoint(std::string_view authority);
61
0
    const std::string& get_location() const { return _location; }
62
    std::string to_string() const;
63
64
private:
65
    Status _parse_authority(const std::string& scheme, const std::string& rest,
66
                            bool azure_provider);
67
    Status _parsing_error(std::string_view message, bool azure_provider) const;
68
69
    static const std::string _SCHEME_S3;
70
    static const std::string _SCHEME_ABFS;
71
    static const std::string _SCHEME_ABFSS;
72
    static const std::string _SCHEME_WASB;
73
    static const std::string _SCHEME_WASBS;
74
    static const std::string _SCHEME_HTTP;
75
    static const std::string _SCHEME_HTTPS;
76
    static const std::string _SCHEME_DELIM;
77
    static const std::string _PATH_DELIM;
78
    static const std::string _QUERY_DELIM;
79
    static const std::string _FRAGMENT_DELIM;
80
    static const StringCaseSet _VALID_SCHEMES;
81
82
    std::string _location;
83
    std::string _scheme;
84
    std::string _bucket;
85
    std::string _key;
86
    std::string _endpoint;
87
    std::string _account;
88
    bool _is_azure = false;
89
};
90
} // end namespace doris