/Users/deen/code/yugabyte-db/src/yb/yql/pggate/pg_column.h
Line | Count | Source (jump to first uncovered line) |
1 | | //-------------------------------------------------------------------------------------------------- |
2 | | // Copyright (c) YugaByte, Inc. |
3 | | // |
4 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
5 | | // in compliance with the License. You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
10 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
11 | | // or implied. See the License for the specific language governing permissions and limitations |
12 | | // under the License. |
13 | | // |
14 | | // |
15 | | // Structure definitions for column descriptor of a table. |
16 | | //-------------------------------------------------------------------------------------------------- |
17 | | |
18 | | #ifndef YB_YQL_PGGATE_PG_COLUMN_H_ |
19 | | #define YB_YQL_PGGATE_PG_COLUMN_H_ |
20 | | |
21 | | #include "yb/common/common_fwd.h" |
22 | | #include "yb/common/ql_datatype.h" |
23 | | |
24 | | namespace yb { |
25 | | namespace pggate { |
26 | | |
27 | | class PgColumn { |
28 | | public: |
29 | | // Constructor & Destructor. |
30 | | PgColumn(std::reference_wrapper<const Schema> schema, size_t index); |
31 | | |
32 | | // Bindings for write requests. |
33 | | PgsqlExpressionPB *AllocPrimaryBindPB(PgsqlWriteRequestPB *write_req); |
34 | | PgsqlExpressionPB *AllocBindPB(PgsqlWriteRequestPB *write_req); |
35 | | |
36 | | // Bindings for read requests. |
37 | | PgsqlExpressionPB *AllocPrimaryBindPB(PgsqlReadRequestPB *write_req); |
38 | | PgsqlExpressionPB *AllocBindPB(PgsqlReadRequestPB *read_req); |
39 | | |
40 | | // Bindings for read requests. |
41 | | PgsqlExpressionPB *AllocBindConditionExprPB(PgsqlReadRequestPB *read_req); |
42 | | |
43 | | // Assign values for write requests. |
44 | | PgsqlExpressionPB *AllocAssignPB(PgsqlWriteRequestPB *write_req); |
45 | | |
46 | | void ResetBindPB(); |
47 | | |
48 | | // Access functions. |
49 | | const ColumnSchema& desc() const; |
50 | | |
51 | 0 | const PgsqlExpressionPB *bind_pb() const { |
52 | 0 | return bind_pb_; |
53 | 0 | } |
54 | | |
55 | 10.9M | PgsqlExpressionPB *bind_pb() { |
56 | 10.9M | return bind_pb_; |
57 | 10.9M | } |
58 | | |
59 | 259k | PgsqlExpressionPB *assign_pb() { |
60 | 259k | return assign_pb_; |
61 | 259k | } |
62 | | |
63 | | const std::string& attr_name() const; |
64 | | |
65 | | int attr_num() const; |
66 | | |
67 | | int id() const; |
68 | | |
69 | | InternalType internal_type() const; |
70 | | |
71 | 39.6M | bool read_requested() const { |
72 | 39.6M | return read_requested_; |
73 | 39.6M | } |
74 | | |
75 | 7.05M | void set_read_requested(const bool value) { |
76 | 7.05M | read_requested_ = value; |
77 | 7.05M | } |
78 | | |
79 | 25.5M | bool write_requested() const { |
80 | 25.5M | return write_requested_; |
81 | 25.5M | } |
82 | | |
83 | 259k | void set_write_requested(const bool value) { |
84 | 259k | write_requested_ = value; |
85 | 259k | } |
86 | | |
87 | | bool is_partition() const; |
88 | | bool is_primary() const; |
89 | | bool is_virtual_column() const; |
90 | | |
91 | 3.93k | void set_pg_type_info(int typid, int typmod, int collid) { |
92 | 3.93k | pg_typid_ = typid; |
93 | 3.93k | pg_typmod_ = typmod; |
94 | 3.93k | pg_collid_ = collid; |
95 | 3.93k | } |
96 | | |
97 | 7.31M | bool has_pg_type_info() const { |
98 | 7.31M | return pg_typid_ != 0; |
99 | 7.31M | } |
100 | | |
101 | 3.93k | int pg_typid() const { |
102 | 3.93k | return pg_typid_; |
103 | 3.93k | } |
104 | | |
105 | 3.93k | int pg_typmod() const { |
106 | 3.93k | return pg_typmod_; |
107 | 3.93k | } |
108 | | |
109 | 3.93k | int pg_collid() const { |
110 | 3.93k | return pg_collid_; |
111 | 3.93k | } |
112 | | |
113 | | private: |
114 | | const Schema& schema_; |
115 | | const size_t index_; |
116 | | |
117 | | // Protobuf code. |
118 | | // Input binds. For now these are just literal values of the columns. |
119 | | // - In DocDB API, for primary columns, their associated values in protobuf expression list must |
120 | | // strictly follow the order that was specified by CREATE TABLE statement while Postgres DML |
121 | | // statements will not follow this order. Therefore, we reserve the spaces in protobuf |
122 | | // structures for associated expressions of the primary columns in the specified order. |
123 | | // - During DML execution, the reserved expression spaces will be filled with actual values. |
124 | | // - The data-member "primary_exprs" is to map column id with the reserved expression spaces. |
125 | | PgsqlExpressionPB *bind_pb_ = nullptr; |
126 | | PgsqlExpressionPB *bind_condition_expr_pb_ = nullptr; |
127 | | |
128 | | // Protobuf for new-values of a column in the tuple. |
129 | | PgsqlExpressionPB *assign_pb_ = nullptr; |
130 | | |
131 | | // Wether or not this column must be read from DB for the SQL request. |
132 | | bool read_requested_ = false; |
133 | | |
134 | | // Wether or not this column will be written for the request. |
135 | | bool write_requested_ = false; |
136 | | |
137 | | int pg_typid_ = 0; |
138 | | |
139 | | int pg_typmod_ = -1; |
140 | | |
141 | | int pg_collid_ = 0; |
142 | | }; |
143 | | |
144 | | } // namespace pggate |
145 | | } // namespace yb |
146 | | |
147 | | #endif // YB_YQL_PGGATE_PG_COLUMN_H_ |