YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/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
34.5M
  PgsqlExpressionPB *bind_pb() {
56
34.5M
    return bind_pb_;
57
34.5M
  }
58
59
983k
  PgsqlExpressionPB *assign_pb() {
60
983k
    return assign_pb_;
61
983k
  }
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
128M
  bool read_requested() const {
72
128M
    return read_requested_;
73
128M
  }
74
75
20.9M
  void set_read_requested(const bool value) {
76
20.9M
    read_requested_ = value;
77
20.9M
  }
78
79
86.6M
  bool write_requested() const {
80
86.6M
    return write_requested_;
81
86.6M
  }
82
83
983k
  void set_write_requested(const bool value) {
84
983k
    write_requested_ = value;
85
983k
  }
86
87
  bool is_partition() const;
88
  bool is_primary() const;
89
  bool is_virtual_column() const;
90
91
11.9k
  void set_pg_type_info(int typid, int typmod, int collid) {
92
11.9k
    pg_typid_ = typid;
93
11.9k
    pg_typmod_ = typmod;
94
11.9k
    pg_collid_ = collid;
95
11.9k
  }
96
97
21.9M
  bool has_pg_type_info() const {
98
21.9M
    return pg_typid_ != 0;
99
21.9M
  }
100
101
11.9k
  int pg_typid() const {
102
11.9k
    return pg_typid_;
103
11.9k
  }
104
105
11.9k
  int pg_typmod() const {
106
11.9k
    return pg_typmod_;
107
11.9k
  }
108
109
11.9k
  int pg_collid() const {
110
11.9k
    return pg_collid_;
111
11.9k
  }
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_