YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/docdb/docdb_pgapi.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
// This file contains the C++ API for the PG/YSQL backend library to be used by DocDB.
16
// Analogous to YCQL this should be used for write expressions (e.g. SET clause), filtering
17
// (e.g. WHERE clause), expression projections (e.g. SELECT targets) etc.
18
// Currently it just supports evaluating an YSQL expressions into a QLValues and is only used
19
// for the UPDATE .. SET clause.
20
//
21
// The implementation for these should typically call (and/or extend) either the PG/YSQL C API
22
// from pgapi.h or  directly the pggate C++ API.
23
24
#ifndef YB_DOCDB_DOCDB_PGAPI_H_
25
#define YB_DOCDB_DOCDB_PGAPI_H_
26
27
#include <map>
28
#include <vector>
29
30
#include "yb/common/column_id.h"
31
#include "yb/common/common_fwd.h"
32
33
#include "yb/util/status_fwd.h"
34
#include "yb/util/decimal.h"
35
36
#include "ybgate/ybgate_api.h"
37
38
namespace yb {
39
namespace docdb {
40
41
//-----------------------------------------------------------------------------
42
// Types
43
//-----------------------------------------------------------------------------
44
45
struct DocPgParamDesc {
46
    int32_t attno;
47
    int32_t typid;
48
    int32_t typmod;
49
50
    DocPgParamDesc(int32_t attno, int32_t typid, int32_t typmod)
51
        : attno(attno), typid(typid), typmod(typmod)
52
0
    {}
53
};
54
55
struct DocPgVarRef {
56
  ColumnIdRep var_colid;
57
  const YBCPgTypeEntity *var_type;
58
  YBCPgTypeAttrs var_type_attrs;
59
5.74k
  DocPgVarRef() {}
60
61
  DocPgVarRef(ColumnIdRep var_colid, const YBCPgTypeEntity *var_type, int32_t var_typmod)
62
    : var_colid(var_colid), var_type(var_type), var_type_attrs({var_typmod})
63
10.0k
  {}
64
};
65
66
const YBCPgTypeEntity* DocPgGetTypeEntity(YbgTypeDesc pg_type);
67
68
//-----------------------------------------------------------------------------
69
// Expressions/Values
70
//-----------------------------------------------------------------------------
71
72
Status DocPgPrepareExpr(const std::string& expr_str,
73
                        YbgPreparedExpr *expr,
74
                        DocPgVarRef *ret_type);
75
76
Status DocPgAddVarRef(const ColumnId& column_id,
77
                      int32_t attno,
78
                      int32_t typid,
79
                      int32_t typmod,
80
                      int32_t collid,
81
                      std::map<int, const DocPgVarRef> *var_map);
82
83
Status DocPgCreateExprCtx(const std::map<int, const DocPgVarRef>& var_map,
84
                          YbgExprContext *expr_ctx);
85
86
Status DocPgPrepareExprCtx(const QLTableRow& table_row,
87
                           const std::map<int, const DocPgVarRef>& var_map,
88
                           YbgExprContext expr_ctx);
89
90
Status DocPgEvalExpr(YbgPreparedExpr expr,
91
                     YbgExprContext expr_ctx,
92
                     uint64_t *datum,
93
                     bool *is_null);
94
95
// Given a 'ql_value' with a binary value, interpret the binary value as a text
96
// array, and store the individual elements in 'ql_value_vec';
97
Status ExtractTextArrayFromQLBinaryValue(const QLValuePB& ql_value,
98
                                         std::vector<QLValuePB> *const ql_value_vec);
99
100
// Given a 'ql_value', interpret the binary value in it as an array of type
101
// 'array_type' with elements of type 'elem_type' and store the individual
102
// elements in 'result'. Here, 'array_type' and 'elem_type' are PG typoids
103
// corresponding to the required array and element types.
104
Status ExtractVectorFromQLBinaryValueHelper(const QLValuePB& ql_value,
105
                                            const int array_type,
106
                                            const int elem_type,
107
                                            std::vector<QLValuePB> *result);
108
109
Status SetValueFromQLBinary(const QLValuePB ql_value,
110
                            const int pg_data_type,
111
                            DatumMessagePB* cdc_datum_message = NULL);
112
113
Status SetValueFromQLBinaryHelper(const QLValuePB ql_value,
114
                                  const int elem_type,
115
                                  DatumMessagePB* cdc_datum_message = NULL);
116
117
} // namespace docdb
118
} // namespace yb
119
120
#endif // YB_DOCDB_DOCDB_PGAPI_H_