YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/docdb/docdb_pgapi.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/docdb/docdb_pgapi.h"
16
17
#include "yb/common/ql_expr.h"
18
#include "yb/common/schema.h"
19
20
#include "yb/gutil/singleton.h"
21
#include "yb/yql/pggate/ybc_pg_typedefs.h"
22
#include "yb/yql/pggate/pg_value.h"
23
#include "yb/yql/pggate/pg_expr.h"
24
#include "yb/yql/pggate/ybc_pggate.h"
25
26
27
#include "yb/util/result.h"
28
29
// This file comes from this directory:
30
// postgres_build/src/include/catalog
31
// added as a special include path to CMakeLists.txt
32
#include "pg_type_d.h" // NOLINT
33
34
using yb::pggate::PgValueFromPB;
35
using yb::pggate::PgValueToPB;
36
37
namespace yb {
38
namespace docdb {
39
40
#define PG_RETURN_NOT_OK(status) \
41
428k
  do { \
42
428k
    if (status.err_code != 0) { \
43
0
      std::string msg; \
44
0
      if (status.err_msg != nullptr) { \
45
0
        msg = std::string(status.err_msg); \
46
0
      } else { \
47
0
        msg = std::string("Unexpected error while evaluating expression"); \
48
0
      } \
49
0
      YbgResetMemoryContext(); \
50
0
      return STATUS(QLError, msg); \
51
0
    } \
52
428k
  } while(0);
53
54
#define SET_ELEM_LEN_BYVAL_ALIGN(elemlen, elembyval, elemalign) \
55
204
  do { \
56
204
    elmlen = elemlen; \
57
204
    elmbyval = elembyval; \
58
204
    elmalign = elemalign; \
59
204
  } while (0);
60
61
#define SET_ELEM_LEN_BYVAL_ALIGN_OPT(elemlen, elembyval, elemalign, opt) \
62
12
  do { \
63
12
    elmlen = elemlen; \
64
12
    elmbyval = elembyval; \
65
12
    elmalign = elemalign; \
66
12
    option = opt; \
67
12
  } while (0);
68
69
#define SET_RANGE_ELEM_LEN_BYVAL_ALIGN(elemlen, elembyval, elemalign, \
70
                                       range_elemlen, range_elembyval, range_elemalign) \
71
36
  do { \
72
36
    elmlen = elemlen; \
73
36
    elmbyval = elembyval; \
74
36
    elmalign = elemalign; \
75
36
    range_elmlen = range_elemlen; \
76
36
    range_elmbyval = range_elembyval; \
77
36
    range_elmalign = range_elemalign; \
78
36
  } while (0);
79
80
//-----------------------------------------------------------------------------
81
// Types
82
//-----------------------------------------------------------------------------
83
84
class DocPgTypeAnalyzer {
85
 public:
86
108k
  const YBCPgTypeEntity* GetTypeEntity(int32_t type_oid) {
87
108k
    const auto iter = type_map_.find(type_oid);
88
108k
    if (iter != type_map_.end()) {
89
108k
      return iter->second;
90
108k
    }
91
1
    LOG(FATAL) << "Could not find type entity for oid " << type_oid;
92
1
    return nullptr;
93
108k
  }
94
95
 private:
96
743
  DocPgTypeAnalyzer() {
97
    // Setup type mapping.
98
743
    const YBCPgTypeEntity *type_table;
99
743
    int count;
100
101
743
    YbgGetTypeTable(&type_table, &count);
102
121k
    for (int idx = 0; idx < count; 
idx++120k
) {
103
120k
        const YBCPgTypeEntity *type_entity = &type_table[idx];
104
120k
        type_map_[type_entity->type_oid] = type_entity;
105
120k
    }
106
743
  }
107
108
  // Mapping table of YugaByte and PostgreSQL datatypes.
109
  std::unordered_map<int, const YBCPgTypeEntity *> type_map_;
110
111
  friend class Singleton<DocPgTypeAnalyzer>;
112
  DISALLOW_COPY_AND_ASSIGN(DocPgTypeAnalyzer);
113
};
114
115
//-----------------------------------------------------------------------------
116
// Expressions/Values
117
//-----------------------------------------------------------------------------
118
119
108k
const YBCPgTypeEntity* DocPgGetTypeEntity(YbgTypeDesc pg_type) {
120
108k
    return Singleton<DocPgTypeAnalyzer>::get()->GetTypeEntity(pg_type.type_id);
121
108k
}
122
123
Status DocPgAddVarRef(const ColumnId& column_id,
124
                      int32_t attno,
125
                      int32_t typid,
126
                      int32_t typmod,
127
                      int32_t collid,
128
12.2k
                      std::map<int, const DocPgVarRef> *var_map) {
129
12.2k
  if (var_map->find(attno) != var_map->end()) {
130
0
    VLOG(1) << "Attribute " << attno << " is already processed";
131
0
    return Status::OK();
132
0
  }
133
12.2k
  const YBCPgTypeEntity *arg_type = DocPgGetTypeEntity({typid, typmod});
134
12.2k
  var_map->emplace(std::piecewise_construct,
135
12.2k
                   std::forward_as_tuple(attno),
136
12.2k
                   std::forward_as_tuple(column_id.rep(), arg_type, typmod));
137
12.2k
  VLOG
(1) << "Attribute " << attno << " has been processed"0
;
138
12.2k
  return Status::OK();
139
12.2k
}
140
141
Status DocPgPrepareExpr(const std::string& expr_str,
142
                        YbgPreparedExpr *expr,
143
17.1k
                        DocPgVarRef *ret_type) {
144
17.1k
  char *expr_cstring = const_cast<char *>(expr_str.c_str());
145
18.4E
  VLOG(1) << "Deserialize " << expr_cstring;
146
17.1k
  PG_RETURN_NOT_OK(YbgPrepareExpr(expr_cstring, expr));
147
17.1k
  if (ret_type != nullptr) {
148
16.7k
    int32_t typid;
149
16.7k
    int32_t typmod;
150
16.7k
    PG_RETURN_NOT_OK(YbgExprType(*expr, &typid));
151
16.7k
    PG_RETURN_NOT_OK(YbgExprTypmod(*expr, &typmod));
152
16.7k
    YbgTypeDesc pg_arg_type = {typid, typmod};
153
16.7k
    const YBCPgTypeEntity *arg_type = DocPgGetTypeEntity(pg_arg_type);
154
16.7k
    *ret_type = DocPgVarRef(0, arg_type, typmod);
155
16.7k
    VLOG
(1) << "Processed expression return type"0
;
156
16.7k
  }
157
17.1k
  return Status::OK();
158
17.1k
}
159
160
Status DocPgCreateExprCtx(const std::map<int, const DocPgVarRef>& var_map,
161
12.2k
                          YbgExprContext *expr_ctx) {
162
12.2k
  if (var_map.empty()) {
163
0
    return Status::OK();
164
0
  }
165
166
12.2k
  int32_t min_attno = var_map.begin()->first;
167
12.2k
  int32_t max_attno = var_map.rbegin()->first;
168
169
12.2k
  VLOG
(2) << "Allocating expr context: (" << min_attno << ", " << max_attno << ")"4
;
170
12.2k
  PG_RETURN_NOT_OK(YbgExprContextCreate(min_attno, max_attno, expr_ctx));
171
12.2k
  return Status::OK();
172
12.2k
}
173
174
Status DocPgPrepareExprCtx(const QLTableRow& table_row,
175
                           const std::map<int, const DocPgVarRef>& var_map,
176
67.0k
                           YbgExprContext expr_ctx) {
177
67.0k
  PG_RETURN_NOT_OK(YbgExprContextReset(expr_ctx));
178
  // Set the column values (used to resolve scan variables in the expression).
179
134k
  for (auto it = var_map.begin(); it != var_map.end(); 
it++67.3k
) {
180
67.3k
    const int& attno = it->first;
181
67.3k
    const DocPgVarRef& arg_ref = it->second;
182
67.3k
    const QLValuePB* val = table_row.GetColumn(arg_ref.var_colid);
183
67.3k
    bool is_null = false;
184
67.3k
    uint64_t datum = 0;
185
67.3k
    RETURN_NOT_OK(PgValueFromPB(arg_ref.var_type, arg_ref.var_type_attrs, *val, &datum, &is_null));
186
67.3k
    VLOG
(1) << "Adding value for attno " << attno580
;
187
67.3k
    PG_RETURN_NOT_OK(YbgExprContextAddColValue(expr_ctx, attno, datum, is_null));
188
67.3k
  }
189
67.0k
  return Status::OK();
190
67.0k
}
191
192
Status DocPgEvalExpr(YbgPreparedExpr expr,
193
                     YbgExprContext expr_ctx,
194
                     uint64_t *datum,
195
73.7k
                     bool *is_null) {
196
  // Evaluate the expression and get the result.
197
73.7k
  PG_RETURN_NOT_OK(YbgEvalExpr(expr, expr_ctx, datum, is_null));
198
73.7k
  return Status::OK();
199
73.7k
}
200
201
Status SetValueFromQLBinary(const QLValuePB ql_value,
202
                            const int pg_data_type,
203
78.3k
                            DatumMessagePB* cdc_datum_message) {
204
78.3k
  PG_RETURN_NOT_OK(YbgPrepareMemoryContext());
205
206
78.3k
  RETURN_NOT_OK(SetValueFromQLBinaryHelper(
207
78.3k
    ql_value,
208
78.3k
    pg_data_type,
209
78.3k
    cdc_datum_message));
210
78.3k
  PG_RETURN_NOT_OK(YbgResetMemoryContext());
211
78.3k
  return Status::OK();
212
78.3k
}
213
214
Status ExtractTextArrayFromQLBinaryValue(const QLValuePB& ql_value,
215
422
                                         vector<QLValuePB> *const ql_value_vec) {
216
422
  PG_RETURN_NOT_OK(YbgPrepareMemoryContext());
217
218
422
  RETURN_NOT_OK(ExtractVectorFromQLBinaryValueHelper(
219
422
      ql_value,
220
422
      TEXTARRAYOID,
221
422
      TEXTOID,
222
422
      ql_value_vec));
223
422
  PG_RETURN_NOT_OK(YbgResetMemoryContext());
224
422
  return Status::OK();
225
422
}
226
227
void set_decoded_string_value(
228
    uint64_t datum,
229
    const char* func_name,
230
    DatumMessagePB* cdc_datum_message = nullptr,
231
212
    const char* timezone = nullptr) {
232
212
  char *decoded_str = nullptr;
233
234
212
  if (func_name == nullptr) {
235
0
    return;
236
0
  }
237
238
212
  if (timezone == nullptr)
239
206
    decoded_str = DecodeDatum(func_name, (uintptr_t)datum);
240
6
  else
241
6
    decoded_str = DecodeTZDatum(func_name, (uintptr_t)datum, timezone, true);
242
243
212
  cdc_datum_message->set_datum_string(decoded_str, strlen(decoded_str));
244
212
}
245
246
void set_decoded_string_range(
247
    const QLValuePB ql_value,
248
    const YBCPgTypeEntity* arg_type,
249
    const int elem_type,
250
    const char* func_name,
251
    DatumMessagePB* cdc_datum_message = nullptr,
252
30
    const char* timezone = nullptr) {
253
30
  YBCPgTypeAttrs type_attrs{-1 /* typmod */};
254
255
30
  char* decoded_str = nullptr;
256
30
  string range_val = ql_value.binary_value();
257
30
  uint64_t size = range_val.size();
258
30
  char* val = const_cast<char *>(range_val.c_str());
259
30
  uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
260
261
30
  int16 elmlen;
262
30
  bool elmbyval;
263
30
  char elmalign;
264
30
  bool from_YB = true;
265
30
  char option = '\0';
266
267
30
  switch (elem_type) {
268
6
    case INT4OID:
269
6
      SET_ELEM_LEN_BYVAL_ALIGN(sizeof(int32), true, 'i');
270
6
      break;
271
272
0
    case NUMERICOID:
273
0
      SET_ELEM_LEN_BYVAL_ALIGN(-1, false, 'i');
274
0
      break;
275
276
6
    case TIMESTAMPOID:
277
12
    case INT8OID:
278
12
      SET_ELEM_LEN_BYVAL_ALIGN(sizeof(int64), true, 'i');
279
12
      break;
280
281
6
    case TIMESTAMPTZOID:
282
6
      SET_ELEM_LEN_BYVAL_ALIGN_OPT(sizeof(int64), true, 'i', 't');
283
6
      break;
284
285
6
    case DATEOID:
286
6
      SET_ELEM_LEN_BYVAL_ALIGN(sizeof(int32), true, 'i');
287
6
      break;
288
289
0
    default:
290
0
      SET_ELEM_LEN_BYVAL_ALIGN(-1, false, 'i');
291
0
      break;
292
30
  }
293
294
30
  if (func_name != nullptr) {
295
30
    decoded_str = DecodeRangeDatum(
296
30
        "range_out", (uintptr_t)datum, elmlen, elmbyval, elmalign, option, from_YB, func_name,
297
30
        arg_type->type_oid, timezone);
298
299
30
    cdc_datum_message->set_datum_string(decoded_str, strlen(decoded_str));
300
30
  }
301
30
}
302
303
void set_decoded_string_array(const QLValuePB ql_value,
304
                              const YBCPgTypeEntity* arg_type,
305
                              const int elem_type,
306
                              const char* func_name,
307
                              DatumMessagePB* cdc_datum_message = nullptr,
308
186
                              const char* timezone = nullptr) {
309
186
  YBCPgTypeAttrs type_attrs{-1 /* typmod */};
310
311
186
  char* decoded_str = nullptr;
312
186
  string vector_val = ql_value.binary_value();
313
186
  uint64_t size = vector_val.size();
314
186
  char* val = const_cast<char *>(vector_val.c_str());
315
186
  uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
316
317
186
  int16 elmlen;
318
186
  bool elmbyval;
319
186
  char elmalign;
320
186
  char elmdelim = ',';
321
186
  bool from_YB = true;
322
186
  char option = '\0';
323
324
186
  switch (elem_type) {
325
6
    case TEXTOID:
326
6
    case XMLOID:
327
6
    case BYTEAOID:
328
6
    case INT2VECTOROID:
329
6
    case CHAROID:
330
6
    case REGPROCOID:
331
6
    case TIDOID:
332
12
    case CIDROID:
333
12
    case OIDVECTOROID:
334
18
    case BPCHAROID:
335
24
    case VARCHAROID:
336
30
    case PATHOID:
337
30
    case RELTIMEOID:
338
30
    case TINTERVALOID:
339
30
    case ACLITEMOID:
340
36
    case INETOID:
341
36
    case NUMERICOID:
342
36
    case BITOID:
343
42
    case VARBITOID:
344
42
    case REGPROCEDUREOID:
345
42
    case REGOPEROID:
346
42
    case REGOPERATOROID:
347
42
    case REGCLASSOID:
348
42
    case REGTYPEOID:
349
42
    case REGROLEOID:
350
42
    case REGNAMESPACEOID:
351
42
    case TSVECTOROID:
352
42
    case GTSVECTOROID:
353
42
    case TSQUERYOID:
354
42
    case REGCONFIGOID:
355
42
    case REGDICTIONARYOID:
356
48
    case JSONOID:
357
54
    case JSONBOID:
358
60
    case TXID_SNAPSHOTOID:
359
60
    case RECORDOID:
360
66
    case POLYGONOID:
361
66
      SET_ELEM_LEN_BYVAL_ALIGN(-1, false, 'i');
362
66
      break;
363
364
6
    case LINEOID:
365
12
    case CIRCLEOID:
366
12
      SET_ELEM_LEN_BYVAL_ALIGN(24, false, 'd');
367
12
      break;
368
369
6
    case CASHOID:
370
6
    case INT8OID:
371
12
    case TIMESTAMPOID:
372
18
    case TIMEOID:
373
18
      SET_ELEM_LEN_BYVAL_ALIGN(sizeof(int64), true, 'd');
374
18
      break;
375
376
6
    case BOOLOID:
377
6
      SET_ELEM_LEN_BYVAL_ALIGN(sizeof(bool), true, 'c');
378
6
      break;
379
380
0
    case NAMEOID:
381
0
      SET_ELEM_LEN_BYVAL_ALIGN(64, false, 'c');
382
0
      break;
383
384
6
    case INT2OID:
385
6
      SET_ELEM_LEN_BYVAL_ALIGN(2, true, 's');
386
6
      break;
387
388
6
    case INT4OID:
389
6
    case ABSTIMEOID:
390
12
    case DATEOID:
391
12
    case ANYOID:
392
12
      SET_ELEM_LEN_BYVAL_ALIGN(sizeof(int32), true, 'i');
393
12
      break;
394
395
0
    case OIDOID:
396
0
    case CIDOID:
397
6
    case FLOAT4OID:
398
6
      SET_ELEM_LEN_BYVAL_ALIGN(4, true, 'i');
399
6
      break;
400
401
0
    case XIDOID:
402
0
      SET_ELEM_LEN_BYVAL_ALIGN(16/*sizeof(TransactionId)*/, true, 'i');
403
0
      break;
404
405
6
    case POINTOID:
406
12
    case INTERVALOID:
407
12
      SET_ELEM_LEN_BYVAL_ALIGN(16, false, 'd');
408
12
      break;
409
410
6
    case LSEGOID:
411
6
      SET_ELEM_LEN_BYVAL_ALIGN(32, false, 'd');
412
6
      break;
413
414
6
    case BOXOID:
415
6
      SET_ELEM_LEN_BYVAL_ALIGN(32, false, 'd');
416
6
      elmdelim = ';';
417
6
      break;
418
419
6
    case FLOAT8OID:
420
6
      SET_ELEM_LEN_BYVAL_ALIGN(8, true, 'd');
421
6
      break;
422
423
6
    case MACADDROID:
424
6
      SET_ELEM_LEN_BYVAL_ALIGN(6, false, 'i');
425
6
      break;
426
427
6
    case MACADDR8OID:
428
6
      SET_ELEM_LEN_BYVAL_ALIGN(8, false, 'i');
429
6
      break;
430
431
0
    case CSTRINGOID:
432
0
      SET_ELEM_LEN_BYVAL_ALIGN(-1, false, 'c');
433
0
      break;
434
435
6
    case TIMESTAMPTZOID:
436
6
      SET_ELEM_LEN_BYVAL_ALIGN_OPT(sizeof(int64), true, 'd', 't');
437
6
      break;
438
439
6
    case TIMETZOID:
440
6
      SET_ELEM_LEN_BYVAL_ALIGN(12, false, 'd');
441
6
      break;
442
443
6
    case UUIDOID:
444
6
      SET_ELEM_LEN_BYVAL_ALIGN(16, false, 'c');
445
6
      break;
446
447
0
    case LSNOID:
448
0
      SET_ELEM_LEN_BYVAL_ALIGN(sizeof(uint64), true, 'i');
449
0
      break;
450
451
0
    case INT4RANGEOID:
452
0
    case NUMRANGEOID:
453
0
    case TSRANGEOID:
454
0
    case TSTZRANGEOID:
455
0
    case DATERANGEOID:
456
0
    case INT8RANGEOID:
457
0
      SET_ELEM_LEN_BYVAL_ALIGN_OPT(-1, false, 'i', 'r');
458
0
      break;
459
460
0
    default:
461
0
      SET_ELEM_LEN_BYVAL_ALIGN(-1, false, 'i');
462
0
      break;
463
186
  }
464
465
186
  if (func_name != nullptr) {
466
186
    decoded_str = DecodeArrayDatum(
467
186
        "array_out", (uintptr_t)datum, elmlen, elmbyval, elmalign, elmdelim, from_YB, func_name,
468
186
        timezone, option);
469
470
186
    cdc_datum_message->set_datum_string(decoded_str, strlen(decoded_str));
471
186
  }
472
186
}
473
474
void set_decoded_string_range_array(
475
    const QLValuePB ql_value,
476
    const YBCPgTypeEntity *arg_type,
477
    const int elem_type,
478
    const char *func_name,
479
    DatumMessagePB *cdc_datum_message = nullptr,
480
36
    const char *timezone = nullptr) {
481
36
  YBCPgTypeAttrs type_attrs{-1 /* typmod */};
482
483
36
  char* decoded_str = nullptr;
484
36
  string arr_val = ql_value.binary_value();
485
36
  uint64_t size = arr_val.size();
486
36
  char* val = const_cast<char *>(arr_val.c_str());
487
36
  uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
488
489
36
  int16 elmlen, range_elmlen;
490
36
  bool elmbyval, range_elmbyval;
491
36
  char elmalign, range_elmalign;
492
36
  char elmdelim = ',';
493
36
  bool from_YB = true;
494
36
  char option = 'r';
495
36
  char range_option = '\0';
496
497
36
  switch (elem_type) {
498
6
    case INT4RANGEOID:
499
12
    case DATERANGEOID:
500
12
      SET_RANGE_ELEM_LEN_BYVAL_ALIGN(-1, false, 'i', sizeof(int32), true, 'i');
501
12
      break;
502
503
6
    case NUMRANGEOID:
504
6
      SET_RANGE_ELEM_LEN_BYVAL_ALIGN(-1, false, 'i', -1, false, 'i');
505
6
      break;
506
507
6
    case TSRANGEOID:
508
12
    case INT8RANGEOID:
509
12
      SET_RANGE_ELEM_LEN_BYVAL_ALIGN(-1, false, 'd', sizeof(int64), true, 'i');
510
12
      break;
511
512
6
    case TSTZRANGEOID:
513
6
      SET_RANGE_ELEM_LEN_BYVAL_ALIGN(-1, false, 'd', sizeof(int64), true, 'i');
514
6
      range_option = 't';
515
6
      break;
516
517
0
    default:
518
0
      SET_RANGE_ELEM_LEN_BYVAL_ALIGN(-1, false, 'i', -1, false, 'i');
519
0
      break;
520
36
  }
521
522
36
  if (func_name != nullptr) {
523
36
    decoded_str = DecodeRangeArrayDatum(
524
36
        "array_out", (uintptr_t)datum, elmlen, range_elmlen, elmbyval, range_elmbyval, elmalign,
525
36
        range_elmalign, elmdelim, option, range_option, from_YB, "range_out", func_name, elem_type,
526
36
        timezone);
527
528
36
    cdc_datum_message->set_datum_string(decoded_str, strlen(decoded_str));
529
36
  }
530
36
}
531
532
206
void set_string_value(uint64_t datum, char const *func_name, DatumMessagePB *cdc_datum_message) {
533
206
  set_decoded_string_value(datum, func_name, cdc_datum_message);
534
206
}
535
536
void set_range_string_value(
537
    const QLValuePB ql_value,
538
    const YBCPgTypeEntity* arg_type,
539
    const int type_oid,
540
    char const* func_name,
541
24
    DatumMessagePB* cdc_datum_message) {
542
24
  set_decoded_string_range(ql_value, arg_type, type_oid, func_name, cdc_datum_message);
543
24
}
544
545
void set_array_string_value(
546
    const QLValuePB ql_value,
547
    const YBCPgTypeEntity* arg_type,
548
    const int type_oid,
549
    char const* func_name,
550
180
    DatumMessagePB* cdc_datum_message) {
551
180
  set_decoded_string_array(ql_value, arg_type, type_oid, func_name, cdc_datum_message);
552
180
}
553
554
void set_range_array_string_value(
555
    const QLValuePB ql_value,
556
    const YBCPgTypeEntity* arg_type,
557
    const int type_oid,
558
    char const* func_name,
559
30
    DatumMessagePB* cdc_datum_message) {
560
30
  set_decoded_string_range_array(ql_value, arg_type, type_oid, func_name, cdc_datum_message);
561
30
}
562
563
// This function expects that YbgPrepareMemoryContext was called
564
// by the caller of this function.
565
Status SetValueFromQLBinaryHelper(
566
78.3k
    const QLValuePB ql_value, const int pg_data_type, DatumMessagePB *cdc_datum_message) {
567
78.3k
  uint64_t size;
568
78.3k
  char* val;
569
78.3k
  const char* timezone = "GMT";
570
78.3k
  char const* func_name = nullptr;
571
572
78.3k
  YbgTypeDesc pg_arg_type{pg_data_type, -1 /* typmod */};
573
78.3k
  const YBCPgTypeEntity* arg_type = DocPgGetTypeEntity(pg_arg_type);
574
575
78.3k
  YBCPgTypeAttrs type_attrs{-1 /* typmod */};
576
577
78.3k
  cdc_datum_message->set_column_type(pg_data_type);
578
579
78.3k
  switch (arg_type->type_oid) {
580
8
    case BOOLOID: {
581
8
      func_name = "boolout";
582
8
      bool bool_val = ql_value.bool_value();
583
8
      cdc_datum_message->set_datum_bool(bool_val);
584
8
      break;
585
0
    }
586
8
    case BYTEAOID: {
587
8
      func_name = "byteaout";
588
8
      string bytea_val = ql_value.binary_value();
589
8
      size = bytea_val.size();
590
8
      val = const_cast<char *>(bytea_val.c_str());
591
8
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<void *>(val), size, &type_attrs);
592
8
      set_string_value(datum, func_name, cdc_datum_message);
593
8
      break;
594
0
    }
595
0
    case CHAROID: {
596
0
      func_name = "charout";
597
0
      int char_val = ql_value.int8_value();
598
0
      size = sizeof(int);
599
0
      uint64_t datum =
600
0
          arg_type->yb_to_datum(reinterpret_cast<char *>(&char_val), size, &type_attrs);
601
0
      set_string_value(datum, func_name, cdc_datum_message);
602
0
      break;
603
0
    }
604
0
    case NAMEOID: {
605
0
      func_name = "nameout";
606
0
      string name_val = ql_value.string_value();
607
0
      size = name_val.size();
608
0
      val = const_cast<char *>(name_val.c_str());
609
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<char *>(val), size, &type_attrs);
610
0
      set_string_value(datum, func_name, cdc_datum_message);
611
0
      break;
612
0
    }
613
0
    case INT8OID: {
614
0
      func_name = "int8out";
615
0
      int64_t int8_val = ql_value.int64_value();
616
0
      cdc_datum_message->set_datum_int64(int8_val);
617
0
      break;
618
0
    }
619
0
    case INT2OID: {
620
0
      func_name = "int2out";
621
0
      int int2_val = ql_value.int16_value();
622
0
      cdc_datum_message->set_datum_int32(int2_val);
623
0
      break;
624
0
    }
625
77.8k
    case INT4OID: {
626
77.8k
      func_name = "int4out";
627
77.8k
      int int4_val = ql_value.int32_value();
628
77.8k
      cdc_datum_message->set_datum_int32(int4_val);
629
77.8k
      break;
630
0
    }
631
0
    case REGPROCOID: {
632
0
      func_name = "regprocout";
633
0
      int regproc_val = ql_value.uint32_value();
634
0
      size = arg_type->datum_fixed_size;
635
0
      uint64_t datum =
636
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&regproc_val), size, &type_attrs);
637
0
      set_string_value(datum, func_name, cdc_datum_message);
638
0
      break;
639
0
    }
640
10
    case TEXTOID: {
641
10
      func_name = "textout";
642
10
      string text_val = ql_value.string_value();
643
10
      size = text_val.size();
644
10
      val = const_cast<char *>(text_val.c_str());
645
10
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<char *>(val), size, &type_attrs);
646
10
      set_string_value(datum, func_name, cdc_datum_message);
647
10
      break;
648
0
    }
649
0
    case OIDOID: {
650
0
      func_name = "oidout";
651
0
      uint32 oid_val = ql_value.uint32_value();
652
0
      cdc_datum_message->set_datum_int64(oid_val);
653
0
      break;
654
0
    }
655
0
    case TIDOID: {
656
0
      func_name = "tidout";
657
0
      string tid_val = ql_value.binary_value();
658
0
      size = arg_type->datum_fixed_size;
659
0
      val = const_cast<char *>(tid_val.c_str());
660
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
661
0
      set_string_value(datum, func_name, cdc_datum_message);
662
0
      break;
663
0
    }
664
0
    case XIDOID: {
665
0
      func_name = "xidout";
666
0
      uint32 xid_val = ql_value.uint32_value();
667
0
      size = arg_type->datum_fixed_size;
668
0
      uint64_t datum =
669
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&xid_val), size, &type_attrs);
670
0
      set_string_value(datum, func_name, cdc_datum_message);
671
0
      break;
672
0
    }
673
0
    case CIDOID: {
674
0
      func_name = "cidout";
675
0
      uint32 cid_val = ql_value.uint32_value();
676
0
      size = arg_type->datum_fixed_size;
677
0
      uint64_t datum =
678
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&cid_val), size, &type_attrs);
679
0
      set_string_value(datum, func_name, cdc_datum_message);
680
0
      break;
681
0
    }
682
10
    case JSONOID: {
683
10
      func_name = "json_out";
684
10
      string json_val = ql_value.binary_value();
685
10
      size = json_val.size();
686
10
      val = const_cast<char *>(json_val.c_str());
687
10
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
688
10
      set_string_value(datum, func_name, cdc_datum_message);
689
10
      break;
690
0
    }
691
0
    case XMLOID: {
692
0
      func_name = "xml_out";
693
0
      string xml_val = ql_value.binary_value();
694
0
      size = xml_val.size();
695
0
      val = const_cast<char *>(xml_val.c_str());
696
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
697
0
      set_string_value(datum, func_name, cdc_datum_message);
698
0
      break;
699
0
    }
700
0
    case PGNODETREEOID: {
701
0
      func_name = "pg_node_tree_out";
702
0
      string pg_node_tree_val = ql_value.binary_value();
703
0
      size = pg_node_tree_val.size();
704
0
      val = const_cast<char *>(pg_node_tree_val.c_str());
705
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<void *>(val), size, &type_attrs);
706
0
      set_string_value(datum, func_name, cdc_datum_message);
707
0
      break;
708
0
    }
709
0
    case PGNDISTINCTOID: {
710
0
      func_name = "pg_ndistinct_out";
711
0
      string pg_ndistinct_val = ql_value.binary_value();
712
0
      size = pg_ndistinct_val.size();
713
0
      val = const_cast<char *>(pg_ndistinct_val.c_str());
714
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<void *>(val), size, &type_attrs);
715
0
      set_string_value(datum, func_name, cdc_datum_message);
716
0
      break;
717
0
    }
718
0
    case PGDEPENDENCIESOID: {
719
0
      func_name = "pg_dependencies_out";
720
0
      string pg_dependencies_val = ql_value.binary_value();
721
0
      size = pg_dependencies_val.size();
722
0
      val = const_cast<char *>(pg_dependencies_val.c_str());
723
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<void *>(val), size, &type_attrs);
724
0
      set_string_value(datum, func_name, cdc_datum_message);
725
0
      break;
726
0
    }
727
0
    case PGDDLCOMMANDOID: {
728
0
      func_name = "pg_ddl_command_out";
729
0
      int64_t pg_ddl_command_val = ql_value.int64_value();
730
0
      size = arg_type->datum_fixed_size;
731
0
      uint64_t datum =
732
0
          arg_type->yb_to_datum(reinterpret_cast<int64 *>(&pg_ddl_command_val), size, &type_attrs);
733
0
      set_string_value(datum, func_name, cdc_datum_message);
734
0
      break;
735
0
    }
736
0
    case SMGROID: {
737
0
      func_name = "smgrout";
738
0
      int smgr_val = ql_value.int16_value();
739
0
      size = arg_type->datum_fixed_size;
740
0
      uint64_t datum =
741
0
          arg_type->yb_to_datum(reinterpret_cast<int16 *>(&smgr_val), size, &type_attrs);
742
0
      set_string_value(datum, func_name, cdc_datum_message);
743
0
      break;
744
0
    }
745
8
    case POINTOID: {
746
8
      func_name = "point_out";
747
8
      string point_val = ql_value.binary_value();
748
8
      size = arg_type->datum_fixed_size;
749
8
      val = const_cast<char *>(point_val.c_str());
750
8
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
751
8
      set_string_value(datum, func_name, cdc_datum_message);
752
8
      break;
753
0
    }
754
8
    case LSEGOID: {
755
8
      func_name = "lseg_out";
756
8
      string lseg_val = ql_value.binary_value();
757
8
      size = arg_type->datum_fixed_size;
758
8
      val = const_cast<char *>(lseg_val.c_str());
759
8
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<int8 *>(val), size, &type_attrs);
760
8
      set_string_value(datum, func_name, cdc_datum_message);
761
8
      break;
762
0
    }
763
8
    case PATHOID: {
764
8
      func_name = "path_out";
765
8
      string path_val = ql_value.binary_value();
766
8
      size = path_val.size();
767
8
      val = const_cast<char *>(path_val.c_str());
768
8
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
769
8
      set_string_value(datum, func_name, cdc_datum_message);
770
8
      break;
771
0
    }
772
8
    case BOXOID: {
773
8
      func_name = "box_out";
774
8
      string box_val = ql_value.binary_value();
775
8
      size = arg_type->datum_fixed_size;
776
8
      val = const_cast<char *>(box_val.c_str());
777
8
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
778
8
      set_string_value(datum, func_name, cdc_datum_message);
779
8
      break;
780
0
    }
781
8
    case LINEOID: {
782
8
      func_name = "line_out";
783
8
      string line_val = ql_value.binary_value();
784
8
      size = arg_type->datum_fixed_size;
785
8
      val = const_cast<char *>(line_val.c_str());
786
8
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
787
8
      set_string_value(datum, func_name, cdc_datum_message);
788
8
      break;
789
0
    }
790
0
    case FLOAT4OID: {
791
0
      func_name = "float4out";
792
0
      float float4_val = ql_value.float_value();
793
0
      cdc_datum_message->set_datum_float(float4_val);
794
0
      break;
795
0
    }
796
8
    case FLOAT8OID: {
797
8
      func_name = "float8out";
798
8
      double float8_val = ql_value.double_value();
799
8
      cdc_datum_message->set_datum_double(float8_val);
800
8
      break;
801
0
    }
802
8
    case CIRCLEOID: {
803
8
      func_name = "circle_out";
804
8
      string circle_val = ql_value.binary_value();
805
8
      size = arg_type->datum_fixed_size;
806
8
      val = const_cast<char *>(circle_val.c_str());
807
8
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
808
8
      set_string_value(datum, func_name, cdc_datum_message);
809
8
      break;
810
0
    }
811
10
    case CASHOID: {
812
10
      func_name = "cash_out";
813
10
      int64_t cash_val = ql_value.int64_value();
814
10
      size = arg_type->datum_fixed_size;
815
10
      val = reinterpret_cast<char *>(&cash_val);
816
10
      uint64_t datum =
817
10
          arg_type->yb_to_datum(reinterpret_cast<int64 *>(&cash_val), size, &type_attrs);
818
10
      set_string_value(datum, func_name, cdc_datum_message);
819
10
      break;
820
0
    }
821
8
    case MACADDROID: {
822
8
      func_name = "macaddr_out";
823
8
      string macaddr_val = ql_value.binary_value();
824
8
      size = arg_type->datum_fixed_size;
825
8
      val = const_cast<char *>(macaddr_val.c_str());
826
8
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
827
8
      set_string_value(datum, func_name, cdc_datum_message);
828
8
      break;
829
0
    }
830
8
    case INETOID: {
831
8
      func_name = "inet_out";
832
8
      string inet_val = ql_value.binary_value();
833
8
      size = inet_val.size();
834
8
      val = const_cast<char *>(inet_val.c_str());
835
8
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
836
8
      set_string_value(datum, func_name, cdc_datum_message);
837
8
      break;
838
0
    }
839
8
    case CIDROID: {
840
8
      func_name = "cidr_out";
841
8
      string cidr_val = ql_value.binary_value();
842
8
      size = cidr_val.size();
843
8
      val = const_cast<char *>(cidr_val.c_str());
844
8
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
845
8
      set_string_value(datum, func_name, cdc_datum_message);
846
8
      break;
847
0
    }
848
10
    case MACADDR8OID: {
849
10
      func_name = "macaddr8_out";
850
10
      string macaddr8_val = ql_value.binary_value();
851
10
      size = arg_type->datum_fixed_size;
852
10
      val = const_cast<char *>(macaddr8_val.c_str());
853
10
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
854
10
      set_string_value(datum, func_name, cdc_datum_message);
855
10
      break;
856
0
    }
857
0
    case ACLITEMOID: {
858
0
      func_name = "aclitemout";
859
0
      string aclitem_val = ql_value.binary_value();
860
0
      size = arg_type->datum_fixed_size;
861
0
      val = const_cast<char *>(aclitem_val.c_str());
862
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
863
0
      set_string_value(datum, func_name, cdc_datum_message);
864
0
      break;
865
0
    }
866
0
    case BPCHAROID: {
867
0
      func_name = "bpcharout";
868
0
      string bpchar_val = ql_value.string_value();
869
0
      size = bpchar_val.size();
870
0
      val = const_cast<char *>(bpchar_val.c_str());
871
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<char *>(val), size, &type_attrs);
872
0
      set_string_value(datum, func_name, cdc_datum_message);
873
0
      break;
874
0
    }
875
0
    case VARCHAROID: {
876
0
      func_name = "varcharout";
877
0
      string varchar_val = ql_value.string_value();
878
0
      size = varchar_val.size();
879
0
      val = const_cast<char *>(varchar_val.c_str());
880
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<char *>(val), size, &type_attrs);
881
0
      set_string_value(datum, func_name, cdc_datum_message);
882
0
      break;
883
0
    }
884
12
    case DATEOID: {
885
12
      func_name = "date_out";
886
12
      int date_val = ql_value.int32_value();
887
12
      size = arg_type->datum_fixed_size;
888
12
      uint64_t datum =
889
12
          arg_type->yb_to_datum(reinterpret_cast<int32 *>(&date_val), size, &type_attrs);
890
12
      set_string_value(datum, func_name, cdc_datum_message);
891
12
      break;
892
0
    }
893
10
    case TIMEOID: {
894
10
      func_name = "time_out";
895
10
      int64_t time_val = ql_value.int64_value();
896
10
      size = arg_type->datum_fixed_size;
897
10
      uint64_t datum =
898
10
          arg_type->yb_to_datum(reinterpret_cast<int64 *>(&time_val), size, &type_attrs);
899
10
      set_string_value(datum, func_name, cdc_datum_message);
900
10
      break;
901
0
    }
902
8
    case TIMESTAMPOID: {
903
8
      func_name = "timestamp_out";
904
8
      int64_t timestamp_val = ql_value.int64_value();
905
8
      size = arg_type->datum_fixed_size;
906
8
      uint64_t datum =
907
8
          arg_type->yb_to_datum(reinterpret_cast<int64 *>(&timestamp_val), size, &type_attrs);
908
8
      set_string_value(datum, func_name, cdc_datum_message);
909
8
      break;
910
0
    }
911
6
    case TIMESTAMPTZOID: {
912
6
      func_name = "timestamptz_out";
913
6
      int64_t timestamptz_val = ql_value.int64_value();
914
6
      size = arg_type->datum_fixed_size;
915
6
      uint64_t datum =
916
6
          arg_type->yb_to_datum(reinterpret_cast<int64 *>(&timestamptz_val), size, &type_attrs);
917
918
6
      set_decoded_string_value(datum, func_name, cdc_datum_message, timezone);
919
6
      break;
920
0
    }
921
0
    case INTERVALOID: {
922
0
      func_name = "interval_out";
923
0
      string interval_val = ql_value.binary_value();
924
0
      size = arg_type->datum_fixed_size;
925
0
      val = const_cast<char *>(interval_val.c_str());
926
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<void *>(val), size, &type_attrs);
927
0
      set_string_value(datum, func_name, cdc_datum_message);
928
0
      break;
929
0
    }
930
8
    case TIMETZOID: {
931
8
      func_name = "timetz_out";
932
8
      string timetz_val = ql_value.binary_value();
933
8
      size = arg_type->datum_fixed_size;
934
8
      val = const_cast<char *>(timetz_val.c_str());
935
8
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
936
8
      set_string_value(datum, func_name, cdc_datum_message);
937
8
      break;
938
0
    }
939
10
    case BITOID: {
940
10
      func_name = "bit_out";
941
10
      string bit_val = ql_value.binary_value();
942
10
      size = bit_val.size();
943
10
      val = const_cast<char *>(bit_val.c_str());
944
10
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
945
10
      set_string_value(datum, func_name, cdc_datum_message);
946
10
      break;
947
0
    }
948
10
    case VARBITOID: {
949
10
      func_name = "varbit_out";
950
10
      string varbit_val = ql_value.binary_value();
951
10
      size = varbit_val.size();
952
10
      val = const_cast<char *>(varbit_val.c_str());
953
10
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
954
10
      set_string_value(datum, func_name, cdc_datum_message);
955
10
      break;
956
0
    }
957
8
    case NUMERICOID: {
958
8
      func_name = "numeric_out";
959
8
      util::Decimal decimal;
960
961
8
      Status s = decimal.DecodeFromComparable(ql_value.decimal_value());
962
8
      if (!s.ok())
963
0
        return STATUS_SUBSTITUTE(
964
8
            InternalError, "Failed to deserialize DECIMAL from $1", ql_value.decimal_value());
965
8
      string numeric_val = decimal.ToString();
966
8
      cdc_datum_message->set_datum_double(std::stod(numeric_val));
967
8
      break;
968
8
    }
969
0
    case REGPROCEDUREOID: {
970
0
      func_name = "regprocedureout";
971
0
      uint32 regprocedure_val = ql_value.uint32_value();
972
0
      size = arg_type->datum_fixed_size;
973
0
      uint64_t datum =
974
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&regprocedure_val), size, &type_attrs);
975
0
      set_string_value(datum, func_name, cdc_datum_message);
976
0
      break;
977
8
    }
978
0
    case REGOPEROID: {
979
0
      func_name = "regoperout";
980
0
      uint32 regoper_val = ql_value.uint32_value();
981
0
      size = arg_type->datum_fixed_size;
982
0
      uint64_t datum =
983
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&regoper_val), size, &type_attrs);
984
0
      set_string_value(datum, func_name, cdc_datum_message);
985
0
      break;
986
8
    }
987
0
    case REGOPERATOROID: {
988
0
      func_name = "regoperatorout";
989
0
      uint32 regoperator_val = ql_value.uint32_value();
990
0
      size = arg_type->datum_fixed_size;
991
0
      uint64_t datum =
992
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&regoperator_val), size, &type_attrs);
993
0
      set_string_value(datum, func_name, cdc_datum_message);
994
0
      break;
995
8
    }
996
0
    case REGCLASSOID: {
997
0
      func_name = "regclassout";
998
0
      uint32 regclass_val = ql_value.uint32_value();
999
0
      size = arg_type->datum_fixed_size;
1000
0
      uint64_t datum =
1001
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&regclass_val), size, &type_attrs);
1002
0
      set_string_value(datum, func_name, cdc_datum_message);
1003
0
      break;
1004
8
    }
1005
0
    case REGTYPEOID: {
1006
0
      func_name = "regtypeout";
1007
0
      uint32 regtype_val = ql_value.uint32_value();
1008
0
      size = arg_type->datum_fixed_size;
1009
0
      uint64_t datum =
1010
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&regtype_val), size, &type_attrs);
1011
0
      set_string_value(datum, func_name, cdc_datum_message);
1012
0
      break;
1013
8
    }
1014
0
    case REGROLEOID: {
1015
0
      func_name = "regroleout";
1016
0
      uint32 regrole_val = ql_value.uint32_value();
1017
0
      size = arg_type->datum_fixed_size;
1018
0
      uint64_t datum =
1019
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&regrole_val), size, &type_attrs);
1020
0
      set_string_value(datum, func_name, cdc_datum_message);
1021
0
      break;
1022
8
    }
1023
0
    case REGNAMESPACEOID: {
1024
0
      func_name = "regnamespaceout";
1025
0
      uint32 regnamespace_val = ql_value.uint32_value();
1026
0
      size = arg_type->datum_fixed_size;
1027
0
      uint64_t datum =
1028
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&regnamespace_val), size, &type_attrs);
1029
0
      set_string_value(datum, func_name, cdc_datum_message);
1030
0
      break;
1031
8
    }
1032
10
    case UUIDOID: {
1033
10
      func_name = "uuid_out";
1034
10
      string uuid_val = ql_value.binary_value();
1035
10
      size = uuid_val.size();
1036
10
      val = const_cast<char *>(uuid_val.c_str());
1037
10
      uint64_t datum =
1038
10
          arg_type->yb_to_datum(reinterpret_cast<unsigned char *>(val), size, &type_attrs);
1039
10
      set_string_value(datum, func_name, cdc_datum_message);
1040
10
      break;
1041
8
    }
1042
0
    case LSNOID: {
1043
0
      func_name = "pg_lsn_out";
1044
0
      uint64 pg_lsn_val = ql_value.uint64_value();
1045
0
      size = arg_type->datum_fixed_size;
1046
0
      uint64_t datum =
1047
0
          arg_type->yb_to_datum(reinterpret_cast<uint64 *>(&pg_lsn_val), size, &type_attrs);
1048
0
      set_string_value(datum, func_name, cdc_datum_message);
1049
0
      break;
1050
8
    }
1051
0
    case TSQUERYOID: {
1052
0
      func_name = "tsqueryout";
1053
0
      string tsquery_val = ql_value.binary_value();
1054
0
      size = tsquery_val.size();
1055
0
      val = const_cast<char *>(tsquery_val.c_str());
1056
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
1057
0
      set_string_value(datum, func_name, cdc_datum_message);
1058
0
      break;
1059
8
    }
1060
0
    case REGCONFIGOID: {
1061
0
      func_name = "regconfigout";
1062
0
      uint32 regconfig_val = ql_value.uint32_value();
1063
0
      size = arg_type->datum_fixed_size;
1064
0
      uint64_t datum =
1065
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&regconfig_val), size, &type_attrs);
1066
0
      set_string_value(datum, func_name, cdc_datum_message);
1067
0
      break;
1068
8
    }
1069
0
    case REGDICTIONARYOID: {
1070
0
      func_name = "regdictionaryout";
1071
0
      uint32 regdictionary_val = ql_value.uint32_value();
1072
0
      size = arg_type->datum_fixed_size;
1073
0
      uint64_t datum =
1074
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&regdictionary_val), size, &type_attrs);
1075
0
      set_string_value(datum, func_name, cdc_datum_message);
1076
0
      break;
1077
8
    }
1078
10
    case JSONBOID: {
1079
10
      func_name = "jsonb_out";
1080
10
      string jsonb_val = ql_value.binary_value();
1081
10
      size = jsonb_val.size();
1082
10
      val = const_cast<char *>(jsonb_val.c_str());
1083
10
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<void *>(val), size, &type_attrs);
1084
10
      set_string_value(datum, func_name, cdc_datum_message);
1085
10
      break;
1086
8
    }
1087
0
    case TXID_SNAPSHOTOID: {
1088
0
      func_name = "txid_snapshot_out";
1089
0
      string txid_val = ql_value.binary_value();
1090
0
      size = txid_val.size();
1091
0
      val = const_cast<char *>(txid_val.c_str());
1092
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<void *>(val), size, &type_attrs);
1093
0
      set_string_value(datum, func_name, cdc_datum_message);
1094
0
      break;
1095
8
    }
1096
0
    case RECORDOID: {
1097
      /*func_name = "record_out";
1098
      string record_val = ql_value.binary_value();
1099
      size = record_val.size();
1100
      val = const_cast<char *>(record_val.c_str());
1101
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
1102
1103
      if (!is_proto_record) {
1104
        set_decoded_string_value(datum, func_name, is_proto_record);
1105
      } else {
1106
1107
          set_decoded_string_value(datum, func_name,
1108
                                   cdc_datum_message);
1109
      }*/
1110
1111
0
      cdc_datum_message->set_datum_string("");
1112
0
      break;
1113
8
    }
1114
0
    case CSTRINGOID: {
1115
0
      func_name = "cstring_out";
1116
0
      string cstring_val = ql_value.string_value();
1117
0
      size = cstring_val.size();
1118
0
      val = const_cast<char *>(cstring_val.c_str());
1119
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<char *>(val), size, &type_attrs);
1120
0
      set_string_value(datum, func_name, cdc_datum_message);
1121
0
      break;
1122
8
    }
1123
0
    case ANYOID: {
1124
0
      func_name = "any_out";
1125
0
      int any_val = ql_value.int32_value();
1126
0
      size = arg_type->datum_fixed_size;
1127
0
      uint64_t datum =
1128
0
          arg_type->yb_to_datum(reinterpret_cast<int32 *>(&any_val), size, &type_attrs);
1129
0
      set_string_value(datum, func_name, cdc_datum_message);
1130
0
      break;
1131
8
    }
1132
0
    case VOIDOID: {
1133
0
      func_name = "void_out";
1134
0
      int64_t void_val = ql_value.int64_value();
1135
0
      size = arg_type->datum_fixed_size;
1136
0
      uint64_t datum =
1137
0
          arg_type->yb_to_datum(reinterpret_cast<int64 *>(&void_val), size, &type_attrs);
1138
0
      set_string_value(datum, func_name, cdc_datum_message);
1139
0
      break;
1140
8
    }
1141
0
    case TRIGGEROID: {
1142
0
      func_name = "trigger_out";
1143
0
      uint32 trigger_val = ql_value.uint32_value();
1144
0
      size = arg_type->datum_fixed_size;
1145
0
      uint64_t datum =
1146
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&trigger_val), size, &type_attrs);
1147
0
      set_string_value(datum, func_name, cdc_datum_message);
1148
0
      break;
1149
8
    }
1150
0
    case EVTTRIGGEROID: {
1151
0
      func_name = "event_trigger_out";
1152
0
      uint32 event_trigger_val = ql_value.uint32_value();
1153
0
      size = arg_type->datum_fixed_size;
1154
0
      uint64_t datum =
1155
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&event_trigger_val), size, &type_attrs);
1156
0
      set_string_value(datum, func_name, cdc_datum_message);
1157
0
      break;
1158
8
    }
1159
0
    case LANGUAGE_HANDLEROID: {
1160
0
      func_name = "language_handler_out";
1161
0
      uint32 language_handler_val = ql_value.uint32_value();
1162
0
      size = arg_type->datum_fixed_size;
1163
0
      uint64_t datum = arg_type->yb_to_datum(
1164
0
          reinterpret_cast<uint32 *>(&language_handler_val), size, &type_attrs);
1165
0
      set_string_value(datum, func_name, cdc_datum_message);
1166
0
      break;
1167
8
    }
1168
0
    case INTERNALOID: {
1169
0
      func_name = "internal_out";
1170
0
      int64_t internal_val = ql_value.int64_value();
1171
0
      size = arg_type->datum_fixed_size;
1172
0
      uint64_t datum =
1173
0
          arg_type->yb_to_datum(reinterpret_cast<int64 *>(&internal_val), size, &type_attrs);
1174
0
      set_string_value(datum, func_name, cdc_datum_message);
1175
0
      break;
1176
8
    }
1177
0
    case OPAQUEOID: {
1178
0
      func_name = "opaque_out";
1179
0
      int opaque_val = ql_value.int32_value();
1180
0
      size = arg_type->datum_fixed_size;
1181
0
      uint64_t datum =
1182
0
          arg_type->yb_to_datum(reinterpret_cast<int32 *>(&opaque_val), size, &type_attrs);
1183
0
      set_string_value(datum, func_name, cdc_datum_message);
1184
0
      break;
1185
8
    }
1186
0
    case ANYELEMENTOID: {
1187
0
      func_name = "anyelement_out";
1188
0
      int anyelement_val = ql_value.int32_value();
1189
0
      size = arg_type->datum_fixed_size;
1190
0
      uint64_t datum =
1191
0
          arg_type->yb_to_datum(reinterpret_cast<int32 *>(&anyelement_val), size, &type_attrs);
1192
0
      set_string_value(datum, func_name, cdc_datum_message);
1193
0
      break;
1194
8
    }
1195
0
    case ANYNONARRAYOID: {
1196
0
      func_name = "anynonarray_out";
1197
0
      int anynonarray_val = ql_value.int32_value();
1198
0
      size = arg_type->datum_fixed_size;
1199
0
      uint64_t datum =
1200
0
          arg_type->yb_to_datum(reinterpret_cast<int32 *>(&anynonarray_val), size, &type_attrs);
1201
0
      set_string_value(datum, func_name, cdc_datum_message);
1202
0
      break;
1203
8
    }
1204
0
    case ANYENUMOID: {
1205
0
      func_name = "anyenum_out";
1206
0
      int64_t anyenum_val = ql_value.int64_value();
1207
0
      size = arg_type->datum_fixed_size;
1208
0
      uint64_t datum =
1209
0
          arg_type->yb_to_datum(reinterpret_cast<int64 *>(&anyenum_val), size, &type_attrs);
1210
0
      set_string_value(datum, func_name, cdc_datum_message);
1211
0
      break;
1212
8
    }
1213
0
    case FDW_HANDLEROID: {
1214
0
      func_name = "fdw_handler_out";
1215
0
      uint32 fdw_handler_val = ql_value.uint32_value();
1216
0
      size = arg_type->datum_fixed_size;
1217
0
      uint64_t datum =
1218
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&fdw_handler_val), size, &type_attrs);
1219
0
      set_string_value(datum, func_name, cdc_datum_message);
1220
0
      break;
1221
8
    }
1222
0
    case INDEX_AM_HANDLEROID: {
1223
0
      func_name = "index_am_handler_out";
1224
0
      uint32 index_am_handler_val = ql_value.uint32_value();
1225
0
      size = arg_type->datum_fixed_size;
1226
0
      uint64_t datum = arg_type->yb_to_datum(
1227
0
          reinterpret_cast<uint32 *>(&index_am_handler_val), size, &type_attrs);
1228
0
      set_string_value(datum, func_name, cdc_datum_message);
1229
0
      break;
1230
8
    }
1231
0
    case TSM_HANDLEROID: {
1232
0
      func_name = "tsm_handler_out";
1233
0
      uint32 tsm_handler_val = ql_value.uint32_value();
1234
0
      size = arg_type->datum_fixed_size;
1235
0
      uint64_t datum =
1236
0
          arg_type->yb_to_datum(reinterpret_cast<uint32 *>(&tsm_handler_val), size, &type_attrs);
1237
0
      set_string_value(datum, func_name, cdc_datum_message);
1238
0
      break;
1239
8
    }
1240
0
    case ANYRANGEOID: {
1241
0
      func_name = "anyrange_out";
1242
0
      string anyrange_val = ql_value.binary_value();
1243
0
      size = anyrange_val.size();
1244
0
      val = const_cast<char *>(anyrange_val.c_str());
1245
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
1246
0
      set_string_value(datum, func_name, cdc_datum_message);
1247
0
      break;
1248
8
    }
1249
1250
0
    case INT2VECTOROID: {
1251
0
      func_name = "int2vectorout";
1252
0
      string int2vector_val = ql_value.binary_value();
1253
0
      size = int2vector_val.size();
1254
0
      val = const_cast<char *>(int2vector_val.c_str());
1255
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
1256
0
      set_string_value(datum, func_name, cdc_datum_message);
1257
0
      break;
1258
8
    }
1259
1260
0
    case OIDVECTOROID: {
1261
0
      func_name = "oidvectorout";
1262
0
      string oidvector_val = ql_value.binary_value();
1263
0
      size = oidvector_val.size();
1264
0
      val = const_cast<char *>(oidvector_val.c_str());
1265
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
1266
0
      set_string_value(datum, func_name, cdc_datum_message);
1267
0
      break;
1268
8
    }
1269
1270
0
    case TSVECTOROID: {
1271
0
      func_name = "tsvectorout";
1272
0
      string tsvector_val = ql_value.binary_value();
1273
0
      size = tsvector_val.size();
1274
0
      val = const_cast<char *>(tsvector_val.c_str());
1275
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
1276
0
      set_string_value(datum, func_name, cdc_datum_message);
1277
0
      break;
1278
8
    }
1279
1280
0
    case GTSVECTOROID: {
1281
0
      func_name = "gtsvectorout";
1282
0
      string gtsvector_val = ql_value.binary_value();
1283
0
      size = gtsvector_val.size();
1284
0
      val = const_cast<char *>(gtsvector_val.c_str());
1285
0
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
1286
0
      set_string_value(datum, func_name, cdc_datum_message);
1287
0
      break;
1288
8
    }
1289
1290
8
    case POLYGONOID: {
1291
8
      func_name = "poly_out";
1292
8
      string polygon_val = ql_value.binary_value();
1293
8
      size = polygon_val.size();
1294
8
      val = const_cast<char *>(polygon_val.c_str());
1295
8
      uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8 *>(val), size, &type_attrs);
1296
8
      set_string_value(datum, func_name, cdc_datum_message);
1297
8
      break;
1298
8
    }
1299
1300
    // Range types
1301
6
    case INT4RANGEOID: {
1302
6
      func_name = "int4out";
1303
6
      set_range_string_value(ql_value, arg_type, INT4OID, func_name, cdc_datum_message);
1304
6
      break;
1305
8
    }
1306
1307
0
    case NUMRANGEOID: {
1308
0
      func_name = "numeric_out";
1309
0
      set_range_string_value(ql_value, arg_type, NUMERICOID, func_name, cdc_datum_message);
1310
0
      break;
1311
8
    }
1312
1313
6
    case TSRANGEOID: {
1314
6
      func_name = "timestamp_out";
1315
6
      set_range_string_value(ql_value, arg_type, TIMESTAMPOID, func_name, cdc_datum_message);
1316
6
      break;
1317
8
    }
1318
1319
6
    case TSTZRANGEOID: {
1320
6
      func_name = "timestamptz_out";
1321
6
      set_decoded_string_range(
1322
6
          ql_value, arg_type, TIMESTAMPTZOID, func_name, cdc_datum_message, timezone);
1323
6
      break;
1324
8
    }
1325
1326
6
    case DATERANGEOID: {
1327
6
      func_name = "date_out";
1328
6
      set_range_string_value(ql_value, arg_type, DATEOID, func_name, cdc_datum_message);
1329
6
      break;
1330
8
    }
1331
1332
6
    case INT8RANGEOID: {
1333
6
      func_name = "int8out";
1334
6
      set_range_string_value(ql_value, arg_type, INT8OID, func_name, cdc_datum_message);
1335
6
      break;
1336
8
    }
1337
1338
    // Array types
1339
0
    case XMLARRAYOID: {
1340
0
      func_name = "xml_out";
1341
0
      set_array_string_value(ql_value, arg_type, XMLOID, func_name, cdc_datum_message);
1342
0
      break;
1343
8
    }
1344
1345
6
    case LINEARRAYOID: {
1346
6
      func_name = "line_out";
1347
6
      set_array_string_value(ql_value, arg_type, LINEOID, func_name, cdc_datum_message);
1348
6
      break;
1349
8
    }
1350
1351
6
    case CIRCLEARRAYOID: {
1352
6
      func_name = "circle_out";
1353
6
      set_array_string_value(ql_value, arg_type, CIRCLEOID, func_name, cdc_datum_message);
1354
6
      break;
1355
8
    }
1356
1357
6
    case MONEYARRAYOID: {
1358
6
      func_name = "cash_out";
1359
6
      set_array_string_value(ql_value, arg_type, CASHOID, func_name, cdc_datum_message);
1360
6
      break;
1361
8
    }
1362
1363
6
    case BOOLARRAYOID: {
1364
6
      func_name = "boolout";
1365
6
      set_array_string_value(ql_value, arg_type, BOOLOID, func_name, cdc_datum_message);
1366
6
      break;
1367
8
    }
1368
1369
0
    case BYTEAARRAYOID: {
1370
0
      func_name = "byteaout";
1371
0
      set_array_string_value(ql_value, arg_type, BYTEAOID, func_name, cdc_datum_message);
1372
0
      break;
1373
8
    }
1374
1375
0
    case CHARARRAYOID: {
1376
0
      func_name = "charout";
1377
0
      set_array_string_value(ql_value, arg_type, CHAROID, func_name, cdc_datum_message);
1378
0
      break;
1379
8
    }
1380
1381
0
    case NAMEARRAYOID: {
1382
0
      func_name = "nameout";
1383
0
      set_array_string_value(ql_value, arg_type, NAMEOID, func_name, cdc_datum_message);
1384
0
      break;
1385
8
    }
1386
1387
6
    case INT2ARRAYOID: {
1388
6
      func_name = "int2out";
1389
6
      set_array_string_value(ql_value, arg_type, INT2OID, func_name, cdc_datum_message);
1390
6
      break;
1391
8
    }
1392
1393
0
    case INT2VECTORARRAYOID: {
1394
0
      func_name = "int2vectorout";
1395
0
      set_array_string_value(ql_value, arg_type, INT2VECTOROID, func_name, cdc_datum_message);
1396
0
      break;
1397
8
    }
1398
1399
6
    case INT4ARRAYOID: {
1400
6
      func_name = "int4out";
1401
6
      set_array_string_value(ql_value, arg_type, INT4OID, func_name, cdc_datum_message);
1402
6
      break;
1403
8
    }
1404
1405
0
    case REGPROCARRAYOID: {
1406
0
      func_name = "regprocout";
1407
0
      set_array_string_value(ql_value, arg_type, REGPROCOID, func_name, cdc_datum_message);
1408
0
      break;
1409
8
    }
1410
1411
6
    case TEXTARRAYOID: {
1412
6
      func_name = "textout";
1413
6
      set_array_string_value(ql_value, arg_type, TEXTOID, func_name, cdc_datum_message);
1414
6
      break;
1415
8
    }
1416
1417
0
    case OIDARRAYOID: {
1418
0
      func_name = "oidout";
1419
0
      set_array_string_value(ql_value, arg_type, OIDOID, func_name, cdc_datum_message);
1420
0
      break;
1421
8
    }
1422
1423
6
    case CIDRARRAYOID: {
1424
6
      func_name = "cidr_out";
1425
6
      set_array_string_value(ql_value, arg_type, CIDROID, func_name, cdc_datum_message);
1426
6
      break;
1427
8
    }
1428
1429
0
    case TIDARRAYOID: {
1430
0
      func_name = "tidout";
1431
0
      set_array_string_value(ql_value, arg_type, TIDOID, func_name, cdc_datum_message);
1432
0
      break;
1433
8
    }
1434
1435
0
    case XIDARRAYOID: {
1436
0
      func_name = "xidout";
1437
0
      set_array_string_value(ql_value, arg_type, XIDOID, func_name, cdc_datum_message);
1438
0
      break;
1439
8
    }
1440
1441
0
    case CIDARRAYOID: {
1442
0
      func_name = "cidout";
1443
0
      set_array_string_value(ql_value, arg_type, CIDOID, func_name, cdc_datum_message);
1444
0
      break;
1445
8
    }
1446
1447
0
    case OIDVECTORARRAYOID: {
1448
0
      func_name = "oidvectorout";
1449
0
      set_array_string_value(ql_value, arg_type, OIDVECTOROID, func_name, cdc_datum_message);
1450
0
      break;
1451
8
    }
1452
1453
6
    case BPCHARARRAYOID: {
1454
6
      func_name = "bpcharout";
1455
6
      set_array_string_value(ql_value, arg_type, BPCHAROID, func_name, cdc_datum_message);
1456
6
      break;
1457
8
    }
1458
1459
6
    case VARCHARARRAYOID: {
1460
6
      func_name = "varcharout";
1461
6
      set_array_string_value(ql_value, arg_type, VARCHAROID, func_name, cdc_datum_message);
1462
6
      break;
1463
8
    }
1464
1465
0
    case INT8ARRAYOID: {
1466
0
      func_name = "int8out";
1467
0
      set_array_string_value(ql_value, arg_type, INT8OID, func_name, cdc_datum_message);
1468
0
      break;
1469
8
    }
1470
1471
6
    case POINTARRAYOID: {
1472
6
      func_name = "point_out";
1473
6
      set_array_string_value(ql_value, arg_type, POINTOID, func_name, cdc_datum_message);
1474
6
      break;
1475
8
    }
1476
1477
6
    case LSEGARRAYOID: {
1478
6
      func_name = "lseg_out";
1479
6
      set_array_string_value(ql_value, arg_type, LSEGOID, func_name, cdc_datum_message);
1480
6
      break;
1481
8
    }
1482
1483
6
    case PATHARRAYOID: {
1484
6
      func_name = "path_out";
1485
6
      set_array_string_value(ql_value, arg_type, PATHOID, func_name, cdc_datum_message);
1486
6
      break;
1487
8
    }
1488
1489
6
    case BOXARRAYOID: {
1490
6
      func_name = "box_out";
1491
6
      set_array_string_value(ql_value, arg_type, BOXOID, func_name, cdc_datum_message);
1492
6
      break;
1493
8
    }
1494
1495
6
    case FLOAT4ARRAYOID: {
1496
6
      func_name = "float4out";
1497
6
      set_array_string_value(ql_value, arg_type, FLOAT4OID, func_name, cdc_datum_message);
1498
6
      break;
1499
8
    }
1500
1501
6
    case FLOAT8ARRAYOID: {
1502
6
      func_name = "float8out";
1503
6
      set_array_string_value(ql_value, arg_type, FLOAT8OID, func_name, cdc_datum_message);
1504
6
      break;
1505
8
    }
1506
1507
0
    case ABSTIMEARRAYOID: {
1508
0
      func_name = "abstimeout";
1509
0
      set_array_string_value(ql_value, arg_type, ABSTIMEOID, func_name, cdc_datum_message);
1510
0
      break;
1511
8
    }
1512
1513
0
    case RELTIMEARRAYOID: {
1514
0
      func_name = "reltimeout";
1515
0
      set_array_string_value(ql_value, arg_type, RELTIMEOID, func_name, cdc_datum_message);
1516
0
      break;
1517
8
    }
1518
1519
0
    case TINTERVALARRAYOID: {
1520
0
      func_name = "tintervalout";
1521
0
      set_array_string_value(ql_value, arg_type, TINTERVALOID, func_name, cdc_datum_message);
1522
0
      break;
1523
8
    }
1524
1525
0
    case ACLITEMARRAYOID: {
1526
0
      func_name = "aclitemout";
1527
0
      set_array_string_value(ql_value, arg_type, ACLITEMOID, func_name, cdc_datum_message);
1528
0
      break;
1529
8
    }
1530
1531
6
    case MACADDRARRAYOID: {
1532
6
      func_name = "macaddr_out";
1533
6
      set_array_string_value(ql_value, arg_type, MACADDROID, func_name, cdc_datum_message);
1534
6
      break;
1535
8
    }
1536
1537
6
    case MACADDR8ARRAYOID: {
1538
6
      func_name = "macaddr8_out";
1539
6
      set_array_string_value(ql_value, arg_type, MACADDR8OID, func_name, cdc_datum_message);
1540
6
      break;
1541
8
    }
1542
1543
6
    case INETARRAYOID: {
1544
6
      func_name = "inet_out";
1545
6
      set_array_string_value(ql_value, arg_type, INETOID, func_name, cdc_datum_message);
1546
6
      break;
1547
8
    }
1548
1549
0
    case CSTRINGARRAYOID: {
1550
0
      func_name = "cstring_out";
1551
0
      set_array_string_value(ql_value, arg_type, CSTRINGOID, func_name, cdc_datum_message);
1552
0
      break;
1553
8
    }
1554
1555
6
    case TIMESTAMPARRAYOID: {
1556
6
      func_name = "timestamp_out";
1557
6
      set_array_string_value(ql_value, arg_type, TIMESTAMPOID, func_name, cdc_datum_message);
1558
6
      break;
1559
8
    }
1560
1561
6
    case DATEARRAYOID: {
1562
6
      func_name = "date_out";
1563
6
      set_array_string_value(ql_value, arg_type, DATEOID, func_name, cdc_datum_message);
1564
6
      break;
1565
8
    }
1566
1567
6
    case TIMEARRAYOID: {
1568
6
      func_name = "time_out";
1569
6
      set_array_string_value(ql_value, arg_type, TIMEOID, func_name, cdc_datum_message);
1570
6
      break;
1571
8
    }
1572
1573
6
    case TIMESTAMPTZARRAYOID: {
1574
6
      func_name = "timestamptz_out";
1575
6
      set_decoded_string_array(
1576
6
          ql_value, arg_type, TIMESTAMPTZOID, func_name, cdc_datum_message, timezone);
1577
6
      break;
1578
8
    }
1579
1580
6
    case INTERVALARRAYOID: {
1581
6
      func_name = "interval_out";
1582
6
      set_array_string_value(ql_value, arg_type, INTERVALOID, func_name, cdc_datum_message);
1583
6
      break;
1584
8
    }
1585
1586
0
    case NUMERICARRAYOID: {
1587
0
      func_name = "numeric_out";
1588
0
      set_array_string_value(ql_value, arg_type, NUMERICOID, func_name, cdc_datum_message);
1589
0
      break;
1590
8
    }
1591
1592
6
    case TIMETZARRAYOID: {
1593
6
      func_name = "timetz_out";
1594
6
      set_array_string_value(ql_value, arg_type, TIMETZOID, func_name, cdc_datum_message);
1595
6
      break;
1596
8
    }
1597
1598
0
    case BITARRAYOID: {
1599
0
      func_name = "bit_out";
1600
0
      set_array_string_value(ql_value, arg_type, BITOID, func_name, cdc_datum_message);
1601
0
      break;
1602
8
    }
1603
1604
6
    case VARBITARRAYOID: {
1605
6
      func_name = "varbit_out";
1606
6
      set_array_string_value(ql_value, arg_type, VARBITOID, func_name, cdc_datum_message);
1607
6
      break;
1608
8
    }
1609
1610
0
    case REGPROCEDUREARRAYOID: {
1611
0
      func_name = "regprocedureout";
1612
0
      set_array_string_value(ql_value, arg_type, REGPROCEDUREOID, func_name, cdc_datum_message);
1613
0
      break;
1614
8
    }
1615
1616
0
    case REGOPERARRAYOID: {
1617
0
      func_name = "regoperout";
1618
0
      set_array_string_value(ql_value, arg_type, REGOPEROID, func_name, cdc_datum_message);
1619
0
      break;
1620
8
    }
1621
1622
0
    case REGOPERATORARRAYOID: {
1623
0
      func_name = "regoperatorout";
1624
0
      set_array_string_value(ql_value, arg_type, REGOPERATOROID, func_name, cdc_datum_message);
1625
0
      break;
1626
8
    }
1627
1628
0
    case REGCLASSARRAYOID: {
1629
0
      func_name = "regclassout";
1630
0
      set_array_string_value(ql_value, arg_type, REGCLASSOID, func_name, cdc_datum_message);
1631
0
      break;
1632
8
    }
1633
1634
0
    case REGTYPEARRAYOID: {
1635
0
      func_name = "regtypeout";
1636
0
      set_array_string_value(ql_value, arg_type, REGTYPEOID, func_name, cdc_datum_message);
1637
0
      break;
1638
8
    }
1639
1640
0
    case REGROLEARRAYOID: {
1641
0
      func_name = "regroleout";
1642
0
      set_array_string_value(ql_value, arg_type, REGROLEOID, func_name, cdc_datum_message);
1643
0
      break;
1644
8
    }
1645
1646
0
    case REGNAMESPACEARRAYOID: {
1647
0
      func_name = "regnamespaceout";
1648
0
      set_array_string_value(ql_value, arg_type, REGNAMESPACEOID, func_name, cdc_datum_message);
1649
0
      break;
1650
8
    }
1651
1652
6
    case UUIDARRAYOID: {
1653
6
      func_name = "uuid_out";
1654
6
      set_array_string_value(ql_value, arg_type, UUIDOID, func_name, cdc_datum_message);
1655
6
      break;
1656
8
    }
1657
1658
0
    case PG_LSNARRAYOID: {
1659
0
      func_name = "pg_lsn_out";
1660
0
      set_array_string_value(ql_value, arg_type, LSNOID, func_name, cdc_datum_message);
1661
0
      break;
1662
8
    }
1663
1664
0
    case TSVECTORARRAYOID: {
1665
0
      func_name = "tsvectorout";
1666
0
      set_array_string_value(ql_value, arg_type, TSVECTOROID, func_name, cdc_datum_message);
1667
0
      break;
1668
8
    }
1669
1670
0
    case GTSVECTORARRAYOID: {
1671
0
      func_name = "gtsvectorout";
1672
0
      set_array_string_value(ql_value, arg_type, GTSVECTOROID, func_name, cdc_datum_message);
1673
0
      break;
1674
8
    }
1675
1676
0
    case TSQUERYARRAYOID: {
1677
0
      func_name = "tsqueryout";
1678
0
      set_array_string_value(ql_value, arg_type, TSQUERYOID, func_name, cdc_datum_message);
1679
0
      break;
1680
8
    }
1681
1682
0
    case REGCONFIGARRAYOID: {
1683
0
      func_name = "regconfigout";
1684
0
      set_array_string_value(ql_value, arg_type, REGCONFIGOID, func_name, cdc_datum_message);
1685
0
      break;
1686
8
    }
1687
1688
0
    case REGDICTIONARYARRAYOID: {
1689
0
      func_name = "regdictionaryout";
1690
0
      set_array_string_value(ql_value, arg_type, REGDICTIONARYOID, func_name, cdc_datum_message);
1691
0
      break;
1692
8
    }
1693
1694
6
    case JSONARRAYOID: {
1695
6
      func_name = "json_out";
1696
6
      set_array_string_value(ql_value, arg_type, JSONOID, func_name, cdc_datum_message);
1697
6
      break;
1698
8
    }
1699
1700
6
    case JSONBARRAYOID: {
1701
6
      func_name = "jsonb_out";
1702
6
      set_array_string_value(ql_value, arg_type, JSONBOID, func_name, cdc_datum_message);
1703
6
      break;
1704
8
    }
1705
1706
6
    case TXID_SNAPSHOTARRAYOID: {
1707
6
      func_name = "txid_snapshot_out";
1708
6
      set_array_string_value(ql_value, arg_type, TXID_SNAPSHOTOID, func_name, cdc_datum_message);
1709
6
      break;
1710
8
    }
1711
1712
0
    case RECORDARRAYOID: {
1713
0
      cdc_datum_message->set_datum_string("");
1714
0
      break;
1715
8
    }
1716
1717
0
    case ANYARRAYOID: {
1718
0
      func_name = "any_out";
1719
0
      set_array_string_value(ql_value, arg_type, ANYOID, func_name, cdc_datum_message);
1720
0
      break;
1721
8
    }
1722
1723
6
    case POLYGONARRAYOID: {
1724
6
      func_name = "poly_out";
1725
6
      set_array_string_value(ql_value, arg_type, POLYGONOID, func_name, cdc_datum_message);
1726
6
      break;
1727
8
    }
1728
1729
6
    case INT4RANGEARRAYOID: {
1730
6
      func_name = "int4out";
1731
6
      set_range_array_string_value(ql_value, arg_type, INT4RANGEOID, func_name, cdc_datum_message);
1732
6
      break;
1733
8
    }
1734
1735
6
    case NUMRANGEARRAYOID: {
1736
6
      func_name = "numeric_out";
1737
6
      set_range_array_string_value(ql_value, arg_type, NUMRANGEOID, func_name, cdc_datum_message);
1738
6
      break;
1739
8
    }
1740
1741
6
    case TSRANGEARRAYOID: {
1742
6
      func_name = "timestamp_out";
1743
6
      set_range_array_string_value(ql_value, arg_type, TSRANGEOID, func_name, cdc_datum_message);
1744
6
      break;
1745
8
    }
1746
1747
6
    case TSTZRANGEARRAYOID: {
1748
6
      func_name = "timestamptz_out";
1749
6
      set_decoded_string_range_array(
1750
6
          ql_value, arg_type, TSTZRANGEOID, func_name, cdc_datum_message, timezone);
1751
6
      break;
1752
8
    }
1753
1754
6
    case DATERANGEARRAYOID: {
1755
6
      func_name = "date_out";
1756
6
      set_range_array_string_value(ql_value, arg_type, DATERANGEOID, func_name, cdc_datum_message);
1757
6
      break;
1758
8
    }
1759
1760
6
    case INT8RANGEARRAYOID: {
1761
6
      func_name = "int8out";
1762
6
      set_range_array_string_value(ql_value, arg_type, INT8RANGEOID, func_name, cdc_datum_message);
1763
6
      break;
1764
8
    }
1765
1766
0
    default:
1767
0
      LOG(INFO) << "Unknown type in SetValueFromQLBinaryHelper: " << arg_type->type_oid;
1768
0
      break;
1769
78.3k
  }
1770
1771
78.3k
  return Status::OK();
1772
78.3k
}
1773
1774
// This function expects that YbgPrepareMemoryContext was called by the caller of this function.
1775
Status ExtractVectorFromQLBinaryValueHelper(const QLValuePB& ql_value,
1776
                                            const int array_type,
1777
                                            const int elem_type,
1778
422
                                            vector<QLValuePB> *const result) {
1779
422
  const uint64_t size = ql_value.binary_value().size();
1780
422
  char *val = const_cast<char *>(ql_value.binary_value().c_str());
1781
1782
422
  YbgTypeDesc pg_arg_type {array_type, -1 /* typmod */};
1783
422
  const YBCPgTypeEntity *arg_type = DocPgGetTypeEntity(pg_arg_type);
1784
422
  YBCPgTypeAttrs type_attrs {-1 /* typmod */};
1785
422
  uint64_t datum = arg_type->yb_to_datum(reinterpret_cast<uint8_t *>(val), size, &type_attrs);
1786
1787
422
  uint64_t *datum_elements;
1788
422
  int num_elems = 0;
1789
422
  PG_RETURN_NOT_OK(YbgSplitArrayDatum(datum, elem_type, &datum_elements, &num_elems));
1790
422
  YbgTypeDesc elem_pg_arg_type {elem_type, -1 /* typmod */};
1791
422
  const YBCPgTypeEntity *elem_arg_type = DocPgGetTypeEntity(elem_pg_arg_type);
1792
422
  VLOG
(4) << "Number of parsed elements: " << num_elems0
;
1793
844
  for (int i = 0; i < num_elems; 
++i422
) {
1794
422
    QLValuePB ql_val;
1795
422
    pggate::PgConstant value(elem_arg_type,
1796
422
                             false /* collate_is_valid_non_c */,
1797
422
                             nullptr /* collation_sortkey */,
1798
422
                             datum_elements[i], false /* isNull */);
1799
422
    RETURN_NOT_OK(value.Eval(&ql_val));
1800
422
    VLOG
(4) << "Parsed value: " << ql_val.string_value()0
;
1801
422
    result->emplace_back(std::move(ql_val));
1802
422
  }
1803
422
  return Status::OK();
1804
422
}
1805
1806
}  // namespace docdb
1807
}  // namespace yb