YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/client/schema.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/client/schema.h"
34
35
#include <unordered_map>
36
37
#include <glog/logging.h>
38
39
#include "yb/client/schema-internal.h"
40
41
#include "yb/common/partial_row.h"
42
#include "yb/common/ql_type.h"
43
#include "yb/common/schema.h"
44
#include "yb/common/wire_protocol.h"
45
46
#include "yb/gutil/map-util.h"
47
#include "yb/gutil/strings/substitute.h"
48
49
#include "yb/util/result.h"
50
#include "yb/util/status_format.h"
51
52
using std::shared_ptr;
53
using std::unordered_map;
54
using std::vector;
55
using strings::Substitute;
56
57
namespace yb {
58
namespace client {
59
////////////////////////////////////////////////////////////
60
// YBColumnSpec
61
////////////////////////////////////////////////////////////
62
63
YBColumnSpec::YBColumnSpec(const std::string& name)
64
11.1k
  : data_(new Data(name)) {
65
11.1k
}
66
67
11.1k
YBColumnSpec::~YBColumnSpec() {
68
11.1k
  delete data_;
69
11.1k
}
70
71
11.0k
YBColumnSpec* YBColumnSpec::Type(const std::shared_ptr<QLType>& type) {
72
11.0k
  data_->has_type = true;
73
11.0k
  data_->type = type;
74
11.0k
  return this;
75
11.0k
}
76
77
9.84k
YBColumnSpec* YBColumnSpec::Order(int32_t order) {
78
9.84k
  data_->has_order = true;
79
9.84k
  data_->order = order;
80
9.84k
  return this;
81
9.84k
}
82
83
5.41k
YBColumnSpec* YBColumnSpec::SetSortingType(SortingType sorting_type) {
84
5.41k
  data_->sorting_type = sorting_type;
85
5.41k
  return this;
86
5.41k
}
87
88
5.81k
YBColumnSpec* YBColumnSpec::PrimaryKey() {
89
5.81k
  NotNull();
90
5.81k
  data_->primary_key = true;
91
5.81k
  return this;
92
5.81k
}
93
94
3.51k
YBColumnSpec* YBColumnSpec::HashPrimaryKey() {
95
3.51k
  PrimaryKey();
96
3.51k
  data_->hash_primary_key = true;
97
3.51k
  return this;
98
3.51k
}
99
100
43
YBColumnSpec* YBColumnSpec::StaticColumn() {
101
43
  data_->static_column = true;
102
43
  return this;
103
43
}
104
105
6.31k
YBColumnSpec* YBColumnSpec::NotNull() {
106
6.31k
  data_->has_nullable = true;
107
6.31k
  data_->nullable = false;
108
6.31k
  return this;
109
6.31k
}
110
111
2.32k
YBColumnSpec* YBColumnSpec::Nullable() {
112
2.32k
  data_->has_nullable = true;
113
2.32k
  data_->nullable = true;
114
2.32k
  return this;
115
2.32k
}
116
117
16
YBColumnSpec* YBColumnSpec::Counter() {
118
16
  data_->is_counter = true;
119
16
  return this;
120
16
}
121
122
3.67k
YBColumnSpec* YBColumnSpec::PgTypeOid(int32_t oid) {
123
3.67k
  data_->has_pg_type_oid = true;
124
3.67k
  data_->pg_type_oid = oid;
125
3.67k
  return this;
126
3.67k
}
127
128
15
YBColumnSpec* YBColumnSpec::RenameTo(const std::string& new_name) {
129
15
  data_->has_rename_to = true;
130
15
  data_->rename_to = new_name;
131
15
  return this;
132
15
}
133
134
11.0k
Status YBColumnSpec::ToColumnSchema(YBColumnSchema* col) const {
135
  // Verify that the user isn't trying to use any methods that
136
  // don't make sense for CREATE.
137
11.0k
  if (data_->has_rename_to) {
138
    // TODO(KUDU-861): adjust these errors as this method will also be used for
139
    // ALTER TABLE ADD COLUMN support.
140
0
    return STATUS(NotSupported, "cannot rename a column during CreateTable",
141
0
                                data_->name);
142
0
  }
143
144
11.0k
  if (!data_->has_type) {
145
0
    return STATUS(InvalidArgument, "no type provided for column", data_->name);
146
0
  }
147
148
11.0k
  bool nullable = data_->has_nullable ? data_->nullable : true;
149
150
11.0k
  *col = YBColumnSchema(data_->name, data_->type, nullable, data_->hash_primary_key,
151
11.0k
                        data_->static_column, data_->is_counter, data_->order,
152
11.0k
                        data_->sorting_type, data_->pg_type_oid);
153
154
11.0k
  return Status::OK();
155
11.0k
}
156
157
1.04k
YBColumnSpec* YBColumnSpec::Type(DataType type) {
158
1.04k
  return Type(QLType::Create(type));
159
1.04k
}
160
161
////////////////////////////////////////////////////////////
162
// YBSchemaBuilder
163
////////////////////////////////////////////////////////////
164
165
class YBSchemaBuilder::Data {
166
 public:
167
3.30k
  ~Data() {
168
    // Rather than delete the specs here, we have to do it in
169
    // ~YBSchemaBuilder(), to avoid a circular dependency in the
170
    // headers declaring friend classes with nested classes.
171
3.30k
  }
172
173
  // These members can be used to specify a subset of columns are primary or hash primary keys.
174
  // NOTE: "key_col_names" and "key_hash_col_count" are not used unless "has_key_col_names" is true.
175
  bool has_key_col_names = false;
176
  vector<string> key_col_names;
177
  size_t key_hash_col_count = 0;
178
179
  vector<YBColumnSpec*> specs;
180
  TableProperties table_properties;
181
  std::string schema_name;
182
};
183
184
YBSchemaBuilder::YBSchemaBuilder()
185
3.31k
  : data_(new Data()) {
186
3.31k
}
187
188
3.30k
YBSchemaBuilder::~YBSchemaBuilder() {
189
10.8k
  for (YBColumnSpec* spec : data_->specs) {
190
    // Can't use STLDeleteElements because YBSchemaBuilder
191
    // is a friend of YBColumnSpec in order to access its destructor.
192
    // STLDeleteElements is a free function and therefore can't access it.
193
10.8k
    delete spec;
194
10.8k
  }
195
3.30k
  delete data_;
196
3.30k
}
197
198
10.8k
YBColumnSpec* YBSchemaBuilder::AddColumn(const std::string& name) {
199
10.8k
  auto c = new YBColumnSpec(name);
200
10.8k
  data_->specs.push_back(c);
201
10.8k
  return c;
202
10.8k
}
203
204
YBSchemaBuilder* YBSchemaBuilder::SetPrimaryKey(
205
    const std::vector<std::string>& key_col_names,
206
4
    size_t key_hash_col_count) {
207
4
  data_->has_key_col_names = true;
208
4
  data_->key_col_names = key_col_names;
209
4
  data_->key_hash_col_count = key_hash_col_count;
210
4
  return this;
211
4
}
212
213
3.02k
YBSchemaBuilder* YBSchemaBuilder::SetTableProperties(const TableProperties& table_properties) {
214
3.02k
  data_->table_properties = table_properties;
215
3.02k
  return this;
216
3.02k
}
217
218
1.41k
YBSchemaBuilder* YBSchemaBuilder::SetSchemaName(const std::string& pgschema_name) {
219
1.41k
  data_->schema_name = pgschema_name;
220
1.41k
  return this;
221
1.41k
}
222
223
0
std::string YBSchemaBuilder::SchemaName() {
224
0
  return data_->schema_name;
225
0
}
226
227
3.31k
Status YBSchemaBuilder::Build(YBSchema* schema) {
228
3.31k
  std::vector<YBColumnSchema> cols(data_->specs.size(), YBColumnSchema());
229
14.1k
  for (size_t i = 0; i < cols.size(); i++) {
230
10.8k
    RETURN_NOT_OK(data_->specs[i]->ToColumnSchema(&cols[i]));
231
10.8k
  }
232
233
3.31k
  size_t num_key_cols = 0;
234
3.31k
  if (!data_->has_key_col_names) {
235
    // Change the API to allow specifying each column individually as part of a primary key.
236
    // Previously, we must pass an extra list of columns if the key is a compound of columns.
237
    //
238
    // Removing the following restriction from Kudu:
239
    //   If they didn't explicitly pass the column names for key,
240
    //   then they should have set it on exactly one column.
241
3.30k
    const YBColumnSpec::Data* reached_primary_column = nullptr;
242
3.30k
    const YBColumnSpec::Data* reached_regular_column = nullptr;
243
14.1k
    for (size_t i = 0; i < cols.size(); i++) {
244
10.8k
      auto& column_data = *data_->specs[i]->data_;
245
10.8k
      if (column_data.hash_primary_key) {
246
3.51k
        num_key_cols++;
247
3.51k
        if (reached_primary_column) {
248
1
          return STATUS_FORMAT(
249
1
              InvalidArgument, "Hash primary key column '$0' should be before primary key '$1'",
250
1
              column_data.name, reached_primary_column->name);
251
1
        }
252
3.51k
        if (reached_regular_column) {
253
0
          return STATUS_FORMAT(
254
0
              InvalidArgument, "Hash primary key column '$0' should be before regular column '$1'",
255
0
              column_data.name, reached_regular_column->name);
256
0
        }
257
258
7.31k
      } else if (column_data.primary_key) {
259
2.29k
        num_key_cols++;
260
2.29k
        if (reached_regular_column) {
261
1
          return STATUS_FORMAT(
262
1
              InvalidArgument, "Primary key column '$0' should be before regular column '$1'",
263
1
              column_data.name, reached_regular_column->name);
264
1
        }
265
266
2.29k
        reached_primary_column = &column_data;
267
5.02k
      } else {
268
5.02k
        reached_regular_column = &column_data;
269
5.02k
      }
270
10.8k
    }
271
272
3.30k
    if (num_key_cols <= 0) {
273
2
      return STATUS(InvalidArgument, "No primary key specified");
274
2
    }
275
4
  } else {
276
    // Build a map from name to index of all of the columns.
277
4
    unordered_map<string, size_t> name_to_idx_map;
278
4
    size_t i = 0;
279
8
    for (YBColumnSpec* spec : data_->specs) {
280
      // If they did pass the key column names, then we should not have explicitly
281
      // set it on any columns.
282
8
      if (spec->data_->primary_key) {
283
1
        return STATUS(InvalidArgument, "Primary key specified by both SetPrimaryKey() and on a "
284
1
                                       "specific column", spec->data_->name);
285
1
      }
286
287
      // Set the primary keys here to make sure the two different APIs for ColumnSpecs yield the
288
      // same result.
289
7
      if (i < data_->key_hash_col_count) {
290
0
        spec->HashPrimaryKey();
291
7
      } else {
292
7
        spec->PrimaryKey();
293
7
      }
294
295
      // If we have a duplicate column name, the Schema::Reset() will catch it later,
296
      // anyway.
297
7
      name_to_idx_map[spec->data_->name] = i++;
298
7
    }
299
300
    // Convert the key column names to a set of indexes.
301
3
    vector<size_t> key_col_indexes;
302
5
    for (const string& key_col_name : data_->key_col_names) {
303
5
      size_t idx;
304
5
      if (!FindCopy(name_to_idx_map, key_col_name, &idx)) {
305
1
        return STATUS(InvalidArgument, "Primary key column not defined", key_col_name);
306
1
      }
307
4
      key_col_indexes.push_back(idx);
308
4
    }
309
310
    // Currently we require that the key columns be contiguous at the front
311
    // of the schema. We'll lift this restriction later -- hence the more
312
    // flexible user-facing API.
313
4
    for (size_t i = 0; i < key_col_indexes.size(); i++) {
314
3
      if (key_col_indexes[i] != i) {
315
1
        return STATUS(InvalidArgument, "Primary key columns must be listed first in the schema",
316
1
                                       data_->key_col_names[i]);
317
1
      }
318
3
    }
319
320
    // Indicate the first "num_key_cols" are primary key.
321
1
    num_key_cols = key_col_indexes.size();
322
1
  }
323
324
3.30k
  RETURN_NOT_OK(schema->Reset(cols, num_key_cols, data_->table_properties));
325
3.30k
  internal::GetSchema(schema).SetSchemaName(data_->schema_name);
326
327
3.30k
  return Status::OK();
328
3.30k
}
329
330
////////////////////////////////////////////////////////////
331
// YBColumnSchema
332
////////////////////////////////////////////////////////////
333
334
0
std::string YBColumnSchema::DataTypeToString(DataType type) {
335
0
  return DataType_Name(type);
336
0
}
337
338
YBColumnSchema::YBColumnSchema(const std::string &name,
339
                               const shared_ptr<QLType>& type,
340
                               bool is_nullable,
341
                               bool is_hash_key,
342
                               bool is_static,
343
                               bool is_counter,
344
                               int32_t order,
345
                               SortingType sorting_type,
346
3.32M
                               int32_t pg_type_oid) {
347
3.32M
  col_ = std::make_unique<ColumnSchema>(name, type, is_nullable, is_hash_key, is_static, is_counter,
348
3.32M
                                        order, sorting_type, pg_type_oid);
349
3.32M
}
350
351
10.8k
YBColumnSchema::YBColumnSchema(const YBColumnSchema& other) {
352
10.8k
  CopyFrom(other);
353
10.8k
}
354
355
3.48k
YBColumnSchema::YBColumnSchema() = default;
356
357
3.52M
YBColumnSchema::~YBColumnSchema() = default;
358
359
11.0k
YBColumnSchema& YBColumnSchema::operator=(const YBColumnSchema& other) {
360
11.0k
  if (&other != this) {
361
11.0k
    CopyFrom(other);
362
11.0k
  }
363
11.0k
  return *this;
364
11.0k
}
365
366
21.8k
void YBColumnSchema::CopyFrom(const YBColumnSchema& other) {
367
21.8k
  col_.reset();
368
21.8k
  if (other.col_) {
369
11.0k
    col_ = std::make_unique<ColumnSchema>(*other.col_);
370
11.0k
  }
371
21.8k
}
372
373
0
bool YBColumnSchema::Equals(const YBColumnSchema& other) const {
374
0
  return this == &other || col_ == other.col_ || (col_ != nullptr && col_->Equals(*other.col_));
375
0
}
376
377
6.83M
const std::string& YBColumnSchema::name() const {
378
6.83M
  return DCHECK_NOTNULL(col_)->name();
379
6.83M
}
380
381
0
bool YBColumnSchema::is_nullable() const {
382
0
  return DCHECK_NOTNULL(col_)->is_nullable();
383
0
}
384
385
0
bool YBColumnSchema::is_hash_key() const {
386
0
  return DCHECK_NOTNULL(col_)->is_hash_key();
387
0
}
388
389
3.33M
bool YBColumnSchema::is_static() const {
390
3.33M
  return DCHECK_NOTNULL(col_)->is_static();
391
3.33M
}
392
393
6.66M
const shared_ptr<QLType>& YBColumnSchema::type() const {
394
6.66M
  return DCHECK_NOTNULL(col_)->type();
395
6.66M
}
396
397
327
SortingType YBColumnSchema::sorting_type() const {
398
327
  return DCHECK_NOTNULL(col_)->sorting_type();
399
327
}
400
401
3.33M
bool YBColumnSchema::is_counter() const {
402
3.33M
  return DCHECK_NOTNULL(col_)->is_counter();
403
3.33M
}
404
405
0
int32_t YBColumnSchema::order() const {
406
0
  return DCHECK_NOTNULL(col_)->order();
407
0
}
408
409
0
int32_t YBColumnSchema::pg_type_oid() const {
410
0
  return DCHECK_NOTNULL(col_)->pg_type_oid();
411
0
}
412
413
40.4M
InternalType YBColumnSchema::ToInternalDataType(const std::shared_ptr<QLType>& ql_type) {
414
40.4M
  switch (ql_type->main()) {
415
316k
    case INT8:
416
316k
      return InternalType::kInt8Value;
417
199k
    case INT16:
418
199k
      return InternalType::kInt16Value;
419
20.9M
    case INT32:
420
20.9M
      return InternalType::kInt32Value;
421
881k
    case INT64:
422
881k
      return InternalType::kInt64Value;
423
2.91M
    case UINT32:
424
2.91M
      return InternalType::kUint32Value;
425
0
    case UINT64:
426
0
      return InternalType::kUint64Value;
427
20.3k
    case FLOAT:
428
20.3k
      return InternalType::kFloatValue;
429
977k
    case DOUBLE:
430
977k
      return InternalType::kDoubleValue;
431
12.0k
    case DECIMAL:
432
12.0k
      return InternalType::kDecimalValue;
433
5.45M
    case STRING:
434
5.45M
      return InternalType::kStringValue;
435
2.95k
    case TIMESTAMP:
436
2.95k
      return InternalType::kTimestampValue;
437
213
    case DATE:
438
213
      return InternalType::kDateValue;
439
210
    case TIME:
440
210
      return InternalType::kTimeValue;
441
351k
    case INET:
442
351k
      return InternalType::kInetaddressValue;
443
8.71k
    case JSONB:
444
8.71k
      return InternalType::kJsonbValue;
445
322k
    case UUID:
446
322k
      return InternalType::kUuidValue;
447
387
    case TIMEUUID:
448
387
      return InternalType::kTimeuuidValue;
449
572k
    case BOOL:
450
572k
      return InternalType::kBoolValue;
451
6.96M
    case BINARY:
452
6.96M
      return InternalType::kBinaryValue;
453
365
    case USER_DEFINED_TYPE: FALLTHROUGH_INTENDED;
454
274k
    case MAP:
455
274k
      return InternalType::kMapValue;
456
133k
    case SET:
457
133k
      return InternalType::kSetValue;
458
70.9k
    case LIST:
459
70.9k
      return InternalType::kListValue;
460
2.66k
    case VARINT:
461
2.66k
      return InternalType::kVarintValue;
462
627
    case FROZEN:
463
627
      return InternalType::kFrozenValue;
464
117
    case GIN_NULL:
465
117
      return InternalType::kGinNullValue;
466
467
361
    case TUPLE: FALLTHROUGH_INTENDED; // TODO (mihnea) Tuple type not fully supported yet
468
410
    case NULL_VALUE_TYPE: FALLTHROUGH_INTENDED;
469
410
    case UNKNOWN_DATA:
470
410
      return InternalType::VALUE_NOT_SET;
471
472
0
    case TYPEARGS: FALLTHROUGH_INTENDED;
473
0
    case UINT8: FALLTHROUGH_INTENDED;
474
0
    case UINT16:
475
0
      break;
476
0
  }
477
0
  LOG(FATAL) << "Internal error: unsupported type " << ql_type->ToString();
478
0
  return InternalType::VALUE_NOT_SET;
479
0
}
480
481
////////////////////////////////////////////////////////////
482
// YBSchema
483
////////////////////////////////////////////////////////////
484
485
namespace internal {
486
487
113M
const Schema& GetSchema(const YBSchema& schema) {
488
113M
  return *schema.schema_;
489
113M
}
490
491
155k
Schema& GetSchema(YBSchema* schema) {
492
155k
  return *schema->schema_;
493
155k
}
494
495
} // namespace internal
496
497
157k
YBSchema::YBSchema() {}
498
499
151k
YBSchema::YBSchema(const YBSchema& other) {
500
151k
  CopyFrom(other);
501
151k
}
502
503
52
YBSchema::YBSchema(YBSchema&& other) {
504
52
  MoveFrom(std::move(other));
505
52
}
506
507
YBSchema::YBSchema(const Schema& schema)
508
98
    : schema_(new Schema(schema)) {
509
98
}
510
511
248k
YBSchema::~YBSchema() {
512
248k
}
513
514
0
YBSchema& YBSchema::operator=(const YBSchema& other) {
515
0
  if (&other != this) {
516
0
    CopyFrom(other);
517
0
  }
518
0
  return *this;
519
0
}
520
521
0
YBSchema& YBSchema::operator=(YBSchema&& other) {
522
0
  if (&other != this) {
523
0
    MoveFrom(std::move(other));
524
0
  }
525
0
  return *this;
526
0
}
527
528
151k
void YBSchema::CopyFrom(const YBSchema& other) {
529
151k
  schema_.reset(new Schema(*other.schema_));
530
151k
  version_ = other.version();
531
151k
  is_compatible_with_previous_version_ = other.is_compatible_with_previous_version();
532
151k
}
533
534
52
void YBSchema::MoveFrom(YBSchema&& other) {
535
52
  schema_ = std::move(other.schema_);
536
52
  version_ = other.version();
537
52
  is_compatible_with_previous_version_ = other.is_compatible_with_previous_version();
538
52
}
539
540
152k
void YBSchema::Reset(std::unique_ptr<Schema> schema) {
541
152k
  schema_ = std::move(schema);
542
152k
}
543
544
Status YBSchema::Reset(const vector<YBColumnSchema>& columns, size_t key_columns,
545
3.30k
                       const TableProperties& table_properties) {
546
3.30k
  vector<ColumnSchema> cols_private;
547
10.8k
  for (const YBColumnSchema& col : columns) {
548
10.8k
    cols_private.push_back(*col.col_);
549
10.8k
  }
550
3.30k
  std::unique_ptr<Schema> new_schema(new Schema());
551
3.30k
  RETURN_NOT_OK(new_schema->Reset(cols_private, key_columns, table_properties));
552
553
3.30k
  schema_ = std::move(new_schema);
554
3.30k
  return Status::OK();
555
3.30k
}
556
557
0
bool YBSchema::Equals(const YBSchema& other) const {
558
0
  return this == &other ||
559
0
         (schema_.get() && other.schema_.get() && schema_->Equals(*other.schema_));
560
0
}
561
562
0
bool YBSchema::EquivalentForDataCopy(const YBSchema& other) const {
563
0
  return this == &other ||
564
0
      (schema_.get() && other.schema_.get() && schema_->EquivalentForDataCopy(*other.schema_));
565
0
}
566
567
0
Result<bool> YBSchema::Equals(const SchemaPB& other) const {
568
0
  Schema schema;
569
0
  RETURN_NOT_OK(SchemaFromPB(other, &schema));
570
571
0
  YBSchema yb_schema(schema);
572
0
  return Equals(yb_schema);
573
0
}
574
575
0
Result<bool> YBSchema::EquivalentForDataCopy(const SchemaPB& other) const {
576
0
  Schema schema;
577
0
  RETURN_NOT_OK(SchemaFromPB(other, &schema));
578
579
0
  YBSchema yb_schema(schema);
580
0
  return EquivalentForDataCopy(yb_schema);
581
0
}
582
583
1.41M
const TableProperties& YBSchema::table_properties() const {
584
1.41M
  return schema_->table_properties();
585
1.41M
}
586
587
3.49M
YBColumnSchema YBSchema::Column(size_t idx) const {
588
3.49M
  ColumnSchema col(schema_->column(idx));
589
3.49M
  return YBColumnSchema(col.name(), col.type(), col.is_nullable(), col.is_hash_key(),
590
3.49M
                        col.is_static(), col.is_counter(), col.order(), col.sorting_type());
591
3.49M
}
592
593
0
YBColumnSchema YBSchema::ColumnById(int32_t column_id) const {
594
0
  return Column(schema_->find_column_by_id(yb::ColumnId(column_id)));
595
0
}
596
597
3.81M
int32_t YBSchema::ColumnId(size_t idx) const {
598
3.81M
  return schema_->column_id(idx);
599
3.81M
}
600
601
0
std::unique_ptr<YBPartialRow> YBSchema::NewRow() const {
602
0
  return std::make_unique<YBPartialRow>(schema_.get());
603
0
}
604
605
2.95M
const std::vector<ColumnSchema>& YBSchema::columns() const {
606
2.95M
  return schema_->columns();
607
2.95M
}
608
609
4.22M
size_t YBSchema::num_columns() const {
610
4.22M
  return schema_->num_columns();
611
4.22M
}
612
613
4.92M
size_t YBSchema::num_key_columns() const {
614
4.92M
  return schema_->num_key_columns();
615
4.92M
}
616
617
4.41M
size_t YBSchema::num_hash_key_columns() const {
618
4.41M
  return schema_->num_hash_key_columns();
619
4.41M
}
620
621
221
size_t YBSchema::num_range_key_columns() const {
622
221
  return schema_->num_range_key_columns();
623
221
}
624
625
6.99M
bool YBSchema::is_compatible_with_previous_version() const {
626
6.99M
  return is_compatible_with_previous_version_;
627
6.99M
}
628
629
152k
void YBSchema::set_is_compatible_with_previous_version(bool is_compatible) {
630
152k
  is_compatible_with_previous_version_ = is_compatible;
631
152k
}
632
633
9.70M
uint32_t YBSchema::version() const {
634
9.70M
  return version_;
635
9.70M
}
636
637
152k
void YBSchema::set_version(uint32_t version) {
638
152k
  version_ = version;
639
152k
}
640
641
1
std::vector<size_t> YBSchema::GetPrimaryKeyColumnIndexes() const {
642
1
  std::vector<size_t> result(num_key_columns());
643
3
  for (size_t i = 0; i < num_key_columns(); i++) {
644
2
    result[i] = i;
645
2
  }
646
1
  return result;
647
1
}
648
649
0
string YBSchema::ToString() const {
650
0
  return schema_->ToString();
651
0
}
652
653
27
ssize_t YBSchema::FindColumn(const GStringPiece& name) const {
654
27
  return schema_->find_column(name);
655
27
}
656
657
} // namespace client
658
} // namespace yb