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_testvars.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
#include "yb/yql/pggate/test/pggate_test.h"
16
17
namespace yb {
18
namespace pggate {
19
20
/***************************************************************************************************
21
 * Conversion Functions.
22
 **************************************************************************************************/
23
/*
24
 * BOOL conversion.
25
 * Ignore the "bytes" data size.
26
 */
27
0
void YBCTestDatumToBool(Datum datum, void *void_data, int64 *bytes) {
28
0
  bool *data = reinterpret_cast<bool*>(void_data);
29
0
  *data = static_cast<bool>((datum & 0x000000ff) != 0);
30
0
}
31
32
0
Datum YBCTestBoolToDatum(const void *void_data, int64 bytes, const YBCPgTypeAttrs *type_attrs) {
33
0
  const bool *data = reinterpret_cast<const bool*>(void_data);
34
0
  return (static_cast<Datum>(*data)) & 0x000000ff;
35
0
}
36
37
/*
38
 * CHAR conversion.
39
 * Ignore the "bytes" data size.
40
 */
41
0
void YBCTestDatumToChar(Datum datum, void *void_data, int64 *bytes) {
42
0
  char *data = reinterpret_cast<char*>(void_data);
43
0
  *data = static_cast<char>(datum & 0x000000ff);
44
0
}
45
46
0
Datum YBCTestCharToDatum(const void *void_data, int64 bytes, const YBCPgTypeAttrs *type_attrs) {
47
0
  const char *data = reinterpret_cast<const char*>(void_data);
48
0
  return (static_cast<Datum>(*data)) & 0x000000ff;
49
0
}
50
51
/*
52
 * TEXT conversion.
53
 */
54
0
void YBCTestDatumToStr(Datum datum, void *void_data, int64 *bytes) {
55
0
  char **data = reinterpret_cast<char**>(void_data);
56
0
  *data = reinterpret_cast<char*>(datum);
57
0
  *bytes = strlen(*data);
58
0
}
59
60
0
Datum YBCTestStrToDatum(const void *void_data, int64 bytes, const YBCPgTypeAttrs *type_attrs) {
61
0
  int64 len = type_attrs->typmod > 0 ? type_attrs->typmod : bytes + 1;
62
0
  char *str = static_cast<char *>(PggateTestAlloc(len));
63
64
0
  const char *data = reinterpret_cast<const char*>(void_data);
65
0
  strncpy(str, data, len - 1);
66
0
  str[len - 1] = 0;
67
0
  return reinterpret_cast<uint64_t>(str);
68
0
}
69
70
/*
71
 * INTEGERs conversion.
72
 */
73
0
void YBCTestDatumToInt16(Datum datum, void *void_data, int64 *bytes) {
74
0
  int16* data = reinterpret_cast<int16*>(void_data);
75
0
  *data = static_cast<int16>(datum & 0x0000ffff);
76
0
}
77
78
0
Datum YBCTestInt16ToDatum(const void *void_data, int64 bytes, const YBCPgTypeAttrs *type_attrs) {
79
0
  const int16* data = reinterpret_cast<const int16*>(void_data);
80
0
  return (static_cast<Datum>(*data)) & 0x0000ffff;
81
0
}
82
83
0
void YBCTestDatumToInt32(Datum datum, void *void_data, int64 *bytes) {
84
0
  int32 *data = reinterpret_cast<int32*>(void_data);
85
0
  *data = static_cast<int32>(datum & 0xffffffff);
86
0
}
87
88
0
Datum YBCTestInt32ToDatum(const void *void_data, int64 bytes, const YBCPgTypeAttrs *type_attrs) {
89
0
  const int32 *data = reinterpret_cast<const int32*>(void_data);
90
0
  return (static_cast<Datum>(*data)) & 0xffffffff;
91
0
}
92
93
0
void YBCTestDatumToInt64(Datum datum, void *void_data, int64 *bytes) {
94
0
  int64 *data = reinterpret_cast<int64*>(void_data);
95
0
  *data = static_cast<int64>(datum);
96
0
}
97
98
0
Datum YBCTestInt64ToDatum(const void *void_data, int64 bytes, const YBCPgTypeAttrs *type_attrs) {
99
0
  const int64 *data = reinterpret_cast<const int64*>(void_data);
100
0
  return *reinterpret_cast<const Datum*>(data);
101
0
}
102
103
/*
104
 * FLOATs conversion.
105
 */
106
0
void YBCTestDatumToFloat4(Datum datum, void *void_data, int64 *bytes) {
107
0
  float *data = reinterpret_cast<float*>(void_data);
108
0
  *data = *reinterpret_cast<float *>(&datum);
109
0
}
110
111
0
Datum YBCTestFloat4ToDatum(const void *void_data, int64 bytes, const YBCPgTypeAttrs *type_attrs) {
112
0
  return YBCTestInt32ToDatum(void_data, 0, nullptr);
113
0
}
114
115
0
void YBCTestDatumToFloat8(Datum datum, void *void_data, int64 *bytes) {
116
0
  double *data = reinterpret_cast<double*>(void_data);
117
0
  *data = *reinterpret_cast<double*>(&datum);
118
0
}
119
120
0
Datum YBCTestFloat8ToDatum(const void *void_data, int64 bytes, const YBCPgTypeAttrs *type_attrs) {
121
0
  return YBCTestInt64ToDatum(void_data, 0, nullptr);
122
0
}
123
124
/***************************************************************************************************
125
 * Conversion Table
126
 **************************************************************************************************/
127
static const YBCPgTypeEntity YBCTestTypeEntityTable[] = {
128
  { BOOLOID, YB_YQL_DATA_TYPE_BOOL, true, 1,
129
    (YBCPgDatumToData)YBCTestDatumToBool,
130
    (YBCPgDatumFromData)YBCTestBoolToDatum },
131
132
  { INT2OID, YB_YQL_DATA_TYPE_INT16, true, 2,
133
    (YBCPgDatumToData)YBCTestDatumToInt16,
134
    (YBCPgDatumFromData)YBCTestInt16ToDatum },
135
136
  { INT4OID, YB_YQL_DATA_TYPE_INT32, true, 4,
137
    (YBCPgDatumToData)YBCTestDatumToInt32,
138
    (YBCPgDatumFromData)YBCTestInt32ToDatum },
139
140
  { INT8OID, YB_YQL_DATA_TYPE_INT64, true, 8,
141
    (YBCPgDatumToData)YBCTestDatumToInt64,
142
    (YBCPgDatumFromData)YBCTestInt64ToDatum },
143
144
  { TEXTOID, YB_YQL_DATA_TYPE_STRING, true, -1,
145
    (YBCPgDatumToData)YBCTestDatumToStr,
146
    (YBCPgDatumFromData)YBCTestStrToDatum },
147
148
  { OIDOID, YB_YQL_DATA_TYPE_INT32, true, 4,
149
    (YBCPgDatumToData)YBCTestDatumToInt32,
150
    (YBCPgDatumFromData)YBCTestInt32ToDatum },
151
152
  { FLOAT4OID, YB_YQL_DATA_TYPE_FLOAT, true, 8,
153
    (YBCPgDatumToData)YBCTestDatumToFloat4,
154
    (YBCPgDatumFromData)YBCTestFloat4ToDatum },
155
156
  { FLOAT8OID, YB_YQL_DATA_TYPE_DOUBLE, true, 8,
157
    (YBCPgDatumToData)YBCTestDatumToFloat8,
158
    (YBCPgDatumFromData)YBCTestFloat8ToDatum },
159
};
160
161
0
void YBCTestGetTypeTable(const YBCPgTypeEntity **type_table, int *count) {
162
0
  *type_table = YBCTestTypeEntityTable;
163
0
  *count = sizeof(YBCTestTypeEntityTable)/sizeof(YBCPgTypeEntity);
164
0
}
165
166
} // namespace pggate
167
} // namespace yb