YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/docdb/doc_path.h
Line
Count
Source (jump to first uncovered line)
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
#ifndef YB_DOCDB_DOC_PATH_H_
15
#define YB_DOCDB_DOC_PATH_H_
16
17
#include <stdint.h>
18
19
#include <cstring>
20
#include <functional>
21
#include <ostream>
22
#include <string>
23
#include <type_traits>
24
#include <unordered_set>
25
#include <utility>
26
#include <vector>
27
28
#include "yb/docdb/docdb_fwd.h"
29
#include "yb/docdb/key_bytes.h"
30
31
#include "yb/gutil/integral_types.h"
32
#include "yb/gutil/macros.h"
33
#include "yb/gutil/strings/substitute.h"
34
35
#include "yb/util/string_util.h"
36
37
namespace yb {
38
namespace docdb {
39
40
// Identifies a particular subdocument inside the logical representation of the document database.
41
// By "logical representation" we mean that we are not concerned with the exact keys used in the
42
// underlying key-value store. This is very similar to a SubDocKey without a hybrid time, and can
43
// probably be merged with it.
44
45
class DocPath {
46
 public:
47
  template<class... T>
48
61.5k
  DocPath(const KeyBytes& encoded_doc_key, T... subkeys) {
49
61.5k
    encoded_doc_key_ = encoded_doc_key;
50
61.5k
    AppendPrimitiveValues(&subkeys_, subkeys...);
51
61.5k
  }
_ZN2yb5docdb7DocPathC2IJNS0_14PrimitiveValueEEEERKNS0_8KeyBytesEDpT_
Line
Count
Source
48
78
  DocPath(const KeyBytes& encoded_doc_key, T... subkeys) {
49
78
    encoded_doc_key_ = encoded_doc_key;
50
78
    AppendPrimitiveValues(&subkeys_, subkeys...);
51
78
  }
Unexecuted instantiation: _ZN2yb5docdb7DocPathC2IJNS0_14PrimitiveValueES3_S3_EEERKNS0_8KeyBytesEDpT_
_ZN2yb5docdb7DocPathC2IJEEERKNS0_8KeyBytesEDpT_
Line
Count
Source
48
61.4k
  DocPath(const KeyBytes& encoded_doc_key, T... subkeys) {
49
61.4k
    encoded_doc_key_ = encoded_doc_key;
50
61.4k
    AppendPrimitiveValues(&subkeys_, subkeys...);
51
61.4k
  }
Unexecuted instantiation: _ZN2yb5docdb7DocPathC2IJNS0_14PrimitiveValueES3_EEERKNS0_8KeyBytesEDpT_
Unexecuted instantiation: _ZN2yb5docdb7DocPathC2IJPKciEEERKNS0_8KeyBytesEDpT_
Unexecuted instantiation: _ZN2yb5docdb7DocPathC2IJPKcEEERKNS0_8KeyBytesEDpT_
Unexecuted instantiation: _ZN2yb5docdb7DocPathC2IJPKcS4_EEERKNS0_8KeyBytesEDpT_
52
53
  template<class... T>
54
  DocPath(const Slice& encoded_doc_key, T... subkeys)
55
21.1M
      : encoded_doc_key_(encoded_doc_key) {
56
21.1M
    AppendPrimitiveValues(&subkeys_, subkeys...);
57
21.1M
  }
_ZN2yb5docdb7DocPathC2IJNS0_14PrimitiveValueEEEERKNS_5SliceEDpT_
Line
Count
Source
55
21.0M
      : encoded_doc_key_(encoded_doc_key) {
56
21.0M
    AppendPrimitiveValues(&subkeys_, subkeys...);
57
21.0M
  }
_ZN2yb5docdb7DocPathC2IJEEERKNS_5SliceEDpT_
Line
Count
Source
55
122k
      : encoded_doc_key_(encoded_doc_key) {
56
122k
    AppendPrimitiveValues(&subkeys_, subkeys...);
57
122k
  }
58
59
  DocPath(const KeyBytes& encoded_doc_key, const vector<PrimitiveValue>& subkeys)
60
      : encoded_doc_key_(encoded_doc_key),
61
0
        subkeys_(subkeys) {
62
0
  }
63
64
21.3M
  const KeyBytes& encoded_doc_key() const { return encoded_doc_key_; }
65
66
42.4M
  size_t num_subkeys() const { return subkeys_.size(); }
67
68
21.1M
  const PrimitiveValue& subkey(size_t i) const {
69
21.1M
    assert(i < num_subkeys());
70
21.1M
    return subkeys_[i];
71
21.1M
  }
72
73
  std::string ToString() const;
74
75
  void AddSubKey(const PrimitiveValue& subkey);
76
77
  void AddSubKey(PrimitiveValue&& subkey);
78
79
0
  const PrimitiveValue& last_subkey() const {
80
0
    assert(!subkeys_.empty());
81
0
    return subkeys_.back();
82
0
  }
83
84
  // Note: the hash is supposed to be uint16_t, but protobuf only supports uint32.
85
  // So this function takes in uint32_t.
86
  // TODO (akashnil): Add uint16 data type in docdb.
87
  static DocPath DocPathFromRedisKey(uint16_t hash, const string& key, const string& subkey = "");
88
89
15
  const std::vector<PrimitiveValue>& subkeys() const {
90
15
    return subkeys_;
91
15
  }
92
93
 private:
94
  // Encoded key identifying the document. This key can itself contain multiple components
95
  // (hash bucket, hashed components, range components).
96
  // TODO(mikhail): should this really be encoded?
97
  KeyBytes encoded_doc_key_;
98
99
  std::vector<PrimitiveValue> subkeys_;
100
};
101
102
1
inline std::ostream& operator << (std::ostream& out, const DocPath& doc_path) {
103
1
  return out << doc_path.ToString();
104
1
}
105
106
}  // namespace docdb
107
}  // namespace yb
108
109
#endif  // YB_DOCDB_DOC_PATH_H_