-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathType.cpp
683 lines (595 loc) · 21.6 KB
/
Type.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
/* SPDX-License-Identifier: Apache-2.0 */
#include "substrait/type/Type.h"
#include <algorithm>
#include <sstream>
#include <stdexcept>
#include "substrait/common/Exceptions.h"
#include "substrait/common/NumberUtils.h"
#include "substrait/common/StringUtils.h"
namespace io::substrait {
namespace {
size_t findNextComma(std::string_view str, size_t start) {
int cnt = 0;
for (auto i = start; i < str.size(); i++) {
if (str[i] == '<') {
cnt++;
} else if (str[i] == '>') {
cnt--;
} else if (cnt == 0 && str[i] == ',') {
return i;
}
}
return std::string::npos;
}
template <TypeKind Kind>
ParameterizedTypePtr decodeType(bool nullable) {
return std::make_shared<const ScalarType<Kind>>(nullable);
}
template <TypeKind Kind>
ParameterizedTypePtr decodeType(
bool isParameterized,
bool nullable,
const std::vector<ParameterizedTypePtr>& parameterTypes) {
SUBSTRAIT_UNSUPPORTED(
std::string("Unsupported parameter type: ") +
TypeTraits<Kind>::kTypeString);
}
template <>
ParameterizedTypePtr decodeType<TypeKind::kList>(
bool isParameterized,
bool nullable,
const std::vector<ParameterizedTypePtr>& parameterTypes) {
if (isParameterized) {
return std::make_shared<ParameterizedList>(parameterTypes[0], nullable);
} else {
return std::make_shared<List>(
std::dynamic_pointer_cast<const Type>(parameterTypes[0]), nullable);
}
}
template <>
ParameterizedTypePtr decodeType<TypeKind::kMap>(
bool isParameterized,
bool nullable,
const std::vector<ParameterizedTypePtr>& parameterTypes) {
if (isParameterized) {
if (parameterTypes.size() >= 2) {
return std::make_shared<ParameterizedMap>(
parameterTypes[0], parameterTypes[1], nullable);
} else if (!parameterTypes.empty()) {
return std::make_shared<ParameterizedMap>(
parameterTypes[0], nullptr, nullable);
} else {
return std::make_shared<ParameterizedMap>(nullptr, nullptr, nullable);
}
} else {
return std::make_shared<Map>(
std::dynamic_pointer_cast<const Type>(parameterTypes[0]),
std::dynamic_pointer_cast<const Type>(parameterTypes[1]),
nullable);
}
}
template <>
ParameterizedTypePtr decodeType<TypeKind::kStruct>(
bool isParameterized,
bool nullable,
const std::vector<ParameterizedTypePtr>& parameterTypes) {
if (isParameterized) {
return std::make_shared<const ParameterizedStruct>(
parameterTypes, nullable);
} else {
std::vector<TypePtr> types;
types.reserve(parameterTypes.size());
for (const auto& parameterType : parameterTypes) {
types.emplace_back(std::dynamic_pointer_cast<const Type>(parameterType));
}
return std::make_shared<Struct>(types, nullable);
}
}
template <>
ParameterizedTypePtr decodeType<TypeKind::kDecimal>(
bool isParameterized,
bool nullable,
const std::vector<ParameterizedTypePtr>& parameterTypes) {
if (parameterTypes.size() != 2) {
SUBSTRAIT_FAIL(
"Decimal types should have both precision and scale specifiers.")
}
auto precision =
std::dynamic_pointer_cast<const StringLiteral>(parameterTypes[0]);
auto scale =
std::dynamic_pointer_cast<const StringLiteral>(parameterTypes[1]);
if (isParameterized) {
return std::make_shared<ParameterizedDecimal>(precision, scale, nullable);
} else {
if (common::NumberUtils::isNonNegativeInteger(precision->value()) &&
common::NumberUtils::isNonNegativeInteger(scale->value())) {
return std::make_shared<Decimal>(
std::stoi(precision->value()), std::stoi(scale->value()), nullable);
} else {
SUBSTRAIT_FAIL(
"Fail decode to Decimal type, precision or scale parameter must be a "
"positive number")
}
}
}
template <class ParameterizedTypeTag, class TypeTag, TypeKind Kind>
ParameterizedTypePtr decodeLengthBaseType(
bool isParameterized,
bool nullable,
const std::vector<ParameterizedTypePtr>& parameterTypes) {
auto length =
std::dynamic_pointer_cast<const StringLiteral>(parameterTypes[0]);
if (isParameterized) {
return std::make_shared<ParameterizedTypeTag>(length, nullable);
} else {
if (common::NumberUtils::isNonNegativeInteger(length->value())) {
return std::make_shared<TypeTag>(std::stoi(length->value()), nullable);
} else {
SUBSTRAIT_FAIL(
"Fail decode to {} type, length parameter must be a positive integer",
TypeTraits<Kind>::kTypeString);
}
}
}
template <>
ParameterizedTypePtr decodeType<TypeKind::kVarchar>(
bool isParameterized,
bool nullable,
const std::vector<ParameterizedTypePtr>& parameterTypes) {
return decodeLengthBaseType<
ParameterizedVarchar,
Varchar,
TypeKind::kVarchar>(isParameterized, nullable, parameterTypes);
}
template <>
ParameterizedTypePtr decodeType<TypeKind::kFixedChar>(
bool isParameterized,
bool nullable,
const std::vector<ParameterizedTypePtr>& parameterTypes) {
return decodeLengthBaseType<
ParameterizedFixedChar,
class FixedChar,
TypeKind::kFixedChar>(isParameterized, nullable, parameterTypes);
}
template <>
ParameterizedTypePtr decodeType<TypeKind::kFixedBinary>(
bool isParameterized,
bool nullable,
const std::vector<ParameterizedTypePtr>& parameterTypes) {
return decodeLengthBaseType<
ParameterizedFixedBinary,
class FixedBinary,
TypeKind::kBinary>(isParameterized, nullable, parameterTypes);
}
} // namespace
ParameterizedTypePtr ParameterizedType::decode(
const std::string& value,
bool isParameterized) {
std::string rawType =
static_cast<std::string>(common::StringUtils::trim(value));
std::string matchingType = rawType;
std::transform(
matchingType.begin(),
matchingType.end(),
matchingType.begin(),
[](unsigned char c) { return std::tolower(c); });
const auto& questionMaskPos = matchingType.find_last_of('?');
const auto& leftAngleBracketPos = matchingType.find('<');
if (leftAngleBracketPos == std::string::npos) {
bool nullable;
if (matchingType.empty()) {
nullable = false;
} else {
nullable = matchingType.back() == '?';
}
// deal with type and with a question mask like "i32?".
const auto& baseType = nullable
? matchingType = matchingType.substr(0, questionMaskPos)
: matchingType;
if (TypeTraits<TypeKind::kBool>::kTypeString == baseType ||
TypeTraits<TypeKind::kBool>::kSignature == baseType) {
return decodeType<TypeKind::kBool>(nullable);
} else if (TypeTraits<TypeKind::kI8>::kTypeString == baseType) {
return decodeType<TypeKind::kI8>(nullable);
} else if (TypeTraits<TypeKind::kI16>::kTypeString == baseType) {
return decodeType<TypeKind::kI16>(nullable);
} else if (TypeTraits<TypeKind::kI32>::kTypeString == baseType) {
return decodeType<TypeKind::kI32>(nullable);
} else if (TypeTraits<TypeKind::kI64>::kTypeString == baseType) {
return decodeType<TypeKind::kI64>(nullable);
} else if (TypeTraits<TypeKind::kFp32>::kTypeString == baseType) {
return decodeType<TypeKind::kFp32>(nullable);
} else if (TypeTraits<TypeKind::kFp64>::kTypeString == baseType) {
return decodeType<TypeKind::kFp64>(nullable);
} else if (
TypeTraits<TypeKind::kString>::kTypeString == baseType ||
TypeTraits<TypeKind::kString>::kSignature == baseType) {
return decodeType<TypeKind::kString>(nullable);
} else if (TypeTraits<TypeKind::kBinary>::kTypeString == baseType) {
return decodeType<TypeKind::kBinary>(nullable);
} else if (TypeTraits<TypeKind::kUuid>::kTypeString == baseType) {
return decodeType<TypeKind::kUuid>(nullable);
} else if (TypeTraits<TypeKind::kIntervalYear>::kTypeString == baseType) {
return decodeType<TypeKind::kIntervalYear>(nullable);
} else if (TypeTraits<TypeKind::kIntervalDay>::kTypeString == baseType) {
return decodeType<TypeKind::kIntervalDay>(nullable);
} else if (TypeTraits<TypeKind::kTimestamp>::kTypeString == baseType) {
return decodeType<TypeKind::kTimestamp>(nullable);
} else if (TypeTraits<TypeKind::kTimestampTz>::kTypeString == baseType) {
return decodeType<TypeKind::kTimestampTz>(nullable);
} else if (TypeTraits<TypeKind::kDate>::kTypeString == baseType) {
return decodeType<TypeKind::kDate>(nullable);
} else if (TypeTraits<TypeKind::kTime>::kTypeString == baseType) {
return decodeType<TypeKind::kTime>(nullable);
} else {
bool wildcard = matchingType.rfind("any", 0) == 0;
bool placeholder = !wildcard && !common::NumberUtils::isInteger(rawType);
return std::make_shared<const StringLiteral>(
rawType, wildcard, placeholder);
}
} else {
bool nullable =
leftAngleBracketPos > 1 && matchingType[leftAngleBracketPos - 1] == '?';
const auto& rightAngleBracketPos = rawType.rfind('>');
const auto& baseTypePos = nullable
? std::min(leftAngleBracketPos, questionMaskPos)
: leftAngleBracketPos;
const auto& baseType = matchingType.substr(0, baseTypePos);
std::vector<ParameterizedTypePtr> nestedTypes;
auto prevPos = leftAngleBracketPos + 1;
auto commaPos = findNextComma(rawType, prevPos);
while (commaPos != std::string::npos) {
auto token = rawType.substr(prevPos, commaPos - prevPos);
nestedTypes.emplace_back(decode(token, isParameterized));
prevPos = commaPos + 1;
commaPos = findNextComma(rawType, prevPos);
}
auto token = rawType.substr(prevPos, rightAngleBracketPos - prevPos);
nestedTypes.emplace_back(decode(token, isParameterized));
if (TypeTraits<TypeKind::kList>::kTypeString == baseType) {
return decodeType<TypeKind::kList>(
isParameterized, nullable, nestedTypes);
} else if (TypeTraits<TypeKind::kMap>::kTypeString == baseType) {
return decodeType<TypeKind::kMap>(isParameterized, nullable, nestedTypes);
} else if (TypeTraits<TypeKind::kStruct>::kTypeString == baseType) {
return decodeType<TypeKind::kStruct>(
isParameterized, nullable, nestedTypes);
} else if (TypeTraits<TypeKind::kDecimal>::kTypeString == baseType) {
return decodeType<TypeKind::kDecimal>(
isParameterized, nullable, nestedTypes);
} else if (TypeTraits<TypeKind::kVarchar>::kTypeString == baseType) {
return decodeType<TypeKind::kVarchar>(
isParameterized, nullable, nestedTypes);
} else if (TypeTraits<TypeKind::kFixedChar>::kTypeString == baseType) {
return decodeType<TypeKind::kFixedChar>(
isParameterized, nullable, nestedTypes);
} else if (TypeTraits<TypeKind::kFixedBinary>::kTypeString == baseType) {
return decodeType<TypeKind::kFixedBinary>(
isParameterized, nullable, nestedTypes);
} else {
SUBSTRAIT_UNSUPPORTED("Unsupported type: " + rawType);
}
}
}
std::string Decimal::signature() const {
std::stringstream sign;
sign << TypeBase::signature();
sign << "<" << precision_ << "," << scale_ << ">";
return sign.str();
}
bool Decimal::isMatch(
const std::shared_ptr<const ParameterizedType>& type) const {
if (auto decimalType = std::dynamic_pointer_cast<const Decimal>(type)) {
return TypeBase::isMatch(type) && precision_ == decimalType->precision() &&
scale_ == decimalType->scale();
}
return false;
}
std::string FixedBinary::signature() const {
std::stringstream sign;
sign << TypeBase::signature();
sign << "<" << length() << ">";
return sign.str();
}
bool FixedBinary::isMatch(
const std::shared_ptr<const ParameterizedType>& type) const {
if (auto fBinaryType = std::dynamic_pointer_cast<const FixedBinary>(type)) {
return TypeBase::isMatch(type) && length_ == fBinaryType->length();
}
return false;
}
std::string FixedChar::signature() const {
std::stringstream sign;
sign << TypeBase::signature();
sign << "<" << length() << ">";
return sign.str();
}
bool FixedChar::isMatch(
const std::shared_ptr<const ParameterizedType>& type) const {
if (auto fBinaryType = std::dynamic_pointer_cast<const FixedChar>(type)) {
return TypeBase::isMatch(type) && length_ == fBinaryType->length();
}
return false;
}
std::string Varchar::signature() const {
std::stringstream sign;
sign << TypeBase::signature();
sign << "<" << length() << ">";
return sign.str();
}
bool Varchar::isMatch(
const std::shared_ptr<const ParameterizedType>& type) const {
if (auto varcharType = std::dynamic_pointer_cast<const Varchar>(type)) {
return TypeBase::isMatch(type) && length_ == varcharType->length();
}
return false;
}
std::string List::signature() const {
std::stringstream sign;
sign << TypeBase::signature();
sign << "<" << elementType_->signature() << ">";
return sign.str();
}
bool List::isMatch(const std::shared_ptr<const ParameterizedType>& type) const {
if (auto listType = std::dynamic_pointer_cast<const List>(type)) {
return TypeBase::isMatch(type) &&
elementType()->isMatch(listType->elementType());
}
return false;
}
std::string Struct::signature() const {
std::stringstream sign;
sign << TypeBase::signature();
sign << "<";
for (auto it = children_.begin(); it != children_.end(); ++it) {
const auto& typeSign = (*it)->signature();
if (it == children_.end() - 1) {
sign << typeSign;
} else {
sign << typeSign << ",";
}
}
sign << ">";
return sign.str();
}
bool Struct::isMatch(
const std::shared_ptr<const ParameterizedType>& type) const {
if (auto structType = std::dynamic_pointer_cast<const Struct>(type)) {
bool sameSize = structType->children_.size() == children_.size();
if (sameSize) {
for (int i = 0; i < children_.size(); i++) {
if (!children_[i]->isMatch(structType->children_[i])) {
return false;
}
}
return true;
}
}
return false;
}
std::string Map::signature() const {
std::stringstream sign;
sign << TypeBase::signature();
sign << "<";
sign << keyType()->signature();
sign << ",";
sign << valueType()->signature();
sign << ">";
return sign.str();
}
bool Map::isMatch(const std::shared_ptr<const ParameterizedType>& type) const {
if (auto mapType = std::dynamic_pointer_cast<const Map>(type)) {
return TypeBase::isMatch(type) && keyType()->isMatch(mapType->keyType()) &&
valueType()->isMatch(mapType->valueType());
}
return false;
}
std::string ParameterizedFixedBinary::signature() const {
std::stringstream sign;
sign << TypeTraits<TypeKind::kFixedBinary>::kSignature;
sign << "<" << length_->value() << ">";
return sign.str();
}
bool ParameterizedFixedBinary::isMatch(
const std::shared_ptr<const ParameterizedType>& type) const {
if (auto parameterizedFixedBinary =
std::dynamic_pointer_cast<const ParameterizedFixedBinary>(type)) {
return length()->isMatch(parameterizedFixedBinary->length()) &&
nullMatch(type);
}
return false;
}
std::string ParameterizedDecimal::signature() const {
std::stringstream sign;
sign << TypeTraits<TypeKind::kDecimal>::kSignature;
sign << "<" << precision_->value() << "," << scale_->value() << ">";
return sign.str();
}
bool ParameterizedDecimal::isMatch(
const std::shared_ptr<const ParameterizedType>& type) const {
if (auto decimal = std::dynamic_pointer_cast<const Decimal>(type)) {
return nullMatch(type);
}
return false;
}
std::string ParameterizedFixedChar::signature() const {
std::stringstream sign;
sign << TypeTraits<TypeKind::kFixedChar>::kSignature;
sign << "<" << length_->value() << ">";
return sign.str();
}
bool ParameterizedFixedChar::isMatch(
const std::shared_ptr<const ParameterizedType>& type) const {
if (auto fixedChar = std::dynamic_pointer_cast<const class FixedChar>(type)) {
return nullMatch(type);
}
return false;
}
std::string ParameterizedVarchar::signature() const {
std::stringstream sign;
sign << TypeTraits<TypeKind::kVarchar>::kSignature;
sign << "<" << length_->value() << ">";
return sign.str();
}
bool ParameterizedVarchar::isMatch(
const std::shared_ptr<const ParameterizedType>& type) const {
if (auto varchar = std::dynamic_pointer_cast<const Varchar>(type)) {
return nullMatch(type);
}
return false;
}
std::string ParameterizedList::signature() const {
std::stringstream sign;
sign << TypeTraits<TypeKind::kList>::kSignature;
sign << "<" << elementType()->signature() << ">";
return sign.str();
}
bool ParameterizedList::isMatch(
const std::shared_ptr<const ParameterizedType>& type) const {
if (auto list = std::dynamic_pointer_cast<const List>(type)) {
return elementType()->isMatch(list->elementType()) && nullMatch(type);
}
return false;
}
std::string ParameterizedStruct::signature() const {
std::stringstream sign;
sign << TypeTraits<TypeKind::kStruct>::kSignature;
sign << "<";
for (auto it = children_.begin(); it != children_.end(); ++it) {
const auto& typeSign = (*it)->signature();
if (it == children_.end() - 1) {
sign << typeSign;
} else {
sign << typeSign << ",";
}
}
sign << ">";
return sign.str();
}
bool ParameterizedStruct::isMatch(
const std::shared_ptr<const ParameterizedType>& type) const {
if (auto structType = std::dynamic_pointer_cast<const Struct>(type)) {
bool sameSize = structType->children().size() == children_.size();
if (sameSize) {
for (int i = 0; i < children_.size(); i++) {
if (!children_[i]->isMatch(structType->children()[i])) {
return false;
}
}
return nullMatch(type);
}
}
return false;
}
std::string ParameterizedMap::signature() const {
std::stringstream sign;
sign << TypeTraits<TypeKind::kMap>::kSignature;
sign << "<";
if (keyType() != nullptr) {
sign << keyType()->signature();
}
sign << ",";
if (valueType() != nullptr) {
sign << valueType()->signature();
}
sign << ">";
return sign.str();
}
bool ParameterizedMap::isMatch(
const std::shared_ptr<const ParameterizedType>& type) const {
if (auto mapType = std::dynamic_pointer_cast<const Map>(type)) {
return keyType()->isMatch(mapType->keyType()) &&
valueType()->isMatch(mapType->valueType()) && nullMatch(type);
}
return false;
}
std::shared_ptr<const ScalarType<TypeKind::kBool>> boolean() {
return std::make_shared<const ScalarType<TypeKind::kBool>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kI8>> tinyint() {
return std::make_shared<const ScalarType<TypeKind::kI8>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kI16>> smallint() {
return std::make_shared<const ScalarType<TypeKind::kI16>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kI32>> integer() {
return std::make_shared<const ScalarType<TypeKind::kI32>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kI64>> bigint() {
return std::make_shared<const ScalarType<TypeKind::kI64>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kFp32>> float4() {
return std::make_shared<const ScalarType<TypeKind::kFp32>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kFp64>> float8() {
return std::make_shared<const ScalarType<TypeKind::kFp64>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kString>> string() {
return std::make_shared<const ScalarType<TypeKind::kString>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kBinary>> binary() {
return std::make_shared<const ScalarType<TypeKind::kBinary>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kTimestamp>> timestamp() {
return std::make_shared<const ScalarType<TypeKind::kTimestamp>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kDate>> date() {
return std::make_shared<const ScalarType<TypeKind::kDate>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kTime>> time() {
return std::make_shared<const ScalarType<TypeKind::kTime>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kIntervalYear>> intervalYear() {
return std::make_shared<const ScalarType<TypeKind::kIntervalYear>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kIntervalDay>> intervalDay() {
return std::make_shared<const ScalarType<TypeKind::kIntervalDay>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kTimestampTz>> timestampTz() {
return std::make_shared<const ScalarType<TypeKind::kTimestampTz>>(false);
}
std::shared_ptr<const ScalarType<TypeKind::kUuid>> uuid() {
return std::make_shared<const ScalarType<TypeKind::kUuid>>(false);
}
std::shared_ptr<const Decimal> decimal(int precision, int scale) {
return std::make_shared<const Decimal>(precision, scale, false);
}
std::shared_ptr<const Varchar> varchar(int len) {
return std::make_shared<const Varchar>(len, false);
}
std::shared_ptr<const class FixedChar> fchar(int len) {
return std::make_shared<const class FixedChar>(len, false);
}
std::shared_ptr<const class FixedBinary> fixedBinary(int len) {
return std::make_shared<const class FixedBinary>(len, false);
}
std::shared_ptr<const List> list(const TypePtr& elementType) {
return std::make_shared<const List>(elementType, false);
}
std::shared_ptr<const Map> map(
const TypePtr& keyType,
const TypePtr& valueType) {
return std::make_shared<const Map>(keyType, valueType, false);
}
std::shared_ptr<const Struct> row(const std::vector<TypePtr>& children) {
return std::make_shared<const Struct>(children, false);
}
std::shared_ptr<const class FixedChar> fixedChar(int len) {
return std::make_shared<const class FixedChar>(len);
}
bool StringLiteral::isMatch(
const std::shared_ptr<const ParameterizedType>& type) const {
if (isWildcard()) {
return true;
} else {
if (auto stringLiteral =
std::dynamic_pointer_cast<const StringLiteral>(type)) {
return value_ == stringLiteral->value_;
}
return false;
}
}
bool StringLiteral::isInteger() const {
return common::NumberUtils::isInteger(value_);
}
} // namespace io::substrait