Coverage Report

Created: 2026-03-17 02:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/url/protocol.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
// This file is copied from
18
// https://github.com/ClickHouse/ClickHouse/blob/master/src/Functions/URL/protocol.h
19
// and modified by Doris
20
21
#pragma once
22
23
#include "exec/common/string_utils/string_utils.h"
24
#include "exprs/function/url/functions_url.h"
25
26
namespace doris {
27
28
/// Extracts scheme from given url.
29
16
inline StringRef get_url_scheme(const char* data, size_t size) {
30
    // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
31
16
    const char* pos = data;
32
16
    const char* end = data + size;
33
34
16
    if (is_alpha_ascii(*pos)) {
35
74
        for (++pos; pos < end; ++pos) {
36
71
            if (!(is_alpha_numeric_ascii(*pos) || *pos == '+' || *pos == '-' || *pos == '.')) {
37
11
                break;
38
11
            }
39
71
        }
40
41
14
        return StringRef(data, pos - data);
42
14
    }
43
44
2
    return {};
45
16
}
46
47
struct ExtractProtocol {
48
1
    static size_t get_reserve_length_for_element() { return strlen("https") + 1; }
49
50
16
    static void execute(Pos data, size_t size, Pos& res_data, size_t& res_size) {
51
16
        res_data = data;
52
16
        res_size = 0;
53
54
16
        StringRef scheme = get_url_scheme(data, size);
55
16
        Pos pos = data + scheme.size;
56
57
16
        if (scheme.size == 0 || (data + size) - pos < 4) return;
58
59
11
        if (pos[0] == ':') res_size = pos - data;
60
11
    }
61
};
62
63
} // namespace doris