YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/yql/pggate/test/pggate_testapi.cc
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
16
#include "yb/yql/pggate/test/pggate_test.h"
17
#include "yb/yql/pggate/ybc_pggate.h"
18
19
namespace yb {
20
namespace pggate {
21
22
static const YBCPgTypeAttrs kYBCTestTypeAttrs = { 0 };
23
24
YBCStatus YBCTestCreateTableAddColumn(YBCPgStatement handle, const char *attr_name, int attr_num,
25
0
                                      DataType yb_type, bool is_hash, bool is_range) {
26
0
  int pg_type = 0;
27
0
  switch (yb_type) {
28
0
  case DataType::BOOL:
29
0
    pg_type = BOOLOID;
30
0
    break;
31
0
  case DataType::INT8:
32
0
    pg_type = CHAROID;
33
0
    break;
34
0
  case DataType::INT16:
35
0
    pg_type = INT2OID;
36
0
    break;
37
0
  case DataType::INT32:
38
0
    pg_type = INT4OID;
39
0
    break;
40
0
  case DataType::INT64:
41
0
    pg_type = INT8OID;
42
0
    break;
43
0
  case DataType::FLOAT:
44
0
    pg_type = FLOAT4OID;
45
0
    break;
46
0
  case DataType::DOUBLE:
47
0
    pg_type = FLOAT8OID;
48
0
    break;
49
0
  case DataType::STRING:
50
0
    pg_type = TEXTOID;
51
0
    break;
52
0
  default:
53
0
    break;
54
0
  }
55
0
  return YBCPgCreateTableAddColumn(handle, attr_name, attr_num, YBCPgFindTypeEntity(pg_type),
56
0
      is_hash, is_range, false /* is_desc */, false /* is_nulls_first */);
57
0
}
58
59
//--------------------------------------------------------------------------------------------------
60
61
YBCStatus YBCTestNewColumnRef(YBCPgStatement stmt, int attr_num, DataType yb_type,
62
0
                              YBCPgExpr *expr_handle) {
63
0
  int pg_type = 0;
64
0
  switch (yb_type) {
65
0
  case DataType::BOOL:
66
0
    pg_type = BOOLOID;
67
0
    break;
68
0
  case DataType::INT8:
69
0
    pg_type = CHAROID;
70
0
    break;
71
0
  case DataType::INT16:
72
0
    pg_type = INT2OID;
73
0
    break;
74
0
  case DataType::INT32:
75
0
    pg_type = INT4OID;
76
0
    break;
77
0
  case DataType::INT64:
78
0
    pg_type = INT8OID;
79
0
    break;
80
0
  case DataType::FLOAT:
81
0
    pg_type = FLOAT4OID;
82
0
    break;
83
0
  case DataType::DOUBLE:
84
0
    pg_type = FLOAT8OID;
85
0
    break;
86
0
  case DataType::STRING:
87
0
    pg_type = TEXTOID;
88
0
    break;
89
0
  default:
90
0
    break;
91
0
  }
92
0
  return YBCPgNewColumnRef(stmt, attr_num, YBCPgFindTypeEntity(pg_type),
93
0
                           false /* collate_is_valid_non_c */,
94
0
                           &kYBCTestTypeAttrs, expr_handle);
95
0
}
96
97
//--------------------------------------------------------------------------------------------------
98
99
YBCStatus YBCTestNewConstantBool(YBCPgStatement stmt, bool value, bool is_null,
100
0
                                 YBCPgExpr *expr_handle) {
101
0
  const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(BOOLOID);
102
0
  Datum datum = type_entity->yb_to_datum(&value, 0, nullptr);
103
0
  return YBCPgNewConstant(stmt, type_entity, false, nullptr, datum, is_null, expr_handle);
104
0
}
105
106
YBCStatus YBCTestNewConstantInt1(YBCPgStatement stmt, int8_t value, bool is_null,
107
0
                                 YBCPgExpr *expr_handle) {
108
0
  const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(CHAROID);
109
0
  Datum datum = type_entity->yb_to_datum(&value, 0, nullptr);
110
0
  return YBCPgNewConstant(stmt, type_entity, false, nullptr, datum, is_null, expr_handle);
111
0
}
112
113
YBCStatus YBCTestNewConstantInt2(YBCPgStatement stmt, int16_t value, bool is_null,
114
0
                                 YBCPgExpr *expr_handle) {
115
0
  const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(INT2OID);
116
0
  Datum datum = type_entity->yb_to_datum(&value, 0, nullptr);
117
0
  return YBCPgNewConstant(stmt, type_entity, false, nullptr, datum, is_null, expr_handle);
118
0
}
119
120
YBCStatus YBCTestNewConstantInt4(YBCPgStatement stmt, int32_t value, bool is_null,
121
0
                                 YBCPgExpr *expr_handle) {
122
0
  const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(INT4OID);
123
0
  Datum datum = type_entity->yb_to_datum(&value, 0, nullptr);
124
0
  return YBCPgNewConstant(stmt, type_entity, false, nullptr, datum, is_null, expr_handle);
125
0
}
126
127
YBCStatus YBCTestNewConstantInt8(YBCPgStatement stmt, int64_t value, bool is_null,
128
0
                                 YBCPgExpr *expr_handle) {
129
0
  const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(INT8OID);
130
0
  Datum datum = type_entity->yb_to_datum(&value, 0, nullptr);
131
0
  return YBCPgNewConstant(stmt, type_entity, false, nullptr, datum, is_null, expr_handle);
132
0
}
133
134
YBCStatus YBCTestNewConstantInt8Op(YBCPgStatement stmt, int64_t value, bool is_null,
135
0
                                 YBCPgExpr *expr_handle, bool is_gt) {
136
0
  const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(INT8OID);
137
0
  Datum datum = type_entity->yb_to_datum(&value, 0, nullptr);
138
0
  return YBCPgNewConstantOp(stmt, type_entity, false, nullptr, datum, is_null, expr_handle, is_gt);
139
0
}
140
141
YBCStatus YBCTestNewConstantFloat4(YBCPgStatement stmt, float value, bool is_null,
142
0
                                   YBCPgExpr *expr_handle) {
143
0
  const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(FLOAT4OID);
144
0
  Datum datum = type_entity->yb_to_datum(&value, 0, nullptr);
145
0
  return YBCPgNewConstant(stmt, type_entity, false, nullptr, datum, is_null, expr_handle);
146
0
}
147
148
YBCStatus YBCTestNewConstantFloat8(YBCPgStatement stmt, double value, bool is_null,
149
0
                                   YBCPgExpr *expr_handle) {
150
0
  const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(FLOAT8OID);
151
0
  Datum datum = type_entity->yb_to_datum(&value, 0, nullptr);
152
0
  return YBCPgNewConstant(stmt, type_entity, false, nullptr, datum, is_null, expr_handle);
153
0
}
154
155
YBCStatus YBCTestNewConstantText(YBCPgStatement stmt, const char *value, bool is_null,
156
0
                                 YBCPgExpr *expr_handle) {
157
0
  const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(TEXTOID);
158
0
  Datum datum = type_entity->yb_to_datum(value, strlen(value), &kYBCTestTypeAttrs);
159
0
  return YBCPgNewConstant(stmt, type_entity, false, nullptr, datum, is_null, expr_handle);
160
0
}
161
162
} // namespace pggate
163
} // namespace yb