YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/common/partial_row.cc
Line
Count
Source (jump to first uncovered line)
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
// The following only applies to changes made to this file as part of YugaByte development.
19
//
20
// Portions Copyright (c) YugaByte, Inc.
21
//
22
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
23
// in compliance with the License.  You may obtain a copy of the License at
24
//
25
// http://www.apache.org/licenses/LICENSE-2.0
26
//
27
// Unless required by applicable law or agreed to in writing, software distributed under the License
28
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29
// or implied.  See the License for the specific language governing permissions and limitations
30
// under the License.
31
//
32
33
#include "yb/common/partial_row.h"
34
35
#include <algorithm>
36
#include <string>
37
38
#include "yb/common/common.pb.h"
39
#include "yb/common/key_encoder.h"
40
#include "yb/common/row.h"
41
#include "yb/common/schema.h"
42
#include "yb/gutil/strings/substitute.h"
43
#include "yb/util/bitmap.h"
44
#include "yb/util/decimal.h"
45
#include "yb/util/result.h"
46
#include "yb/util/status.h"
47
#include "yb/util/status_log.h"
48
49
using strings::Substitute;
50
51
namespace yb {
52
53
namespace {
54
55
30
inline Result<size_t> FindColumn(const Schema& schema, const Slice& col_name) {
56
30
  GStringPiece sp(col_name.cdata(), col_name.size());
57
30
  auto result = schema.find_column(sp);
58
30
  if (PREDICT_FALSE(result == Schema::kColumnNotFound)) {
59
0
    return STATUS(NotFound, "No such column", col_name);
60
0
  }
61
30
  return result;
62
30
}
63
64
} // anonymous namespace
65
66
YBPartialRow::YBPartialRow(const Schema* schema)
67
12
  : schema_(schema) {
68
12
  DCHECK(schema_->initialized());
69
12
  size_t column_bitmap_size = BitmapSize(schema_->num_columns());
70
12
  size_t row_size = ContiguousRowHelper::row_size(*schema);
71
72
12
  auto dst = new uint8_t[2 * column_bitmap_size + row_size];
73
12
  isset_bitmap_ = dst;
74
12
  owned_strings_bitmap_ = isset_bitmap_ + column_bitmap_size;
75
76
12
  memset(isset_bitmap_, 0, 2 * column_bitmap_size);
77
78
12
  row_data_ = owned_strings_bitmap_ + column_bitmap_size;
79
12
#ifndef NDEBUG
80
12
  OverwriteWithPattern(reinterpret_cast<char*>(row_data_),
81
12
                       row_size, "NEWNEWNEWNEWNEW");
82
12
#endif
83
12
  ContiguousRowHelper::InitNullsBitmap(
84
12
    *schema_, row_data_, ContiguousRowHelper::null_bitmap_size(*schema_));
85
12
}
86
87
16
YBPartialRow::~YBPartialRow() {
88
16
  DeallocateOwnedStrings();
89
  // Both the row data and bitmap came from the same allocation.
90
  // The bitmap is at the start of it.
91
16
  delete [] isset_bitmap_;
92
16
}
93
94
YBPartialRow::YBPartialRow(const YBPartialRow& other)
95
4
    : schema_(other.schema_) {
96
4
  size_t column_bitmap_size = BitmapSize(schema_->num_columns());
97
4
  size_t row_size = ContiguousRowHelper::row_size(*schema_);
98
99
4
  size_t len = 2 * column_bitmap_size + row_size;
100
4
  isset_bitmap_ = new uint8_t[len];
101
4
  owned_strings_bitmap_ = isset_bitmap_ + column_bitmap_size;
102
4
  row_data_ = owned_strings_bitmap_ + column_bitmap_size;
103
104
  // Copy all bitmaps and row data.
105
4
  memcpy(isset_bitmap_, other.isset_bitmap_, len);
106
107
  // Copy owned strings.
108
20
  for (size_t col_idx = 0; col_idx < schema_->num_columns(); col_idx++) {
109
16
    if (BitmapTest(owned_strings_bitmap_, col_idx)) {
110
1
      ContiguousRow row(schema_, row_data_);
111
1
      Slice* slice = reinterpret_cast<Slice*>(row.mutable_cell_ptr(col_idx));
112
1
      auto data = new uint8_t[slice->size()];
113
1
      slice->relocate(data);
114
1
    }
115
16
  }
116
4
}
117
118
3
YBPartialRow& YBPartialRow::operator=(YBPartialRow other) {
119
3
  std::swap(schema_, other.schema_);
120
3
  std::swap(isset_bitmap_, other.isset_bitmap_);
121
3
  std::swap(owned_strings_bitmap_, other.owned_strings_bitmap_);
122
3
  std::swap(row_data_, other.row_data_);
123
3
  return *this;
124
3
}
125
126
template<typename T>
127
Status YBPartialRow::Set(const Slice& col_name,
128
                         const typename T::cpp_type& val,
129
19
                         bool owned) {
130
19
  return Set<T>(VERIFY_RESULT(FindColumn(*schema_, col_name)), val, owned);
131
19
}
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE1EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE2EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
_ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE3EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
Line
Count
Source
129
2
                         bool owned) {
130
2
  return Set<T>(VERIFY_RESULT(FindColumn(*schema_, col_name)), val, owned);
131
2
}
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE4EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE10EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE7EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE8EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE6EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
_ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE5EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
Line
Count
Source
129
15
                         bool owned) {
130
15
  return Set<T>(VERIFY_RESULT(FindColumn(*schema_, col_name)), val, owned);
131
15
}
_ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE9EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
Line
Count
Source
129
2
                         bool owned) {
130
2
  return Set<T>(VERIFY_RESULT(FindColumn(*schema_, col_name)), val, owned);
131
2
}
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE22EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE17EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE18EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE11EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE13EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE25EEEEENS_6StatusERKNS_5SliceERKNT_8cpp_typeEb
132
133
template<typename T>
134
Status YBPartialRow::Set(size_t col_idx,
135
                         const typename T::cpp_type& val,
136
37
                         bool owned) {
137
37
  const ColumnSchema& col = schema_->column(col_idx);
138
37
  if (PREDICT_FALSE(col.type_info()->type() != T::type)) {
139
    // TODO: at some point we could allow type coercion here.
140
3
    return STATUS(InvalidArgument,
141
3
      Substitute("invalid type $0 provided for column '$1' (expected $2)",
142
3
                 T::name(),
143
3
                 col.name(), col.type_info()->name()));
144
3
  }
145
146
34
  ContiguousRow row(schema_, row_data_);
147
148
  // If we're replacing an existing STRING/BINARY/INET value, deallocate the old value.
149
34
  if (T::physical_type == BINARY) DeallocateStringIfSet(col_idx, col);
150
151
  // Mark the column as set.
152
34
  BitmapSet(isset_bitmap_, col_idx);
153
154
34
  if (col.is_nullable()) {
155
6
    row.set_null(col_idx, false);
156
6
  }
157
158
34
  ContiguousRowCell<ContiguousRow> dst(&row, col_idx);
159
34
  memcpy(dst.mutable_ptr(), &val, sizeof(val));
160
34
  if (owned) {
161
15
    BitmapSet(owned_strings_bitmap_, col_idx);
162
15
  }
163
34
  return Status::OK();
164
34
}
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE1EEEEENS_6StatusEmRKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE2EEEEENS_6StatusEmRKNT_8cpp_typeEb
_ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE3EEEEENS_6StatusEmRKNT_8cpp_typeEb
Line
Count
Source
136
15
                         bool owned) {
137
15
  const ColumnSchema& col = schema_->column(col_idx);
138
15
  if (PREDICT_FALSE(col.type_info()->type() != T::type)) {
139
    // TODO: at some point we could allow type coercion here.
140
0
    return STATUS(InvalidArgument,
141
0
      Substitute("invalid type $0 provided for column '$1' (expected $2)",
142
0
                 T::name(),
143
0
                 col.name(), col.type_info()->name()));
144
0
  }
145
146
15
  ContiguousRow row(schema_, row_data_);
147
148
  // If we're replacing an existing STRING/BINARY/INET value, deallocate the old value.
149
15
  if (T::physical_type == BINARY) DeallocateStringIfSet(col_idx, col);
150
151
  // Mark the column as set.
152
15
  BitmapSet(isset_bitmap_, col_idx);
153
154
15
  if (col.is_nullable()) {
155
0
    row.set_null(col_idx, false);
156
0
  }
157
158
15
  ContiguousRowCell<ContiguousRow> dst(&row, col_idx);
159
15
  memcpy(dst.mutable_ptr(), &val, sizeof(val));
160
15
  if (owned) {
161
0
    BitmapSet(owned_strings_bitmap_, col_idx);
162
0
  }
163
15
  return Status::OK();
164
15
}
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE4EEEEENS_6StatusEmRKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE10EEEEENS_6StatusEmRKNT_8cpp_typeEb
_ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE5EEEEENS_6StatusEmRKNT_8cpp_typeEb
Line
Count
Source
136
19
                         bool owned) {
137
19
  const ColumnSchema& col = schema_->column(col_idx);
138
19
  if (PREDICT_FALSE(col.type_info()->type() != T::type)) {
139
    // TODO: at some point we could allow type coercion here.
140
2
    return STATUS(InvalidArgument,
141
2
      Substitute("invalid type $0 provided for column '$1' (expected $2)",
142
2
                 T::name(),
143
2
                 col.name(), col.type_info()->name()));
144
2
  }
145
146
17
  ContiguousRow row(schema_, row_data_);
147
148
  // If we're replacing an existing STRING/BINARY/INET value, deallocate the old value.
149
17
  if (T::physical_type == BINARY) DeallocateStringIfSet(col_idx, col);
150
151
  // Mark the column as set.
152
17
  BitmapSet(isset_bitmap_, col_idx);
153
154
17
  if (col.is_nullable()) {
155
4
    row.set_null(col_idx, false);
156
4
  }
157
158
17
  ContiguousRowCell<ContiguousRow> dst(&row, col_idx);
159
17
  memcpy(dst.mutable_ptr(), &val, sizeof(val));
160
17
  if (owned) {
161
14
    BitmapSet(owned_strings_bitmap_, col_idx);
162
14
  }
163
17
  return Status::OK();
164
17
}
_ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE9EEEEENS_6StatusEmRKNT_8cpp_typeEb
Line
Count
Source
136
3
                         bool owned) {
137
3
  const ColumnSchema& col = schema_->column(col_idx);
138
3
  if (PREDICT_FALSE(col.type_info()->type() != T::type)) {
139
    // TODO: at some point we could allow type coercion here.
140
1
    return STATUS(InvalidArgument,
141
1
      Substitute("invalid type $0 provided for column '$1' (expected $2)",
142
1
                 T::name(),
143
1
                 col.name(), col.type_info()->name()));
144
1
  }
145
146
2
  ContiguousRow row(schema_, row_data_);
147
148
  // If we're replacing an existing STRING/BINARY/INET value, deallocate the old value.
149
2
  if (T::physical_type == BINARY) DeallocateStringIfSet(col_idx, col);
150
151
  // Mark the column as set.
152
2
  BitmapSet(isset_bitmap_, col_idx);
153
154
2
  if (col.is_nullable()) {
155
2
    row.set_null(col_idx, false);
156
2
  }
157
158
2
  ContiguousRowCell<ContiguousRow> dst(&row, col_idx);
159
2
  memcpy(dst.mutable_ptr(), &val, sizeof(val));
160
2
  if (owned) {
161
1
    BitmapSet(owned_strings_bitmap_, col_idx);
162
1
  }
163
2
  return Status::OK();
164
2
}
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE7EEEEENS_6StatusEmRKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE8EEEEENS_6StatusEmRKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE6EEEEENS_6StatusEmRKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE22EEEEENS_6StatusEmRKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE17EEEEENS_6StatusEmRKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE18EEEEENS_6StatusEmRKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE11EEEEENS_6StatusEmRKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE13EEEEENS_6StatusEmRKNT_8cpp_typeEb
Unexecuted instantiation: _ZN2yb12YBPartialRow3SetINS_10TypeTraitsILNS_8DataTypeE25EEEEENS_6StatusEmRKNT_8cpp_typeEb
165
166
0
Status YBPartialRow::Set(size_t column_idx, const uint8_t* val) {
167
0
  const ColumnSchema& column_schema = schema()->column(column_idx);
168
169
0
  switch (column_schema.type_info()->type()) {
170
0
    case BOOL: {
171
0
      RETURN_NOT_OK(SetBool(column_idx, *reinterpret_cast<const bool*>(val)));
172
0
      break;
173
0
    };
174
0
    case INT8: {
175
0
      RETURN_NOT_OK(SetInt8(column_idx, *reinterpret_cast<const int8_t*>(val)));
176
0
      break;
177
0
    };
178
0
    case INT16: {
179
0
      RETURN_NOT_OK(SetInt16(column_idx, *reinterpret_cast<const int16_t*>(val)));
180
0
      break;
181
0
    };
182
0
    case INT32: {
183
0
      RETURN_NOT_OK(SetInt32(column_idx, *reinterpret_cast<const int32_t*>(val)));
184
0
      break;
185
0
    };
186
0
    case INT64: {
187
0
      RETURN_NOT_OK(SetInt64(column_idx, *reinterpret_cast<const int64_t*>(val)));
188
0
      break;
189
0
    };
190
0
    case FLOAT: {
191
0
      RETURN_NOT_OK(SetFloat(column_idx, *reinterpret_cast<const float*>(val)));
192
0
      break;
193
0
    };
194
0
    case DOUBLE: {
195
0
      RETURN_NOT_OK(SetDouble(column_idx, *reinterpret_cast<const double*>(val)));
196
0
      break;
197
0
    };
198
0
    case STRING: {
199
0
      RETURN_NOT_OK(SetStringCopy(column_idx, *reinterpret_cast<const Slice*>(val)));
200
0
      break;
201
0
    };
202
0
    case BINARY: {
203
0
      RETURN_NOT_OK(SetBinaryCopy(column_idx, *reinterpret_cast<const Slice*>(val)));
204
0
      break;
205
0
    };
206
0
    case TIMESTAMP: {
207
0
      RETURN_NOT_OK(SetTimestamp(column_idx, *reinterpret_cast<const int64_t*>(val)));
208
0
      break;
209
0
    };
210
0
    case INET: {
211
0
      RETURN_NOT_OK(SetInet(column_idx, *reinterpret_cast<const Slice*>(val)));
212
0
      break;
213
0
    };
214
0
    case JSONB: {
215
0
      RETURN_NOT_OK(SetJsonb(column_idx, *reinterpret_cast<const Slice*>(val)));
216
0
      break;
217
0
    };
218
0
    case UUID: {
219
0
      RETURN_NOT_OK(SetUuidCopy(column_idx, *reinterpret_cast<const Slice*>(val)));
220
0
      break;
221
0
    };
222
0
    case TIMEUUID: {
223
0
      RETURN_NOT_OK(SetTimeUuidCopy(column_idx, *reinterpret_cast<const Slice*>(val)));
224
0
      break;
225
0
    }
226
0
    case FROZEN: {
227
0
      RETURN_NOT_OK(SetFrozenCopy(column_idx, *reinterpret_cast<const Slice*>(val)));
228
0
      break;
229
0
    };
230
0
    case DECIMAL: FALLTHROUGH_INTENDED;
231
0
    default: {
232
0
      return STATUS(InvalidArgument, "Unknown column type in schema",
233
0
                                     column_schema.ToString());
234
0
    };
235
0
  }
236
0
  return Status::OK();
237
0
}
238
239
73
void YBPartialRow::DeallocateStringIfSet(size_t col_idx, const ColumnSchema& col) {
240
73
  if (BitmapTest(owned_strings_bitmap_, col_idx)) {
241
16
    ContiguousRow row(schema_, row_data_);
242
16
    const Slice* dst;
243
16
    if (col.type_info()->type() == BINARY) {
244
1
      dst = schema_->ExtractColumnFromRow<BINARY>(row, col_idx);
245
15
    } else if (col.type_info()->type() == INET) {
246
0
      dst = schema_->ExtractColumnFromRow<INET>(row, col_idx);
247
15
    } else if (col.type_info()->type() == JSONB) {
248
0
      dst = schema_->ExtractColumnFromRow<JSONB>(row, col_idx);
249
15
    } else if (col.type_info()->type() == UUID) {
250
0
      dst = schema_->ExtractColumnFromRow<UUID>(row, col_idx);
251
15
    } else if (col.type_info()->type() == TIMEUUID) {
252
0
      dst = schema_->ExtractColumnFromRow<TIMEUUID>(row, col_idx);
253
15
    } else if (col.type_info()->type() == FROZEN) {
254
0
      dst = schema_->ExtractColumnFromRow<FROZEN>(row, col_idx);
255
15
    } else {
256
15
      CHECK(col.type_info()->type() == STRING);
257
15
      dst = schema_->ExtractColumnFromRow<STRING>(row, col_idx);
258
15
    }
259
16
    delete [] dst->data();
260
16
    BitmapClear(owned_strings_bitmap_, col_idx);
261
16
  }
262
73
}
263
264
16
void YBPartialRow::DeallocateOwnedStrings() {
265
66
  for (size_t i = 0; i < schema_->num_columns(); i++) {
266
50
    DeallocateStringIfSet(i, schema_->column(i));
267
50
  }
268
16
}
269
270
//------------------------------------------------------------
271
// Setters
272
//------------------------------------------------------------
273
274
0
Status YBPartialRow::SetBool(const Slice& col_name, bool val) {
275
0
  return Set<TypeTraits<BOOL> >(col_name, val);
276
0
}
277
0
Status YBPartialRow::SetInt8(const Slice& col_name, int8_t val) {
278
0
  return Set<TypeTraits<INT8> >(col_name, val);
279
0
}
280
0
Status YBPartialRow::SetInt16(const Slice& col_name, int16_t val) {
281
0
  return Set<TypeTraits<INT16> >(col_name, val);
282
0
}
283
2
Status YBPartialRow::SetInt32(const Slice& col_name, int32_t val) {
284
2
  return Set<TypeTraits<INT32> >(col_name, val);
285
2
}
286
0
Status YBPartialRow::SetInt64(const Slice& col_name, int64_t val) {
287
0
  return Set<TypeTraits<INT64> >(col_name, val);
288
0
}
289
0
Status YBPartialRow::SetTimestamp(const Slice& col_name, int64_t val) {
290
0
  return Set<TypeTraits<TIMESTAMP> >(col_name, val);
291
0
}
292
0
Status YBPartialRow::SetFloat(const Slice& col_name, float val) {
293
0
  return Set<TypeTraits<FLOAT> >(col_name, val);
294
0
}
295
0
Status YBPartialRow::SetDouble(const Slice& col_name, double val) {
296
0
  return Set<TypeTraits<DOUBLE> >(col_name, val);
297
0
}
298
0
Status YBPartialRow::SetString(const Slice& col_name, const Slice& val) {
299
0
  return Set<TypeTraits<STRING> >(col_name, val, false);
300
0
}
301
0
Status YBPartialRow::SetBinary(const Slice& col_name, const Slice& val) {
302
0
  return Set<TypeTraits<BINARY> >(col_name, val, false);
303
0
}
304
0
Status YBPartialRow::SetFrozen(const Slice& col_name, const Slice& val) {
305
0
  return Set<TypeTraits<FROZEN> >(col_name, val, false);
306
0
}
307
0
Status YBPartialRow::SetInet(const Slice& col_name, const Slice& val) {
308
0
  return SetSliceCopy<TypeTraits<INET> >(col_name, val);
309
0
}
310
0
Status YBPartialRow::SetUuid(const Slice& col_name, const Slice& val) {
311
0
  return Set<TypeTraits<UUID> >(col_name, val, false);
312
0
}
313
0
Status YBPartialRow::SetTimeUuid(const Slice& col_name, const Slice& val) {
314
0
  return Set<TypeTraits<TIMEUUID> >(col_name, val, false);
315
0
}
316
0
Status YBPartialRow::SetDecimal(const Slice& col_name, const Slice& val) {
317
0
  return Set<TypeTraits<DECIMAL> >(col_name, val, false);
318
0
}
319
0
Status YBPartialRow::SetBool(size_t col_idx, bool val) {
320
0
  return Set<TypeTraits<BOOL> >(col_idx, val);
321
0
}
322
0
Status YBPartialRow::SetInt8(size_t col_idx, int8_t val) {
323
0
  return Set<TypeTraits<INT8> >(col_idx, val);
324
0
}
325
0
Status YBPartialRow::SetInt16(size_t col_idx, int16_t val) {
326
0
  return Set<TypeTraits<INT16> >(col_idx, val);
327
0
}
328
13
Status YBPartialRow::SetInt32(size_t col_idx, int32_t val) {
329
13
  return Set<TypeTraits<INT32> >(col_idx, val);
330
13
}
331
0
Status YBPartialRow::SetInt64(size_t col_idx, int64_t val) {
332
0
  return Set<TypeTraits<INT64> >(col_idx, val);
333
0
}
334
0
Status YBPartialRow::SetTimestamp(size_t col_idx, int64_t val) {
335
0
  return Set<TypeTraits<TIMESTAMP> >(col_idx, val);
336
0
}
337
3
Status YBPartialRow::SetString(size_t col_idx, const Slice& val) {
338
3
  return Set<TypeTraits<STRING> >(col_idx, val, false);
339
3
}
340
1
Status YBPartialRow::SetBinary(size_t col_idx, const Slice& val) {
341
1
  return Set<TypeTraits<BINARY> >(col_idx, val, false);
342
1
}
343
0
Status YBPartialRow::SetFrozen(size_t col_idx, const Slice& val) {
344
0
  return Set<TypeTraits<FROZEN> >(col_idx, val, false);
345
0
}
346
0
Status YBPartialRow::SetInet(size_t col_idx, const Slice& val) {
347
0
  return SetSliceCopy<TypeTraits<INET> >(col_idx, val);
348
0
}
349
0
Status YBPartialRow::SetJsonb(size_t col_idx, const Slice& val) {
350
0
  return SetSliceCopy<TypeTraits<JSONB> >(col_idx, val);
351
0
}
352
0
Status YBPartialRow::SetUuid(size_t col_idx, const Slice& val) {
353
0
  return Set<TypeTraits<UUID> >(col_idx, val, false);
354
0
}
355
0
Status YBPartialRow::SetTimeUuid(size_t col_idx, const Slice& val) {
356
0
  return Set<TypeTraits<TIMEUUID> >(col_idx, val, false);
357
0
}
358
0
Status YBPartialRow::SetDecimal(size_t col_idx, const Slice& val) {
359
0
  return Set<TypeTraits<DECIMAL> >(col_idx, val, false);
360
0
}
361
0
Status YBPartialRow::SetFloat(size_t col_idx, float val) {
362
0
  return Set<TypeTraits<FLOAT> >(col_idx, util::CanonicalizeFloat(val));
363
0
}
364
0
Status YBPartialRow::SetDouble(size_t col_idx, double val) {
365
0
  return Set<TypeTraits<DOUBLE> >(col_idx, util::CanonicalizeDouble(val));
366
0
}
367
368
2
Status YBPartialRow::SetBinaryCopy(const Slice& col_name, const Slice& val) {
369
2
  return SetSliceCopy<TypeTraits<BINARY> >(col_name, val);
370
2
}
371
0
Status YBPartialRow::SetBinaryCopy(size_t col_idx, const Slice& val) {
372
0
  return SetSliceCopy<TypeTraits<BINARY> >(col_idx, val);
373
0
}
374
15
Status YBPartialRow::SetStringCopy(const Slice& col_name, const Slice& val) {
375
15
  return SetSliceCopy<TypeTraits<STRING> >(col_name, val);
376
15
}
377
1
Status YBPartialRow::SetStringCopy(size_t col_idx, const Slice& val) {
378
1
  return SetSliceCopy<TypeTraits<STRING> >(col_idx, val);
379
1
}
380
0
Status YBPartialRow::SetUuidCopy(const Slice& col_name, const Slice& val) {
381
0
  return SetSliceCopy<TypeTraits<UUID> >(col_name, val);
382
0
}
383
0
Status YBPartialRow::SetUuidCopy(size_t col_idx, const Slice& val) {
384
0
  return SetSliceCopy<TypeTraits<UUID> >(col_idx, val);
385
0
}
386
0
Status YBPartialRow::SetTimeUuidCopy(const Slice& col_name, const Slice& val) {
387
0
  return SetSliceCopy<TypeTraits<TIMEUUID> >(col_name, val);
388
0
}
389
0
Status YBPartialRow::SetTimeUuidCopy(size_t col_idx, const Slice& val) {
390
0
  return SetSliceCopy<TypeTraits<TIMEUUID> >(col_idx, val);
391
0
}
392
0
Status YBPartialRow::SetFrozenCopy(const Slice& col_name, const Slice& val) {
393
0
  return SetSliceCopy<TypeTraits<FROZEN> >(col_name, val);
394
0
}
395
0
Status YBPartialRow::SetFrozenCopy(size_t col_idx, const Slice& val) {
396
0
  return SetSliceCopy<TypeTraits<FROZEN> >(col_idx, val);
397
0
}
398
399
template<typename T>
400
17
Status YBPartialRow::SetSliceCopy(const Slice& col_name, const Slice& val) {
401
17
  auto relocated = new uint8_t[val.size()];
402
17
  memcpy(relocated, val.data(), val.size());
403
17
  Slice relocated_val(relocated, val.size());
404
17
  Status s = Set<T>(col_name, relocated_val, true);
405
17
  if (!s.ok()) {
406
3
    delete [] relocated;
407
3
  }
408
17
  return s;
409
17
}
_ZN2yb12YBPartialRow12SetSliceCopyINS_10TypeTraitsILNS_8DataTypeE5EEEEENS_6StatusERKNS_5SliceES8_
Line
Count
Source
400
15
Status YBPartialRow::SetSliceCopy(const Slice& col_name, const Slice& val) {
401
15
  auto relocated = new uint8_t[val.size()];
402
15
  memcpy(relocated, val.data(), val.size());
403
15
  Slice relocated_val(relocated, val.size());
404
15
  Status s = Set<T>(col_name, relocated_val, true);
405
15
  if (!s.ok()) {
406
2
    delete [] relocated;
407
2
  }
408
15
  return s;
409
15
}
_ZN2yb12YBPartialRow12SetSliceCopyINS_10TypeTraitsILNS_8DataTypeE9EEEEENS_6StatusERKNS_5SliceES8_
Line
Count
Source
400
2
Status YBPartialRow::SetSliceCopy(const Slice& col_name, const Slice& val) {
401
2
  auto relocated = new uint8_t[val.size()];
402
2
  memcpy(relocated, val.data(), val.size());
403
2
  Slice relocated_val(relocated, val.size());
404
2
  Status s = Set<T>(col_name, relocated_val, true);
405
2
  if (!s.ok()) {
406
1
    delete [] relocated;
407
1
  }
408
2
  return s;
409
2
}
Unexecuted instantiation: _ZN2yb12YBPartialRow12SetSliceCopyINS_10TypeTraitsILNS_8DataTypeE13EEEEENS_6StatusERKNS_5SliceES8_
Unexecuted instantiation: _ZN2yb12YBPartialRow12SetSliceCopyINS_10TypeTraitsILNS_8DataTypeE25EEEEENS_6StatusERKNS_5SliceES8_
Unexecuted instantiation: _ZN2yb12YBPartialRow12SetSliceCopyINS_10TypeTraitsILNS_8DataTypeE17EEEEENS_6StatusERKNS_5SliceES8_
Unexecuted instantiation: _ZN2yb12YBPartialRow12SetSliceCopyINS_10TypeTraitsILNS_8DataTypeE18EEEEENS_6StatusERKNS_5SliceES8_
Unexecuted instantiation: _ZN2yb12YBPartialRow12SetSliceCopyINS_10TypeTraitsILNS_8DataTypeE22EEEEENS_6StatusERKNS_5SliceES8_
410
411
template<typename T>
412
1
Status YBPartialRow::SetSliceCopy(size_t col_idx, const Slice& val) {
413
1
  auto relocated = new uint8_t[val.size()];
414
1
  memcpy(relocated, val.data(), val.size());
415
1
  Slice relocated_val(relocated, val.size());
416
1
  Status s = Set<T>(col_idx, relocated_val, true);
417
1
  if (!s.ok()) {
418
0
    delete [] relocated;
419
0
  }
420
1
  return s;
421
1
}
_ZN2yb12YBPartialRow12SetSliceCopyINS_10TypeTraitsILNS_8DataTypeE5EEEEENS_6StatusEmRKNS_5SliceE
Line
Count
Source
412
1
Status YBPartialRow::SetSliceCopy(size_t col_idx, const Slice& val) {
413
1
  auto relocated = new uint8_t[val.size()];
414
1
  memcpy(relocated, val.data(), val.size());
415
1
  Slice relocated_val(relocated, val.size());
416
1
  Status s = Set<T>(col_idx, relocated_val, true);
417
1
  if (!s.ok()) {
418
0
    delete [] relocated;
419
0
  }
420
1
  return s;
421
1
}
Unexecuted instantiation: _ZN2yb12YBPartialRow12SetSliceCopyINS_10TypeTraitsILNS_8DataTypeE9EEEEENS_6StatusEmRKNS_5SliceE
Unexecuted instantiation: _ZN2yb12YBPartialRow12SetSliceCopyINS_10TypeTraitsILNS_8DataTypeE13EEEEENS_6StatusEmRKNS_5SliceE
Unexecuted instantiation: _ZN2yb12YBPartialRow12SetSliceCopyINS_10TypeTraitsILNS_8DataTypeE25EEEEENS_6StatusEmRKNS_5SliceE
Unexecuted instantiation: _ZN2yb12YBPartialRow12SetSliceCopyINS_10TypeTraitsILNS_8DataTypeE17EEEEENS_6StatusEmRKNS_5SliceE
Unexecuted instantiation: _ZN2yb12YBPartialRow12SetSliceCopyINS_10TypeTraitsILNS_8DataTypeE18EEEEENS_6StatusEmRKNS_5SliceE
Unexecuted instantiation: _ZN2yb12YBPartialRow12SetSliceCopyINS_10TypeTraitsILNS_8DataTypeE22EEEEENS_6StatusEmRKNS_5SliceE
422
423
2
Status YBPartialRow::SetNull(const Slice& col_name) {
424
2
  return SetNull(VERIFY_RESULT(FindColumn(*schema_, col_name)));
425
2
}
426
427
3
Status YBPartialRow::SetNull(size_t col_idx) {
428
3
  const ColumnSchema& col = schema_->column(col_idx);
429
3
  if (PREDICT_FALSE(!col.is_nullable())) {
430
1
    return STATUS(InvalidArgument, "column not nullable", col.ToString());
431
1
  }
432
433
2
  if (col.type_info()->physical_type() == BINARY) DeallocateStringIfSet(col_idx, col);
434
435
2
  ContiguousRow row(schema_, row_data_);
436
2
  row.set_null(col_idx, true);
437
438
  // Mark the column as set.
439
2
  BitmapSet(isset_bitmap_, col_idx);
440
2
  return Status::OK();
441
2
}
442
443
3
Status YBPartialRow::Unset(const Slice& col_name) {
444
3
  return Unset(VERIFY_RESULT(FindColumn(*schema_, col_name)));
445
3
}
446
447
3
Status YBPartialRow::Unset(size_t col_idx) {
448
3
  const ColumnSchema& col = schema_->column(col_idx);
449
3
  if (col.type_info()->physical_type() == BINARY) DeallocateStringIfSet(col_idx, col);
450
3
  BitmapClear(isset_bitmap_, col_idx);
451
3
  return Status::OK();
452
3
}
453
454
//------------------------------------------------------------
455
// Template instantiations: We instantiate all possible templates to avoid linker issues.
456
// see: https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl
457
// TODO We can probably remove this when we move to c++11 and can use "extern template"
458
//------------------------------------------------------------
459
460
template
461
Status YBPartialRow::SetSliceCopy<TypeTraits<STRING> >(size_t col_idx, const Slice& val);
462
463
template
464
Status YBPartialRow::SetSliceCopy<TypeTraits<BINARY> >(size_t col_idx, const Slice& val);
465
466
template
467
Status YBPartialRow::SetSliceCopy<TypeTraits<INET> >(size_t col_idx, const Slice& val);
468
469
template
470
Status YBPartialRow::SetSliceCopy<TypeTraits<JSONB> >(size_t col_idx, const Slice& val);
471
472
template
473
Status YBPartialRow::SetSliceCopy<TypeTraits<UUID> >(size_t col_idx, const Slice& val);
474
475
template
476
Status YBPartialRow::SetSliceCopy<TypeTraits<TIMEUUID> >(size_t col_idx, const Slice& val);
477
478
template
479
Status YBPartialRow::SetSliceCopy<TypeTraits<STRING> >(const Slice& col_name, const Slice& val);
480
481
template
482
Status YBPartialRow::SetSliceCopy<TypeTraits<BINARY> >(const Slice& col_name, const Slice& val);
483
484
template
485
Status YBPartialRow::SetSliceCopy<TypeTraits<INET> >(const Slice& col_name, const Slice& val);
486
487
template
488
Status YBPartialRow::SetSliceCopy<TypeTraits<JSONB> >(const Slice& col_name, const Slice& val);
489
490
template
491
Status YBPartialRow::SetSliceCopy<TypeTraits<UUID> >(const Slice& col_name, const Slice& val);
492
493
template
494
Status YBPartialRow::SetSliceCopy<TypeTraits<TIMEUUID> >(const Slice& col_name, const Slice& val);
495
496
template
497
Status YBPartialRow::Set<TypeTraits<INT8> >(size_t col_idx,
498
                                              const TypeTraits<INT8>::cpp_type& val,
499
                                              bool owned);
500
501
template
502
Status YBPartialRow::Set<TypeTraits<INT16> >(size_t col_idx,
503
                                               const TypeTraits<INT16>::cpp_type& val,
504
                                               bool owned);
505
506
template
507
Status YBPartialRow::Set<TypeTraits<INT32> >(size_t col_idx,
508
                                               const TypeTraits<INT32>::cpp_type& val,
509
                                               bool owned);
510
511
template
512
Status YBPartialRow::Set<TypeTraits<INT64> >(size_t col_idx,
513
                                               const TypeTraits<INT64>::cpp_type& val,
514
                                               bool owned);
515
516
template
517
Status YBPartialRow::Set<TypeTraits<TIMESTAMP> >(
518
    size_t col_idx,
519
    const TypeTraits<TIMESTAMP>::cpp_type& val,
520
    bool owned);
521
522
template
523
Status YBPartialRow::Set<TypeTraits<STRING> >(size_t col_idx,
524
                                                const TypeTraits<STRING>::cpp_type& val,
525
                                                bool owned);
526
527
template
528
Status YBPartialRow::Set<TypeTraits<BINARY> >(size_t col_idx,
529
                                                const TypeTraits<BINARY>::cpp_type& val,
530
                                                bool owned);
531
532
template
533
Status YBPartialRow::Set<TypeTraits<FLOAT> >(size_t col_idx,
534
                                               const TypeTraits<FLOAT>::cpp_type& val,
535
                                               bool owned);
536
537
template
538
Status YBPartialRow::Set<TypeTraits<DOUBLE> >(size_t col_idx,
539
                                                const TypeTraits<DOUBLE>::cpp_type& val,
540
                                                bool owned);
541
542
template
543
Status YBPartialRow::Set<TypeTraits<BOOL> >(size_t col_idx,
544
                                              const TypeTraits<BOOL>::cpp_type& val,
545
                                              bool owned);
546
547
template
548
Status YBPartialRow::Set<TypeTraits<INT8> >(const Slice& col_name,
549
                                              const TypeTraits<INT8>::cpp_type& val,
550
                                              bool owned);
551
552
template
553
Status YBPartialRow::Set<TypeTraits<INT16> >(const Slice& col_name,
554
                                               const TypeTraits<INT16>::cpp_type& val,
555
                                               bool owned);
556
557
template
558
Status YBPartialRow::Set<TypeTraits<INT32> >(const Slice& col_name,
559
                                               const TypeTraits<INT32>::cpp_type& val,
560
                                               bool owned);
561
562
template
563
Status YBPartialRow::Set<TypeTraits<INT64> >(const Slice& col_name,
564
                                               const TypeTraits<INT64>::cpp_type& val,
565
                                               bool owned);
566
567
template
568
Status YBPartialRow::Set<TypeTraits<TIMESTAMP> >(
569
    const Slice& col_name,
570
    const TypeTraits<TIMESTAMP>::cpp_type& val,
571
    bool owned);
572
573
template
574
Status YBPartialRow::Set<TypeTraits<FLOAT> >(const Slice& col_name,
575
                                               const TypeTraits<FLOAT>::cpp_type& val,
576
                                               bool owned);
577
578
template
579
Status YBPartialRow::Set<TypeTraits<DOUBLE> >(const Slice& col_name,
580
                                                const TypeTraits<DOUBLE>::cpp_type& val,
581
                                                bool owned);
582
583
template
584
Status YBPartialRow::Set<TypeTraits<BOOL> >(const Slice& col_name,
585
                                              const TypeTraits<BOOL>::cpp_type& val,
586
                                              bool owned);
587
588
template
589
Status YBPartialRow::Set<TypeTraits<STRING> >(const Slice& col_name,
590
                                                const TypeTraits<STRING>::cpp_type& val,
591
                                                bool owned);
592
593
template
594
Status YBPartialRow::Set<TypeTraits<BINARY> >(const Slice& col_name,
595
                                                const TypeTraits<BINARY>::cpp_type& val,
596
                                                bool owned);
597
598
//------------------------------------------------------------
599
// Getters
600
//------------------------------------------------------------
601
100
bool YBPartialRow::IsColumnSet(size_t col_idx) const {
602
100
  DCHECK_GE(col_idx, 0);
603
100
  DCHECK_LT(col_idx, schema_->num_columns());
604
100
  return BitmapTest(isset_bitmap_, col_idx);
605
100
}
606
607
0
bool YBPartialRow::IsColumnSet(const Slice& col_name) const {
608
0
  return IsColumnSet(CHECK_RESULT(FindColumn(*schema_, col_name)));
609
0
}
610
611
10
bool YBPartialRow::IsNull(size_t col_idx) const {
612
10
  const ColumnSchema& col = schema_->column(col_idx);
613
10
  if (!col.is_nullable()) {
614
2
    return false;
615
2
  }
616
617
8
  if (!IsColumnSet(col_idx)) return false;
618
619
8
  ContiguousRow row(schema_, row_data_);
620
8
  return row.is_null(col_idx);
621
8
}
622
623
3
bool YBPartialRow::IsNull(const Slice& col_name) const {
624
3
  return IsNull(CHECK_RESULT(FindColumn(*schema_, col_name)));
625
3
}
626
627
0
Status YBPartialRow::GetBool(const Slice& col_name, bool* val) const {
628
0
  return Get<TypeTraits<BOOL> >(col_name, val);
629
0
}
630
0
Status YBPartialRow::GetInt8(const Slice& col_name, int8_t* val) const {
631
0
  return Get<TypeTraits<INT8> >(col_name, val);
632
0
}
633
0
Status YBPartialRow::GetInt16(const Slice& col_name, int16_t* val) const {
634
0
  return Get<TypeTraits<INT16> >(col_name, val);
635
0
}
636
1
Status YBPartialRow::GetInt32(const Slice& col_name, int32_t* val) const {
637
1
  return Get<TypeTraits<INT32> >(col_name, val);
638
1
}
639
0
Status YBPartialRow::GetInt64(const Slice& col_name, int64_t* val) const {
640
0
  return Get<TypeTraits<INT64> >(col_name, val);
641
0
}
642
0
Status YBPartialRow::GetTimestamp(const Slice& col_name, int64_t* micros_since_utc_epoch) const {
643
0
  return Get<TypeTraits<TIMESTAMP> >(col_name, micros_since_utc_epoch);
644
0
}
645
0
Status YBPartialRow::GetFloat(const Slice& col_name, float* val) const {
646
0
  return Get<TypeTraits<FLOAT> >(col_name, val);
647
0
}
648
0
Status YBPartialRow::GetDouble(const Slice& col_name, double* val) const {
649
0
  return Get<TypeTraits<DOUBLE> >(col_name, val);
650
0
}
651
2
Status YBPartialRow::GetString(const Slice& col_name, Slice* val) const {
652
2
  return Get<TypeTraits<STRING> >(col_name, val);
653
2
}
654
0
Status YBPartialRow::GetBinary(const Slice& col_name, Slice* val) const {
655
0
  return Get<TypeTraits<BINARY> >(col_name, val);
656
0
}
657
0
Status YBPartialRow::GetInet(const Slice& col_name, Slice* val) const {
658
0
  return Get<TypeTraits<INET> >(col_name, val);
659
0
}
660
0
Status YBPartialRow::GetJsonb(const Slice& col_name, Slice* val) const {
661
0
  return Get<TypeTraits<JSONB> >(col_name, val);
662
0
}
663
0
Status YBPartialRow::GetUuid(const Slice& col_name, Slice* val) const {
664
0
  return Get<TypeTraits<UUID> >(col_name, val);
665
0
}
666
0
Status YBPartialRow::GetTimeUuid(const Slice& col_name, Slice* val) const {
667
0
  return Get<TypeTraits<TIMEUUID> >(col_name, val);
668
0
}
669
0
Status YBPartialRow::GetBool(size_t col_idx, bool* val) const {
670
0
  return Get<TypeTraits<BOOL> >(col_idx, val);
671
0
}
672
0
Status YBPartialRow::GetInt8(size_t col_idx, int8_t* val) const {
673
0
  return Get<TypeTraits<INT8> >(col_idx, val);
674
0
}
675
0
Status YBPartialRow::GetInt16(size_t col_idx, int16_t* val) const {
676
0
  return Get<TypeTraits<INT16> >(col_idx, val);
677
0
}
678
2
Status YBPartialRow::GetInt32(size_t col_idx, int32_t* val) const {
679
2
  return Get<TypeTraits<INT32> >(col_idx, val);
680
2
}
681
0
Status YBPartialRow::GetInt64(size_t col_idx, int64_t* val) const {
682
0
  return Get<TypeTraits<INT64> >(col_idx, val);
683
0
}
684
0
Status YBPartialRow::GetTimestamp(size_t col_idx, int64_t* micros_since_utc_epoch) const {
685
0
  return Get<TypeTraits<TIMESTAMP> >(col_idx, micros_since_utc_epoch);
686
0
}
687
0
Status YBPartialRow::GetFloat(size_t col_idx, float* val) const {
688
0
  return Get<TypeTraits<FLOAT> >(col_idx, val);
689
0
}
690
0
Status YBPartialRow::GetDouble(size_t col_idx, double* val) const {
691
0
  return Get<TypeTraits<DOUBLE> >(col_idx, val);
692
0
}
693
3
Status YBPartialRow::GetString(size_t col_idx, Slice* val) const {
694
3
  return Get<TypeTraits<STRING> >(col_idx, val);
695
3
}
696
2
Status YBPartialRow::GetBinary(size_t col_idx, Slice* val) const {
697
2
  return Get<TypeTraits<BINARY> >(col_idx, val);
698
2
}
699
0
Status YBPartialRow::GetInet(size_t col_idx, Slice* val) const {
700
0
  return Get<TypeTraits<INET> >(col_idx, val);
701
0
}
702
0
Status YBPartialRow::GetJsonb(size_t col_idx, Slice* val) const {
703
0
  return Get<TypeTraits<JSONB> >(col_idx, val);
704
0
}
705
0
Status YBPartialRow::GetUuid(size_t col_idx, Slice* val) const {
706
0
  return Get<TypeTraits<UUID> >(col_idx, val);
707
0
}
708
0
Status YBPartialRow::GetTimeUuid(size_t col_idx, Slice* val) const {
709
0
  return Get<TypeTraits<TIMEUUID> >(col_idx, val);
710
0
}
711
712
template<typename T>
713
Status YBPartialRow::Get(const Slice& col_name,
714
3
                         typename T::cpp_type* val) const {
715
3
  return Get<T>(VERIFY_RESULT(FindColumn(*schema_, col_name)), val);
716
3
}
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE6EEEEENS_6StatusERKNS_5SliceEPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE1EEEEENS_6StatusERKNS_5SliceEPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE2EEEEENS_6StatusERKNS_5SliceEPNT_8cpp_typeE
_ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE3EEEEENS_6StatusERKNS_5SliceEPNT_8cpp_typeE
Line
Count
Source
714
1
                         typename T::cpp_type* val) const {
715
1
  return Get<T>(VERIFY_RESULT(FindColumn(*schema_, col_name)), val);
716
1
}
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE4EEEEENS_6StatusERKNS_5SliceEPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE10EEEEENS_6StatusERKNS_5SliceEPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE7EEEEENS_6StatusERKNS_5SliceEPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE8EEEEENS_6StatusERKNS_5SliceEPNT_8cpp_typeE
_ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE5EEEEENS_6StatusERKNS_5SliceEPNT_8cpp_typeE
Line
Count
Source
714
2
                         typename T::cpp_type* val) const {
715
2
  return Get<T>(VERIFY_RESULT(FindColumn(*schema_, col_name)), val);
716
2
}
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE9EEEEENS_6StatusERKNS_5SliceEPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE13EEEEENS_6StatusERKNS_5SliceEPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE25EEEEENS_6StatusERKNS_5SliceEPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE17EEEEENS_6StatusERKNS_5SliceEPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE18EEEEENS_6StatusERKNS_5SliceEPNT_8cpp_typeE
717
718
template<typename T>
719
10
Status YBPartialRow::Get(size_t col_idx, typename T::cpp_type* val) const {
720
10
  const ColumnSchema& col = schema_->column(col_idx);
721
10
  if (PREDICT_FALSE(col.type_info()->type() != T::type)) {
722
    // TODO: at some point we could allow type coercion here.
723
1
    return STATUS(InvalidArgument,
724
1
      Substitute("invalid type $0 provided for column '$1' (expected $2)",
725
1
                 T::name(),
726
1
                 col.name(), col.type_info()->name()));
727
1
  }
728
729
9
  if (PREDICT_FALSE(!IsColumnSet(col_idx))) {
730
0
    return STATUS(NotFound, "column not set");
731
0
  }
732
9
  if (col.is_nullable() && IsNull(col_idx)) {
733
0
    return STATUS(NotFound, "column is NULL");
734
0
  }
735
736
9
  ContiguousRow row(schema_, row_data_);
737
9
  memcpy(val, row.cell_ptr(col_idx), sizeof(*val));
738
9
  return Status::OK();
739
9
}
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE6EEEEENS_6StatusEmPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE1EEEEENS_6StatusEmPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE2EEEEENS_6StatusEmPNT_8cpp_typeE
_ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE3EEEEENS_6StatusEmPNT_8cpp_typeE
Line
Count
Source
719
3
Status YBPartialRow::Get(size_t col_idx, typename T::cpp_type* val) const {
720
3
  const ColumnSchema& col = schema_->column(col_idx);
721
3
  if (PREDICT_FALSE(col.type_info()->type() != T::type)) {
722
    // TODO: at some point we could allow type coercion here.
723
0
    return STATUS(InvalidArgument,
724
0
      Substitute("invalid type $0 provided for column '$1' (expected $2)",
725
0
                 T::name(),
726
0
                 col.name(), col.type_info()->name()));
727
0
  }
728
729
3
  if (PREDICT_FALSE(!IsColumnSet(col_idx))) {
730
0
    return STATUS(NotFound, "column not set");
731
0
  }
732
3
  if (col.is_nullable() && IsNull(col_idx)) {
733
0
    return STATUS(NotFound, "column is NULL");
734
0
  }
735
736
3
  ContiguousRow row(schema_, row_data_);
737
3
  memcpy(val, row.cell_ptr(col_idx), sizeof(*val));
738
3
  return Status::OK();
739
3
}
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE4EEEEENS_6StatusEmPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE10EEEEENS_6StatusEmPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE7EEEEENS_6StatusEmPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE8EEEEENS_6StatusEmPNT_8cpp_typeE
_ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE5EEEEENS_6StatusEmPNT_8cpp_typeE
Line
Count
Source
719
5
Status YBPartialRow::Get(size_t col_idx, typename T::cpp_type* val) const {
720
5
  const ColumnSchema& col = schema_->column(col_idx);
721
5
  if (PREDICT_FALSE(col.type_info()->type() != T::type)) {
722
    // TODO: at some point we could allow type coercion here.
723
1
    return STATUS(InvalidArgument,
724
1
      Substitute("invalid type $0 provided for column '$1' (expected $2)",
725
1
                 T::name(),
726
1
                 col.name(), col.type_info()->name()));
727
1
  }
728
729
4
  if (PREDICT_FALSE(!IsColumnSet(col_idx))) {
730
0
    return STATUS(NotFound, "column not set");
731
0
  }
732
4
  if (col.is_nullable() && IsNull(col_idx)) {
733
0
    return STATUS(NotFound, "column is NULL");
734
0
  }
735
736
4
  ContiguousRow row(schema_, row_data_);
737
4
  memcpy(val, row.cell_ptr(col_idx), sizeof(*val));
738
4
  return Status::OK();
739
4
}
_ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE9EEEEENS_6StatusEmPNT_8cpp_typeE
Line
Count
Source
719
2
Status YBPartialRow::Get(size_t col_idx, typename T::cpp_type* val) const {
720
2
  const ColumnSchema& col = schema_->column(col_idx);
721
2
  if (PREDICT_FALSE(col.type_info()->type() != T::type)) {
722
    // TODO: at some point we could allow type coercion here.
723
0
    return STATUS(InvalidArgument,
724
0
      Substitute("invalid type $0 provided for column '$1' (expected $2)",
725
0
                 T::name(),
726
0
                 col.name(), col.type_info()->name()));
727
0
  }
728
729
2
  if (PREDICT_FALSE(!IsColumnSet(col_idx))) {
730
0
    return STATUS(NotFound, "column not set");
731
0
  }
732
2
  if (col.is_nullable() && IsNull(col_idx)) {
733
0
    return STATUS(NotFound, "column is NULL");
734
0
  }
735
736
2
  ContiguousRow row(schema_, row_data_);
737
2
  memcpy(val, row.cell_ptr(col_idx), sizeof(*val));
738
2
  return Status::OK();
739
2
}
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE13EEEEENS_6StatusEmPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE25EEEEENS_6StatusEmPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE17EEEEENS_6StatusEmPNT_8cpp_typeE
Unexecuted instantiation: _ZNK2yb12YBPartialRow3GetINS_10TypeTraitsILNS_8DataTypeE18EEEEENS_6StatusEmPNT_8cpp_typeE
740
741
//------------------------------------------------------------
742
// Key-encoding related functions
743
//------------------------------------------------------------
744
2
Status YBPartialRow::EncodeRowKey(string* encoded_key) const {
745
  // Currently, a row key must be fully specified.
746
  // TODO: allow specifying a prefix of the key, and automatically
747
  // fill the rest with minimum values.
748
3
  for (size_t i = 0; i < schema_->num_key_columns(); i++) {
749
2
    if (PREDICT_FALSE(!IsColumnSet(i))) {
750
1
      return STATUS(InvalidArgument, "All key columns must be set",
751
1
                                     schema_->column(i).name());
752
1
    }
753
2
  }
754
755
1
  encoded_key->clear();
756
1
  ContiguousRow row(schema_, row_data_);
757
758
2
  for (size_t i = 0; i < schema_->num_key_columns(); i++) {
759
1
    bool is_last = i == schema_->num_key_columns() - 1;
760
1
    const TypeInfo* ti = schema_->column(i).type_info();
761
1
    GetKeyEncoder<string>(ti).Encode(row.cell_ptr(i), is_last, encoded_key);
762
1
  }
763
764
1
  return Status::OK();
765
2
}
766
767
0
string YBPartialRow::ToEncodedRowKeyOrDie() const {
768
0
  string ret;
769
0
  CHECK_OK(EncodeRowKey(&ret));
770
0
  return ret;
771
0
}
772
773
//------------------------------------------------------------
774
// Utility code
775
//------------------------------------------------------------
776
777
0
bool YBPartialRow::IsHashKeySet() const {
778
0
  return schema_->num_hash_key_columns() > 0 &&
779
0
         BitMapIsAllSet(isset_bitmap_, 0, schema_->num_hash_key_columns());
780
0
}
781
782
2
bool YBPartialRow::IsKeySet() const {
783
2
  return schema_->num_key_columns() > 0 &&
784
2
         BitMapIsAllSet(isset_bitmap_, 0, schema_->num_key_columns());
785
2
}
786
787
0
bool YBPartialRow::IsHashOrPrimaryKeySet() const {
788
0
  return IsHashKeySet() || IsKeySet();
789
0
}
790
791
0
bool YBPartialRow::AllColumnsSet() const {
792
0
  return schema_->num_columns() > 0 &&
793
0
         BitMapIsAllSet(isset_bitmap_, 0, schema_->num_columns());
794
0
}
795
796
19
std::string YBPartialRow::ToString() const {
797
19
  ContiguousRow row(schema_, row_data_);
798
19
  std::string ret;
799
19
  bool first = true;
800
86
  for (size_t i = 0; i < schema_->num_columns(); i++) {
801
67
    if (IsColumnSet(i)) {
802
33
      if (!first) {
803
15
        ret.append(", ");
804
15
      }
805
33
      schema_->column(i).DebugCellAppend(row.cell(i), &ret);
806
33
      first = false;
807
33
    }
808
67
  }
809
19
  return ret;
810
19
}
811
812
//------------------------------------------------------------
813
// Serialization/deserialization
814
//------------------------------------------------------------
815
816
} // namespace yb