YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/common/ql_name.cc
Line
Count
Source
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#include "yb/common/ql_name.h"
15
#include <boost/algorithm/string/replace.hpp>
16
17
using std::string;
18
19
namespace yb {
20
21
// Prefix for various kinds of identifiers.
22
// Currently we only care about table::columns and jsonb::attributes.
23
static const char* kYcqlColumnPrefix = "C$_";                                           // columns.
24
static const char* kYcqlJattrPrefix = "J$_";                                    // JSONB attribute.
25
static const char* kYcqlEscape = "$$";                                         // Escape character.
26
static const char* kYcqlUnescape = "$";                                        // Escape character.
27
28
22.2k
string YcqlName::MangleColumnName(const string& col_name) {
29
  // Add prefix for column and escaping by replacing all appearances of '$' with '$$'.
30
22.2k
  return kYcqlColumnPrefix + ReplacePattern(col_name, kYcqlUnescape, kYcqlEscape);
31
22.2k
}
32
33
1.12k
string YcqlName::MangleJsonAttrName(const string& attr_name) {
34
  // Add prefix for JSONB attribute and escaping by replacing all appearances of '$' with '$$'.
35
1.12k
  return kYcqlJattrPrefix + ReplacePattern(attr_name, kYcqlUnescape, kYcqlEscape);
36
1.12k
}
37
38
51.5k
string YcqlName::DemangleName(const string& col_name) {
39
  // Removing all prefixes and un-escaping by replacing all appearances of '$$' with '$'.
40
51.5k
  string name;
41
51.5k
  name = ReplacePattern(col_name, kYcqlColumnPrefix, "");
42
51.5k
  name = ReplacePattern(name, kYcqlJattrPrefix, "");
43
51.5k
  name = ReplacePattern(name, kYcqlEscape, kYcqlUnescape);
44
51.5k
  return name;
45
51.5k
}
46
47
177k
string YcqlName::ReplacePattern(const string& ql_name, const string& pattern, const string& str) {
48
177k
  string name = ql_name;
49
177k
  boost::replace_all(name, pattern, str);
50
177k
  return name;
51
177k
}
52
53
}  // namespace yb