Coverage Report

Created: 2026-03-13 03:47

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
3
                                            const std::vector<std::string>& values) {
31
3
    std::stringstream partition_name_stream;
32
33
8
    for (size_t i = 0; i < partition_columns_input_index.size(); i++) {
34
5
        if (i > 0) {
35
2
            partition_name_stream << '/';
36
2
        }
37
5
        std::string column = columns[partition_columns_input_index[i]].name;
38
5
        std::string value = values[i];
39
5
        std::transform(column.begin(), column.end(), column.begin(),
40
19
                       [&](char c) { return std::tolower(c); });
41
5
        partition_name_stream << escape_path_name(column) << '=' << escape_path_name(value);
42
5
    }
43
44
3
    return partition_name_stream.str();
45
3
}
46
47
10
std::string VHiveUtils::escape_path_name(const std::string& path) {
48
10
    if (path.empty()) {
49
0
        return "__HIVE_DEFAULT_PARTITION__";
50
0
    }
51
52
10
    std::smatch match;
53
10
    if (!std::regex_search(path, match, PATH_CHAR_TO_ESCAPE)) {
54
8
        return path;
55
8
    }
56
57
2
    std::stringstream ss;
58
2
    size_t from_index = 0;
59
2
    auto begin = path.begin();
60
2
    auto end = path.end();
61
5
    while (std::regex_search(begin + from_index, end, match, PATH_CHAR_TO_ESCAPE)) {
62
3
        size_t escape_at_index = match.position() + from_index;
63
3
        if (escape_at_index > from_index) {
64
3
            ss << path.substr(from_index, escape_at_index - from_index);
65
3
        }
66
3
        char c = path[escape_at_index];
67
3
        ss << '%' << std::hex << std::uppercase << static_cast<int>(c >> 4)
68
3
           << static_cast<int>(c & 0xF);
69
3
        from_index = escape_at_index + 1;
70
3
    }
71
2
    if (from_index < path.length()) {
72
2
        ss << path.substr(from_index);
73
2
    }
74
2
    return ss.str();
75
10
}
76
} // namespace doris