YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
21.4k
string YcqlName::MangleColumnName(const string& col_name) {
29
  // Add prefix for column and escaping by replacing all appearances of '$' with '$$'.
30
21.4k
  return kYcqlColumnPrefix + ReplacePattern(col_name, kYcqlUnescape, kYcqlEscape);
31
21.4k
}
32
33
1.16k
string YcqlName::MangleJsonAttrName(const string& attr_name) {
34
  // Add prefix for JSONB attribute and escaping by replacing all appearances of '$' with '$$'.
35
1.16k
  return kYcqlJattrPrefix + ReplacePattern(attr_name, kYcqlUnescape, kYcqlEscape);
36
1.16k
}
37
38
56.3k
string YcqlName::DemangleName(const string& col_name) {
39
  // Removing all prefixes and un-escaping by replacing all appearances of '$$' with '$'.
40
56.3k
  string name;
41
56.3k
  name = ReplacePattern(col_name, kYcqlColumnPrefix, "");
42
56.3k
  name = ReplacePattern(name, kYcqlJattrPrefix, "");
43
56.3k
  name = ReplacePattern(name, kYcqlEscape, kYcqlUnescape);
44
56.3k
  return name;
45
56.3k
}
46
47
191k
string YcqlName::ReplacePattern(const string& ql_name, const string& pattern, const string& str) {
48
191k
  string name = ql_name;
49
191k
  boost::replace_all(name, pattern, str);
50
191k
  return name;
51
191k
}
52
53
}  // namespace yb