/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 | 36 | DataType yb_type, bool is_hash, bool is_range) { |
26 | 36 | int pg_type = 0; |
27 | 36 | 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 | 5 | case DataType::INT16: |
35 | 5 | pg_type = INT2OID; |
36 | 5 | break; |
37 | 13 | case DataType::INT32: |
38 | 13 | pg_type = INT4OID; |
39 | 13 | break; |
40 | 6 | case DataType::INT64: |
41 | 6 | pg_type = INT8OID; |
42 | 6 | break; |
43 | 5 | case DataType::FLOAT: |
44 | 5 | pg_type = FLOAT4OID; |
45 | 5 | break; |
46 | 0 | case DataType::DOUBLE: |
47 | 0 | pg_type = FLOAT8OID; |
48 | 0 | break; |
49 | 7 | case DataType::STRING: |
50 | 7 | pg_type = TEXTOID; |
51 | 7 | break; |
52 | 0 | default: |
53 | 0 | break; |
54 | 36 | } |
55 | 36 | return YBCPgCreateTableAddColumn(handle, attr_name, attr_num, YBCPgFindTypeEntity(pg_type), |
56 | 36 | is_hash, is_range, false /* is_desc */, false /* is_nulls_first */); |
57 | 36 | } |
58 | | |
59 | | //-------------------------------------------------------------------------------------------------- |
60 | | |
61 | | YBCStatus YBCTestNewColumnRef(YBCPgStatement stmt, int attr_num, DataType yb_type, |
62 | 76 | YBCPgExpr *expr_handle) { |
63 | 76 | int pg_type = 0; |
64 | 76 | 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 | 10 | case DataType::INT16: |
72 | 10 | pg_type = INT2OID; |
73 | 10 | break; |
74 | 24 | case DataType::INT32: |
75 | 24 | pg_type = INT4OID; |
76 | 24 | break; |
77 | 14 | case DataType::INT64: |
78 | 14 | pg_type = INT8OID; |
79 | 14 | break; |
80 | 10 | case DataType::FLOAT: |
81 | 10 | pg_type = FLOAT4OID; |
82 | 10 | break; |
83 | 0 | case DataType::DOUBLE: |
84 | 0 | pg_type = FLOAT8OID; |
85 | 0 | break; |
86 | 18 | case DataType::STRING: |
87 | 18 | pg_type = TEXTOID; |
88 | 18 | break; |
89 | 0 | default: |
90 | 0 | break; |
91 | 76 | } |
92 | 76 | return YBCPgNewColumnRef(stmt, attr_num, YBCPgFindTypeEntity(pg_type), |
93 | 76 | false /* collate_is_valid_non_c */, |
94 | 76 | &kYBCTestTypeAttrs, expr_handle); |
95 | 76 | } |
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 | 7 | YBCPgExpr *expr_handle) { |
115 | 7 | const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(INT2OID); |
116 | 7 | Datum datum = type_entity->yb_to_datum(&value, 0, nullptr); |
117 | 7 | return YBCPgNewConstant(stmt, type_entity, false, nullptr, datum, is_null, expr_handle); |
118 | 7 | } |
119 | | |
120 | | YBCStatus YBCTestNewConstantInt4(YBCPgStatement stmt, int32_t value, bool is_null, |
121 | 21 | YBCPgExpr *expr_handle) { |
122 | 21 | const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(INT4OID); |
123 | 21 | Datum datum = type_entity->yb_to_datum(&value, 0, nullptr); |
124 | 21 | return YBCPgNewConstant(stmt, type_entity, false, nullptr, datum, is_null, expr_handle); |
125 | 21 | } |
126 | | |
127 | | YBCStatus YBCTestNewConstantInt8(YBCPgStatement stmt, int64_t value, bool is_null, |
128 | 13 | YBCPgExpr *expr_handle) { |
129 | 13 | const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(INT8OID); |
130 | 13 | Datum datum = type_entity->yb_to_datum(&value, 0, nullptr); |
131 | 13 | return YBCPgNewConstant(stmt, type_entity, false, nullptr, datum, is_null, expr_handle); |
132 | 13 | } |
133 | | |
134 | | YBCStatus YBCTestNewConstantInt8Op(YBCPgStatement stmt, int64_t value, bool is_null, |
135 | 6 | YBCPgExpr *expr_handle, bool is_gt) { |
136 | 6 | const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(INT8OID); |
137 | 6 | Datum datum = type_entity->yb_to_datum(&value, 0, nullptr); |
138 | 6 | return YBCPgNewConstantOp(stmt, type_entity, false, nullptr, datum, is_null, expr_handle, is_gt); |
139 | 6 | } |
140 | | |
141 | | YBCStatus YBCTestNewConstantFloat4(YBCPgStatement stmt, float value, bool is_null, |
142 | 7 | YBCPgExpr *expr_handle) { |
143 | 7 | const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(FLOAT4OID); |
144 | 7 | Datum datum = type_entity->yb_to_datum(&value, 0, nullptr); |
145 | 7 | return YBCPgNewConstant(stmt, type_entity, false, nullptr, datum, is_null, expr_handle); |
146 | 7 | } |
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 | 13 | YBCPgExpr *expr_handle) { |
157 | 13 | const YBCPgTypeEntity *type_entity = YBCPgFindTypeEntity(TEXTOID); |
158 | 13 | Datum datum = type_entity->yb_to_datum(value, strlen(value), &kYBCTestTypeAttrs); |
159 | 13 | return YBCPgNewConstant(stmt, type_entity, false, nullptr, datum, is_null, expr_handle); |
160 | 13 | } |
161 | | |
162 | | } // namespace pggate |
163 | | } // namespace yb |