/Users/deen/code/yugabyte-db/src/yb/yql/pggate/pg_table.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/yql/pggate/pg_table.h" |
15 | | |
16 | | #include "yb/util/result.h" |
17 | | |
18 | | #include "yb/yql/pggate/pg_tabledesc.h" |
19 | | |
20 | | namespace yb { |
21 | | namespace pggate { |
22 | | |
23 | | PgTable::PgTable(const PgTableDescPtr& desc) |
24 | 2.99M | : desc_(desc), columns_(std::make_shared<std::vector<PgColumn>>()) { |
25 | 2.99M | if (!desc_) { |
26 | 151k | return; |
27 | 151k | } |
28 | 2.84M | size_t num_columns = desc_->num_columns(); |
29 | 2.84M | columns_->reserve(num_columns + 1); |
30 | 19.8M | for (size_t i = 0; i != num_columns; ++i) { |
31 | 16.9M | columns_->emplace_back(desc->schema(), i); |
32 | 16.9M | } |
33 | 2.84M | columns_->emplace_back(desc_->schema(), num_columns); |
34 | 2.84M | } |
35 | | |
36 | 17.6M | Result<PgColumn&> PgTable::ColumnForAttr(int attr_num) { |
37 | 17.6M | return (*columns_)[VERIFY_RESULT(desc_->FindColumn(attr_num))]; |
38 | 17.6M | } |
39 | | |
40 | 6.63M | PgColumn& PgTable::ColumnForIndex(size_t index) { |
41 | 6.63M | CHECK_LT(index + 1, columns_->size()); |
42 | 6.63M | return (*columns_)[index]; |
43 | 6.63M | } |
44 | | |
45 | | } // namespace pggate |
46 | | } // namespace yb |