Coverage Report

Created: 2026-04-07 11:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exec/sink/writer/vhive_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 "exec/sink/writer/vhive_utils.h"
19
20
#include <algorithm>
21
#include <regex>
22
#include <sstream>
23
24
namespace doris {
25
26
const std::regex VHiveUtils::PATH_CHAR_TO_ESCAPE("[\\x00-\\x1F\"#%'*/:=?\\\\\\x7F\\{\\[\\]\\^]");
27
28
std::string VHiveUtils::make_partition_name(const std::vector<THiveColumn>& columns,
29
                                            const std::vector<int>& partition_columns_input_index,
30
651
                                            const std::vector<std::string>& values) {
31
651
    std::stringstream partition_name_stream;
32
33
2.47k
    for (size_t i = 0; i < partition_columns_input_index.size(); i++) {
34
1.82k
        if (i > 0) {
35
1.17k
            partition_name_stream << '/';
36
1.17k
        }
37
1.82k
        std::string column = columns[partition_columns_input_index[i]].name;
38
1.82k
        std::string value = values[i];
39
1.82k
        std::transform(column.begin(), column.end(), column.begin(),
40
13.0k
                       [&](char c) { return std::tolower(c); });
41
1.82k
        partition_name_stream << escape_path_name(column) << '=' << escape_path_name(value);
42
1.82k
    }
43
44
651
    return partition_name_stream.str();
45
651
}
46
47
7.41k
std::string VHiveUtils::escape_path_name(const std::string& path) {
48
7.41k
    if (path.empty()) {
49
2
        return "__HIVE_DEFAULT_PARTITION__";
50
2
    }
51
52
7.41k
    std::smatch match;
53
7.41k
    if (!std::regex_search(path, match, PATH_CHAR_TO_ESCAPE)) {
54
7.23k
        return path;
55
7.23k
    }
56
57
177
    std::stringstream ss;
58
177
    size_t from_index = 0;
59
177
    auto begin = path.begin();
60
177
    auto end = path.end();
61
1.26k
    while (std::regex_search(begin + from_index, end, match, PATH_CHAR_TO_ESCAPE)) {
62
1.08k
        size_t escape_at_index = match.position() + from_index;
63
1.08k
        if (escape_at_index > from_index) {
64
819
            ss << path.substr(from_index, escape_at_index - from_index);
65
819
        }
66
1.08k
        char c = path[escape_at_index];
67
1.08k
        ss << '%' << std::hex << std::uppercase << static_cast<int>(c >> 4)
68
1.08k
           << static_cast<int>(c & 0xF);
69
1.08k
        from_index = escape_at_index + 1;
70
1.08k
    }
71
177
    if (from_index < path.length()) {
72
150
        ss << path.substr(from_index);
73
150
    }
74
177
    return ss.str();
75
7.41k
}
76
} // namespace doris