YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/common/wire_protocol-test-util.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/wire_protocol-test-util.h"
15
16
#include "yb/docdb/doc_key.h"
17
18
namespace yb {
19
20
void AddKVToPB(int32_t key_val,
21
               int32_t int_val,
22
               const string& string_val,
23
1.06M
               docdb::KeyValueWriteBatchPB* write_batch) {
24
1.06M
  const ColumnId int_val_col_id(kFirstColumnId + 1);
25
1.06M
  const ColumnId string_val_col_id(kFirstColumnId + 2);
26
27
1.06M
  auto add_kv_pair =
28
2.12M
    [&](const SubDocKey &subdoc_key, const QLValuePB& value) {
29
2.12M
        KeyValuePairPB *const kv = write_batch->add_write_pairs();
30
2.12M
        kv->set_key(subdoc_key.Encode().ToStringBuffer());
31
2.12M
        docdb::AppendEncodedValue(value, SortingType::kNotSpecified, kv->mutable_value());
32
2.12M
    };
33
34
1.06M
  std::string hash_key;
35
1.06M
  YBPartition::AppendIntToKey<int32_t, uint32_t>(key_val, &hash_key);
36
1.06M
  auto hash = YBPartition::HashColumnCompoundValue(hash_key);
37
1.06M
  const DocKey doc_key(hash, {PrimitiveValue::Int32(key_val)}, {});
38
1.06M
  QLValuePB value;
39
1.06M
  value.set_int32_value(int_val);
40
1.06M
  add_kv_pair(SubDocKey(doc_key, PrimitiveValue(int_val_col_id)), value);
41
1.06M
  value.set_string_value(string_val);
42
1.06M
  add_kv_pair(SubDocKey(doc_key, PrimitiveValue(string_val_col_id)), value);
43
1.06M
}
44
45
}  // namespace yb