aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/public/udf/udf_value.h
blob: 8c2a01acde3f16bd8e8366596b1da63bcfe66d67 (plain) (blame)
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
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
#pragma once

#include "udf_allocator.h"
#include "udf_string.h"
#include "udf_terminator.h"
#include "udf_type_size_check.h"
#include "udf_version.h"

#include <yql/essentials/public/decimal/yql_decimal.h>

#include <util/system/yassert.h> // FAIL, VERIFY_DEBUG
#include <util/generic/utility.h> // Min, Max
#include <util/generic/yexception.h> // Y_ENSURE
#include <util/system/compiler.h> // Y_FORCE_INLINE

#include <algorithm>
#include <type_traits>

class IOutputStream;

namespace NYql {
namespace NUdf {

class TUnboxedValue;
class TUnboxedValuePod;
class TOpaqueListRepresentation;
class IValueBuilder;

enum class EFetchStatus : ui32 {
    Ok,
    Finish,
    Yield
};

///////////////////////////////////////////////////////////////////////////////
// IApplyContext
///////////////////////////////////////////////////////////////////////////////
class IApplyContext {
public:
    virtual ~IApplyContext() = default;
};

UDF_ASSERT_TYPE_SIZE(IApplyContext, 8);

///////////////////////////////////////////////////////////////////////////////
// IBoxedValue
///////////////////////////////////////////////////////////////////////////////
class IBoxedValue;
using IBoxedValuePtr = TRefCountedPtr<IBoxedValue>;

class IBoxedValue1
{
friend struct TBoxedValueAccessor;
public:
    inline bool IsCompatibleTo(ui16 compatibilityVersion) const {
        return AbiCompatibility_ >= compatibilityVersion;
    }

    IBoxedValue1(const IBoxedValue1&) = delete;
    IBoxedValue1& operator=(const IBoxedValue1&) = delete;
    IBoxedValue1() = default;

    virtual ~IBoxedValue1() = default;

private:
    // List accessors
    virtual bool HasFastListLength() const = 0;
    virtual ui64 GetListLength() const = 0;
    virtual ui64 GetEstimatedListLength() const = 0;
    virtual TUnboxedValue GetListIterator() const = 0;
    // customization of list operations, may return null @{
    virtual const TOpaqueListRepresentation* GetListRepresentation() const = 0;
    virtual IBoxedValuePtr ReverseListImpl(const IValueBuilder& builder) const = 0;
    virtual IBoxedValuePtr SkipListImpl(const IValueBuilder& builder, ui64 count) const = 0;
    virtual IBoxedValuePtr TakeListImpl(const IValueBuilder& builder, ui64 count) const = 0;
    virtual IBoxedValuePtr ToIndexDictImpl(const IValueBuilder& builder) const = 0;
    // @}

    // Dict accessors
    virtual ui64 GetDictLength() const = 0;
    virtual TUnboxedValue GetDictIterator() const = 0;
    virtual TUnboxedValue GetKeysIterator() const = 0; // May return empty.
    virtual TUnboxedValue GetPayloadsIterator() const = 0; // May return empty.
    virtual bool Contains(const TUnboxedValuePod& key) const = 0;
    virtual TUnboxedValue Lookup(const TUnboxedValuePod& key) const = 0;

    // Tuple or Struct accessors
    virtual TUnboxedValue GetElement(ui32 index) const = 0;
    virtual const TUnboxedValue* GetElements() const = 0; // May return nullptr.

    // Callable accessors
    virtual TUnboxedValue Run(const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const = 0;

    // Resource accessor
    virtual TStringRef GetResourceTag() const = 0;
    virtual void* GetResource() = 0;

    virtual bool HasListItems() const = 0;
    virtual bool HasDictItems() const = 0;

    virtual ui32 GetVariantIndex() const = 0;
    virtual TUnboxedValue GetVariantItem() const = 0;

    // Either Done/Yield with empty result or Ready with non-empty result should be returned
    virtual EFetchStatus Fetch(TUnboxedValue& result) = 0;

    // Any iterator.
    virtual bool Skip() = 0;
    // List iterator.
    virtual bool Next(TUnboxedValue& value) = 0;
    // Dict iterator.
    virtual bool NextPair(TUnboxedValue& key, TUnboxedValue& payload) = 0;

    virtual void Apply(IApplyContext& context) const = 0;

public:
    // reference counting
    inline void Ref() noexcept;
    inline void UnRef() noexcept;
    inline void ReleaseRef() noexcept;
    inline void DeleteUnreferenced() noexcept;
    inline i32 RefCount() const noexcept;
    inline void SetUserMark(ui8 mark) noexcept;
    inline ui8 UserMark() const noexcept;
    inline i32 LockRef() noexcept;
    inline void UnlockRef(i32 prev) noexcept;

private:
    i32 Refs_ = 0;
    const ui16 AbiCompatibility_ = MakeAbiCompatibilityVersion(UDF_ABI_VERSION_MAJOR, UDF_ABI_VERSION_MINOR);
    ui8 UserMark_ = 0;
    const ui8 Reserved_ = 0;
};

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 3)
class IBoxedValue2 : public IBoxedValue1 {
friend struct TBoxedValueAccessor;
private:
    // Save/Load state
    virtual ui32 GetTraverseCount() const = 0;
    virtual TUnboxedValue GetTraverseItem(ui32 index) const = 0;
    virtual TUnboxedValue Save() const = 0;
    virtual void Load(const TStringRef& state) = 0;
};
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 11)
class IBoxedValue3 : public IBoxedValue2 {
friend struct TBoxedValueAccessor;
private:
    virtual void Push(const TUnboxedValuePod& value) = 0;
};
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 12)
class IBoxedValue4 : public IBoxedValue3 {
friend struct TBoxedValueAccessor;
private:
    virtual bool IsSortedDict() const = 0;
};
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 19)
class IBoxedValue5 : public IBoxedValue4 {
friend struct TBoxedValueAccessor;
private:
    virtual void Unused1() = 0;
    virtual void Unused2() = 0;
    virtual void Unused3() = 0;
    virtual void Unused4() = 0;
    virtual void Unused5() = 0;
    virtual void Unused6() = 0;
};
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 30)
class IBoxedValue6 : public IBoxedValue5 {
friend struct TBoxedValueAccessor;
private:
    virtual EFetchStatus WideFetch(TUnboxedValue* result, ui32 width) = 0;
};
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 36)
class IBoxedValue7 : public IBoxedValue6 {
friend struct TBoxedValueAccessor;
private:
    virtual bool Load2(const TUnboxedValue& state) = 0;
};
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 36)
class IBoxedValue : public IBoxedValue7 {
protected:
    IBoxedValue();
};
#elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 30)
class IBoxedValue : public IBoxedValue6 {
protected:
    IBoxedValue();
};
#elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 19)
class IBoxedValue : public IBoxedValue5 {
protected:
    IBoxedValue();
};
#elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 12)
class IBoxedValue : public IBoxedValue4 {
protected:
    IBoxedValue();
};
#elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 11)
class IBoxedValue : public IBoxedValue3 {
protected:
    IBoxedValue();
};
#elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 3)
class IBoxedValue : public IBoxedValue2 {
protected:
    IBoxedValue();
};
#else
class IBoxedValue : public IBoxedValue1 {
protected:
    IBoxedValue();
};
#endif

UDF_ASSERT_TYPE_SIZE(IBoxedValue, 16);

UDF_ASSERT_TYPE_SIZE(IBoxedValuePtr, 8);

///////////////////////////////////////////////////////////////////////////////
// TBoxedValueAccessor
///////////////////////////////////////////////////////////////////////////////
struct TBoxedValueAccessor
{
#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 36)

#define METHOD_MAP(xx) \
    xx(HasFastListLength) \
    xx(GetListLength) \
    xx(GetEstimatedListLength) \
    xx(GetListIterator) \
    xx(GetListRepresentation) \
    xx(ReverseListImpl) \
    xx(SkipListImpl) \
    xx(TakeListImpl) \
    xx(ToIndexDictImpl) \
    xx(GetDictLength) \
    xx(GetDictIterator) \
    xx(GetKeysIterator) \
    xx(GetPayloadsIterator) \
    xx(Contains) \
    xx(Lookup) \
    xx(GetElement) \
    xx(GetElements) \
    xx(Run) \
    xx(GetResourceTag) \
    xx(GetResource) \
    xx(HasListItems) \
    xx(HasDictItems) \
    xx(GetVariantIndex) \
    xx(GetVariantItem) \
    xx(Fetch) \
    xx(Skip) \
    xx(Next) \
    xx(NextPair) \
    xx(Apply) \
    xx(GetTraverseCount) \
    xx(GetTraverseItem) \
    xx(Save) \
    xx(Load) \
    xx(Push) \
    xx(IsSortedDict) \
    xx(Unused1) \
    xx(Unused2) \
    xx(Unused3) \
    xx(Unused4) \
    xx(Unused5) \
    xx(Unused6) \
    xx(WideFetch) \
    xx(Load2)

#elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 30)

#define METHOD_MAP(xx) \
    xx(HasFastListLength) \
    xx(GetListLength) \
    xx(GetEstimatedListLength) \
    xx(GetListIterator) \
    xx(GetListRepresentation) \
    xx(ReverseListImpl) \
    xx(SkipListImpl) \
    xx(TakeListImpl) \
    xx(ToIndexDictImpl) \
    xx(GetDictLength) \
    xx(GetDictIterator) \
    xx(GetKeysIterator) \
    xx(GetPayloadsIterator) \
    xx(Contains) \
    xx(Lookup) \
    xx(GetElement) \
    xx(GetElements) \
    xx(Run) \
    xx(GetResourceTag) \
    xx(GetResource) \
    xx(HasListItems) \
    xx(HasDictItems) \
    xx(GetVariantIndex) \
    xx(GetVariantItem) \
    xx(Fetch) \
    xx(Skip) \
    xx(Next) \
    xx(NextPair) \
    xx(Apply) \
    xx(GetTraverseCount) \
    xx(GetTraverseItem) \
    xx(Save) \
    xx(Load) \
    xx(Push) \
    xx(IsSortedDict) \
    xx(Unused1) \
    xx(Unused2) \
    xx(Unused3) \
    xx(Unused4) \
    xx(Unused5) \
    xx(Unused6) \
    xx(WideFetch) \

#elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 19)

#define METHOD_MAP(xx) \
    xx(HasFastListLength) \
    xx(GetListLength) \
    xx(GetEstimatedListLength) \
    xx(GetListIterator) \
    xx(GetListRepresentation) \
    xx(ReverseListImpl) \
    xx(SkipListImpl) \
    xx(TakeListImpl) \
    xx(ToIndexDictImpl) \
    xx(GetDictLength) \
    xx(GetDictIterator) \
    xx(GetKeysIterator) \
    xx(GetPayloadsIterator) \
    xx(Contains) \
    xx(Lookup) \
    xx(GetElement) \
    xx(GetElements) \
    xx(Run) \
    xx(GetResourceTag) \
    xx(GetResource) \
    xx(HasListItems) \
    xx(HasDictItems) \
    xx(GetVariantIndex) \
    xx(GetVariantItem) \
    xx(Fetch) \
    xx(Skip) \
    xx(Next) \
    xx(NextPair) \
    xx(Apply) \
    xx(GetTraverseCount) \
    xx(GetTraverseItem) \
    xx(Save) \
    xx(Load) \
    xx(Push) \
    xx(IsSortedDict) \
    xx(Unused1) \
    xx(Unused2) \
    xx(Unused3) \
    xx(Unused4) \
    xx(Unused5) \
    xx(Unused6)

#elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 12)

#define METHOD_MAP(xx) \
    xx(HasFastListLength) \
    xx(GetListLength) \
    xx(GetEstimatedListLength) \
    xx(GetListIterator) \
    xx(GetListRepresentation) \
    xx(ReverseListImpl) \
    xx(SkipListImpl) \
    xx(TakeListImpl) \
    xx(ToIndexDictImpl) \
    xx(GetDictLength) \
    xx(GetDictIterator) \
    xx(GetKeysIterator) \
    xx(GetPayloadsIterator) \
    xx(Contains) \
    xx(Lookup) \
    xx(GetElement) \
    xx(GetElements) \
    xx(Run) \
    xx(GetResourceTag) \
    xx(GetResource) \
    xx(HasListItems) \
    xx(HasDictItems) \
    xx(GetVariantIndex) \
    xx(GetVariantItem) \
    xx(Fetch) \
    xx(Skip) \
    xx(Next) \
    xx(NextPair) \
    xx(Apply) \
    xx(GetTraverseCount) \
    xx(GetTraverseItem) \
    xx(Save) \
    xx(Load) \
    xx(Push) \
    xx(IsSortedDict)

#elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 11)

#define METHOD_MAP(xx) \
    xx(HasFastListLength) \
    xx(GetListLength) \
    xx(GetEstimatedListLength) \
    xx(GetListIterator) \
    xx(GetListRepresentation) \
    xx(ReverseListImpl) \
    xx(SkipListImpl) \
    xx(TakeListImpl) \
    xx(ToIndexDictImpl) \
    xx(GetDictLength) \
    xx(GetDictIterator) \
    xx(GetKeysIterator) \
    xx(GetPayloadsIterator) \
    xx(Contains) \
    xx(Lookup) \
    xx(GetElement) \
    xx(GetElements) \
    xx(Run) \
    xx(GetResourceTag) \
    xx(GetResource) \
    xx(HasListItems) \
    xx(HasDictItems) \
    xx(GetVariantIndex) \
    xx(GetVariantItem) \
    xx(Fetch) \
    xx(Skip) \
    xx(Next) \
    xx(NextPair) \
    xx(Apply) \
    xx(GetTraverseCount) \
    xx(GetTraverseItem) \
    xx(Save) \
    xx(Load) \
    xx(Push)

#elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 3)

#define METHOD_MAP(xx) \
    xx(HasFastListLength) \
    xx(GetListLength) \
    xx(GetEstimatedListLength) \
    xx(GetListIterator) \
    xx(GetListRepresentation) \
    xx(ReverseListImpl) \
    xx(SkipListImpl) \
    xx(TakeListImpl) \
    xx(ToIndexDictImpl) \
    xx(GetDictLength) \
    xx(GetDictIterator) \
    xx(GetKeysIterator) \
    xx(GetPayloadsIterator) \
    xx(Contains) \
    xx(Lookup) \
    xx(GetElement) \
    xx(GetElements) \
    xx(Run) \
    xx(GetResourceTag) \
    xx(GetResource) \
    xx(HasListItems) \
    xx(HasDictItems) \
    xx(GetVariantIndex) \
    xx(GetVariantItem) \
    xx(Fetch) \
    xx(Skip) \
    xx(Next) \
    xx(NextPair) \
    xx(Apply) \
    xx(GetTraverseCount) \
    xx(GetTraverseItem) \
    xx(Save) \
    xx(Load)

#else

#define METHOD_MAP(xx) \
    xx(HasFastListLength) \
    xx(GetListLength) \
    xx(GetEstimatedListLength) \
    xx(GetListIterator) \
    xx(GetListRepresentation) \
    xx(ReverseListImpl) \
    xx(SkipListImpl) \
    xx(TakeListImpl) \
    xx(ToIndexDictImpl) \
    xx(GetDictLength) \
    xx(GetDictIterator) \
    xx(GetKeysIterator) \
    xx(GetPayloadsIterator) \
    xx(Contains) \
    xx(Lookup) \
    xx(GetElement) \
    xx(GetElements) \
    xx(Run) \
    xx(GetResourceTag) \
    xx(GetResource) \
    xx(HasListItems) \
    xx(HasDictItems) \
    xx(GetVariantIndex) \
    xx(GetVariantItem) \
    xx(Fetch) \
    xx(Skip) \
    xx(Next) \
    xx(NextPair) \
    xx(Apply)

#endif

    enum class EMethod : ui32 {
#define MAP_HANDLER(xx) xx,
        METHOD_MAP(MAP_HANDLER)
#undef MAP_HANDLER
    };

    template<typename Method>
    static uintptr_t GetMethodPtr(Method method) {
        uintptr_t ret;
        memcpy(&ret, &method, sizeof(uintptr_t));
        return ret;
    }

    static uintptr_t GetMethodPtr(EMethod method) {
        switch (method) {
#define MAP_HANDLER(xx) case EMethod::xx: return GetMethodPtr(&IBoxedValue::xx);
            METHOD_MAP(MAP_HANDLER)
#undef MAP_HANDLER
        }

        Y_ABORT("unknown method");
    }

    template<EMethod Method> static uintptr_t GetMethodPtr();

    // List accessors
    static inline bool HasFastListLength(const IBoxedValue& value);
    static inline ui64 GetListLength(const IBoxedValue& value);
    static inline ui64 GetEstimatedListLength(const IBoxedValue& value);
    static inline TUnboxedValue GetListIterator(const IBoxedValue& value);
    // customization of list operations, may return null @{
    static inline const TOpaqueListRepresentation* GetListRepresentation(const IBoxedValue& value);
    static inline IBoxedValuePtr ReverseListImpl(const IBoxedValue& value, const IValueBuilder& builder);
    static inline IBoxedValuePtr SkipListImpl(const IBoxedValue& value, const IValueBuilder& builder, ui64 count);
    static inline IBoxedValuePtr TakeListImpl(const IBoxedValue& value, const IValueBuilder& builder, ui64 count);
    static inline IBoxedValuePtr ToIndexDictImpl(const IBoxedValue& value, const IValueBuilder& builder);
    // @}

    // Dict accessors
    static inline ui64 GetDictLength(const IBoxedValue& value);
    static inline TUnboxedValue GetDictIterator(const IBoxedValue& value);
    static inline TUnboxedValue GetKeysIterator(const IBoxedValue& value);
    static inline TUnboxedValue GetPayloadsIterator(const IBoxedValue& value);
    static inline bool Contains(const IBoxedValue& value, const TUnboxedValuePod& key);
    static inline TUnboxedValue Lookup(const IBoxedValue& value, const TUnboxedValuePod& key);

    // Tuple or Struct accessors
    static inline TUnboxedValue GetElement(const IBoxedValue& value, ui32 index);
    static inline const TUnboxedValue* GetElements(const IBoxedValue& value);

    // Callable accessors
    static inline TUnboxedValue Run(const IBoxedValue& value, const IValueBuilder* valueBuilder, const TUnboxedValuePod* args);

    // Resource accessor
    static inline TStringRef GetResourceTag(const IBoxedValue& value);
    static inline void* GetResource(IBoxedValue& value);

    static inline bool HasListItems(const IBoxedValue& value);
    static inline bool HasDictItems(const IBoxedValue& value);

    static inline ui32 GetVariantIndex(const IBoxedValue& value);
    static inline TUnboxedValue GetVariantItem(const IBoxedValue& value);

    static inline EFetchStatus Fetch(IBoxedValue& value, TUnboxedValue& result);

    // Any iterator.
    static inline bool Skip(IBoxedValue& value);
    // List iterator.
    static inline bool Next(IBoxedValue& value, TUnboxedValue& result);
    // Dict iterator.
    static inline bool NextPair(IBoxedValue& value, TUnboxedValue& key, TUnboxedValue& payload);

    static inline void Apply(IBoxedValue& value, IApplyContext& context);

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 3)
    // Save/Load state
    static inline ui32 GetTraverseCount(const IBoxedValue& value);
    static inline TUnboxedValue GetTraverseItem(const IBoxedValue& value, ui32 index);
    static inline TUnboxedValue Save(const IBoxedValue& value);
    static inline void Load(IBoxedValue& value, const TStringRef& state);
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 11)
    static inline void Push(IBoxedValue& value, const TUnboxedValuePod& data);
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 12)
    static inline bool IsSortedDict(IBoxedValue& value);
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 30)
    static inline EFetchStatus WideFetch(IBoxedValue& value, TUnboxedValue* result, ui32 width);
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 36)
    static inline bool Load2(IBoxedValue& value, const TUnboxedValue& data);
#endif
};

#define MAP_HANDLER(xx) template<> inline uintptr_t TBoxedValueAccessor::GetMethodPtr<TBoxedValueAccessor::EMethod::xx>() { return GetMethodPtr(&IBoxedValue::xx); }
METHOD_MAP(MAP_HANDLER)
#undef MAP_HANDLER

#undef METHOD_MAP

///////////////////////////////////////////////////////////////////////////////
// TBoxedValue
///////////////////////////////////////////////////////////////////////////////
class TBoxedValueBase: public IBoxedValue {
private:
    // List accessors
    bool HasFastListLength() const override;
    ui64 GetListLength() const override;
    ui64 GetEstimatedListLength() const override;
    TUnboxedValue GetListIterator() const override;
    const TOpaqueListRepresentation* GetListRepresentation() const override;
    IBoxedValuePtr ReverseListImpl(const IValueBuilder& builder) const override;
    IBoxedValuePtr SkipListImpl(const IValueBuilder& builder, ui64 count) const override;
    IBoxedValuePtr TakeListImpl(const IValueBuilder& builder, ui64 count) const override;
    IBoxedValuePtr ToIndexDictImpl(const IValueBuilder& builder) const override;

    // Dict accessors
    ui64 GetDictLength() const override;
    TUnboxedValue GetDictIterator() const override;
    TUnboxedValue GetKeysIterator() const override;
    TUnboxedValue GetPayloadsIterator() const override;
    bool Contains(const TUnboxedValuePod& key) const override;
    TUnboxedValue Lookup(const TUnboxedValuePod& key) const override;

    // Tuple or Struct accessors
    TUnboxedValue GetElement(ui32 index) const override;
    const TUnboxedValue* GetElements() const override;

    // Callable accessors
    TUnboxedValue Run(const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const override;

    // Resource accessors
    TStringRef GetResourceTag() const override;
    void* GetResource() override;

    bool HasListItems() const override;
    bool HasDictItems() const override;

    ui32 GetVariantIndex() const override;
    TUnboxedValue GetVariantItem() const override;

    EFetchStatus Fetch(TUnboxedValue& result) override;

    // Any iterator.
    bool Skip() override;
    // List iterator.
    bool Next(TUnboxedValue& value) override;
    // Dict iterator.
    bool NextPair(TUnboxedValue& key, TUnboxedValue& payload) override;

    void Apply(IApplyContext& context) const override;

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 3)
    // Save/Load state
    ui32 GetTraverseCount() const override;
    TUnboxedValue GetTraverseItem(ui32 index) const override;
    TUnboxedValue Save() const override;
    void Load(const TStringRef& state) override;
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 11)
    void Push(const TUnboxedValuePod& value) override;
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 12)
    bool IsSortedDict() const override;
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 19)
    void Unused1() override;
    void Unused2() override;
    void Unused3() override;
    void Unused4() override;
    void Unused5() override;
    void Unused6() override;
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 30)
    EFetchStatus WideFetch(TUnboxedValue* result, ui32 width) override;
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 36)
    bool Load2(const TUnboxedValue& value) override;
#endif
};

class TBoxedValueLink: public TBoxedValueBase
{
public:
    void Link(TBoxedValueLink* root);
    void Unlink();
    void InitLinks() { Left = Right = this; }
    TBoxedValueLink* GetLeft() const { return Left; }
    TBoxedValueLink* GetRight() const { return Right; }
private:
    TBoxedValueLink *Left = nullptr;
    TBoxedValueLink *Right = nullptr;
};

class TBoxedValue: public TBoxedValueLink, public TWithUdfAllocator
{
public:
    TBoxedValue();
    ~TBoxedValue();
};

class TManagedBoxedValue: public TBoxedValueBase, public TWithUdfAllocator
{
};

UDF_ASSERT_TYPE_SIZE(TBoxedValue, 32);

///////////////////////////////////////////////////////////////////////////////
// TUnboxedValuePod
///////////////////////////////////////////////////////////////////////////////

struct TRawEmbeddedValue {
    char Buffer[0xE];
    ui8 Size;
    ui8 Meta;
};

struct TRawBoxedValue {
    IBoxedValue* Value;
    ui8 Reserved[7];
    ui8 Meta;
};

struct TRawStringValue {
    static constexpr ui32 OffsetLimit = 1 << 24;

    TStringValue::TData* Value;
    ui32 Size;
    union {
        struct {
            ui8 Skip[3];
            ui8 Meta;
        };
        ui32 Offset;
    };
};

class TUnboxedValuePod
{
friend class TUnboxedValue;
public:
    enum class EMarkers : ui8 {
        Empty = 0,
        Embedded,
        String,
        Boxed,
    };

    inline TUnboxedValuePod() noexcept = default;
    inline ~TUnboxedValuePod() noexcept = default;

    inline TUnboxedValuePod(const TUnboxedValuePod& value) noexcept = default;
    inline TUnboxedValuePod(TUnboxedValuePod&& value) noexcept = default;

    inline TUnboxedValuePod& operator=(const TUnboxedValuePod& value) noexcept = default;
    inline TUnboxedValuePod& operator=(TUnboxedValuePod&& value) noexcept = default;

    inline TUnboxedValuePod(TUnboxedValue&&) = delete;
    inline TUnboxedValuePod& operator=(TUnboxedValue&&) = delete;

    template <typename T, typename = std::enable_if_t<TPrimitiveDataType<T>::Result>>
    inline explicit TUnboxedValuePod(T value);
    inline explicit TUnboxedValuePod(IBoxedValuePtr&& value);
    inline explicit TUnboxedValuePod(TStringValue&& value, ui32 size = Max<ui32>(), ui32 offset = 0U);

    void Dump(IOutputStream& out) const;
    // meta information
    inline explicit operator bool() const { return bool(Raw); }

    inline bool HasValue() const { return EMarkers::Empty != Raw.GetMarkers(); }

    inline bool IsString() const { return EMarkers::String == Raw.GetMarkers(); }
    inline bool IsBoxed() const { return EMarkers::Boxed == Raw.GetMarkers(); }
    inline bool IsEmbedded() const { return EMarkers::Embedded == Raw.GetMarkers(); }

    // Data accessors
    template <typename T, typename = std::enable_if_t<TPrimitiveDataType<T>::Result || std::is_same_v<T, NYql::NDecimal::TInt128>>>
    inline T Get() const;
    template <typename T, typename = std::enable_if_t<TPrimitiveDataType<T>::Result>>
    inline T GetOrDefault(T ifEmpty) const;

    inline explicit TUnboxedValuePod(NYql::NDecimal::TInt128 value);
    inline explicit TUnboxedValuePod(NYql::NDecimal::TUint128 value);
    inline NYql::NDecimal::TInt128 GetInt128() const;
    inline NYql::NDecimal::TUint128 GetUint128() const;

    inline const void* GetRawPtr() const;
    inline void* GetRawPtr();

    inline TStringRef AsStringRef() const&;
    inline TMutableStringRef AsStringRef() &;
    void AsStringRef() && = delete;

    inline TStringValue AsStringValue() const;
    inline IBoxedValuePtr AsBoxed() const;
    inline TStringValue::TData* AsRawStringValue() const;
    inline IBoxedValue* AsRawBoxed() const;
    inline bool UniqueBoxed() const;

    // special values
    inline static TUnboxedValuePod Void();
    inline static TUnboxedValuePod Zero();
    inline static TUnboxedValuePod Embedded(ui8 size);
    inline static TUnboxedValuePod Embedded(const TStringRef& value);
    inline static TUnboxedValuePod Invalid();
    inline static TUnboxedValuePod MakeFinish();
    inline static TUnboxedValuePod MakeYield();
    inline bool IsInvalid() const;
    inline bool IsFinish() const;
    inline bool IsYield() const;
    inline bool IsSpecial() const;

    inline TUnboxedValuePod MakeOptional() const;
    inline TUnboxedValuePod GetOptionalValue() const;

    template<bool IsOptional> inline TUnboxedValuePod GetOptionalValueIf() const;
    template<bool IsOptional> inline TUnboxedValuePod MakeOptionalIf() const;

    // List accessors
    inline bool HasFastListLength() const;
    inline ui64 GetListLength() const;
    inline ui64 GetEstimatedListLength() const;
    inline TUnboxedValue GetListIterator() const;
    inline bool HasListItems() const;
#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 11)
    inline void Push(const TUnboxedValuePod& value) const;
#endif

    // Dict accessors
    inline ui64 GetDictLength() const;
    inline TUnboxedValue GetDictIterator() const;
    inline TUnboxedValue GetKeysIterator() const;
    inline TUnboxedValue GetPayloadsIterator() const;

    inline bool Contains(const TUnboxedValuePod& key) const;
    inline TUnboxedValue Lookup(const TUnboxedValuePod& key) const;
    inline bool HasDictItems() const;

    // Tuple or Struct accessors
    inline TUnboxedValue GetElement(ui32 index) const;
    inline const TUnboxedValue* GetElements() const;

    // Callable accessors
    inline TUnboxedValue Run(const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const;

    // Resource accessors
    inline TStringRef GetResourceTag() const;
    inline void* GetResource() const;

    inline ui32 GetVariantIndex() const;
    inline TUnboxedValue GetVariantItem() const;

    inline EFetchStatus Fetch(TUnboxedValue& result) const;

    // Any iterator.
    inline bool Skip() const;
    // List iterator.
    inline bool Next(TUnboxedValue& value) const;
    // Dict iterator.
    inline bool NextPair(TUnboxedValue& key, TUnboxedValue& payload) const;

    inline void Apply(IApplyContext& context) const;

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 3)
    // Save/Load state
    inline ui32 GetTraverseCount() const;
    inline TUnboxedValue GetTraverseItem(ui32 index) const;
    inline TUnboxedValue Save() const;
    inline void Load(const TStringRef& state);
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 12)
    inline bool IsSortedDict() const;
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 30)
    inline EFetchStatus WideFetch(TUnboxedValue *result, ui32 width) const;
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 36)
    inline bool Load2(const TUnboxedValue& value);
#endif

    inline bool TryMakeVariant(ui32 index);

    inline void SetTimezoneId(ui16 id);
    inline ui16 GetTimezoneId() const;

protected:
    union TRaw {
        ui64 Halfs[2] = {0, 0};

        TRawEmbeddedValue Embedded;
        
        TRawBoxedValue Boxed;
        
        TRawStringValue String;

        struct {
            union {
                #define FIELD(type) type type##_;
                PRIMITIVE_VALUE_TYPES(FIELD);
                #undef FIELD
                const void* Void;
                ui64 Count;
            };
            union {
                ui64 FullMeta;
                struct {
                    ui16 TimezoneId;
                    ui8 Reserved[4];
                    ui8 Size;
                    ui8 Meta;
                };
            };
        } Simple;

        EMarkers GetMarkers() const {
            return static_cast<EMarkers>(0x3 & Simple.Meta);
        }

        ui8 GetIndex() const {
            return Simple.Meta >> 2;
        }

        explicit operator bool() const { return Simple.FullMeta | Simple.Count; }
    } Raw;

public:
    inline void Ref() const noexcept;
    inline void UnRef() const noexcept;
    inline void ReleaseRef() const noexcept;
    inline void DeleteUnreferenced() const noexcept;
    inline i32 LockRef() const noexcept;
    inline void UnlockRef(i32 prev) const noexcept;
    inline i32 RefCount() const noexcept;

    static constexpr ui32 InternalBufferSize = sizeof(TRaw::Embedded.Buffer);
    static constexpr ui32 OffsetLimit = TRawStringValue::OffsetLimit;
};

UDF_ASSERT_TYPE_SIZE(TUnboxedValuePod, 16);

static_assert(std::is_trivially_destructible<TUnboxedValuePod>::value, "Incompatible with LLVM codegeneration!");
static_assert(std::is_trivially_copy_assignable<TUnboxedValuePod>::value, "Incompatible with LLVM codegeneration!");
static_assert(std::is_trivially_move_assignable<TUnboxedValuePod>::value, "Incompatible with LLVM codegeneration!");
static_assert(std::is_trivially_copy_constructible<TUnboxedValuePod>::value, "Incompatible with LLVM codegeneration!");
static_assert(std::is_trivially_move_constructible<TUnboxedValuePod>::value, "Incompatible with LLVM codegeneration!");

//////////////////////////////////////////////////////////////////////////////
// TUnboxedValue
///////////////////////////////////////////////////////////////////////////////
class TUnboxedValue : public TUnboxedValuePod
{
public:
    inline TUnboxedValue() noexcept = default;
    inline ~TUnboxedValue() noexcept;

    inline TUnboxedValue(const TUnboxedValuePod& value) noexcept;
    inline TUnboxedValue(TUnboxedValuePod&& value) noexcept;

    inline TUnboxedValue(const TUnboxedValue& value) noexcept;
    inline TUnboxedValue(TUnboxedValue&& value) noexcept;

    inline TUnboxedValue& operator=(const TUnboxedValue& value) noexcept;
    inline TUnboxedValue& operator=(TUnboxedValue&& value) noexcept;

    inline TUnboxedValuePod Release() noexcept;

    inline void Clear() noexcept;

    using TAllocator = TStdAllocatorForUdf<TUnboxedValue>;
};

UDF_ASSERT_TYPE_SIZE(TUnboxedValue, 16);

///////////////////////////////////////////////////////////////////////////////
// TBoxedResource
///////////////////////////////////////////////////////////////////////////////
template <typename TResourceData, const char* ResourceTag>
class TBoxedResource: public TBoxedValue
{
public:
    template <typename... Args>
    inline TBoxedResource(Args&&... args)
        : ResourceData_(std::forward<Args>(args)...)
    {
    }

    inline TStringRef GetResourceTag() const override {
        return TStringRef(ResourceTag, std::strlen(ResourceTag));
    }

    inline void* GetResource() override {
        return Get();
    }

    inline TResourceData* Get() {
        return &ResourceData_;
    }

    inline static void Validate(const TUnboxedValuePod& value) {
        Y_DEBUG_ABORT_UNLESS(value.GetResourceTag() == TStringRef(ResourceTag, std::strlen(ResourceTag)));
    }

private:
    TResourceData ResourceData_;
};

#define INCLUDE_UDF_VALUE_INL_H
#include "udf_value_inl.h"
#undef INCLUDE_UDF_VALUE_INL_H

} // namespace NUdf
} // namespace NYql

template<>
inline void Out<NYql::NUdf::TUnboxedValuePod>(class IOutputStream &o, const NYql::NUdf::TUnboxedValuePod& value);

template<>
inline void Out<NYql::NUdf::TUnboxedValue>(class IOutputStream &o, const NYql::NUdf::TUnboxedValue& value);

template<>
inline void Out<NYql::NUdf::EFetchStatus>(class IOutputStream &o, NYql::NUdf::EFetchStatus value);

template<>
inline void Out<NYql::NUdf::TStringRef>(class IOutputStream &o, const NYql::NUdf::TStringRef& value);

#include "udf_terminator.h"
#include <util/stream/output.h>
#include <tuple>

namespace NYql {
namespace NUdf {

//////////////////////////////////////////////////////////////////////////////
// TBoxedValue
//////////////////////////////////////////////////////////////////////////////
inline bool TBoxedValueBase::HasFastListLength() const
{
    Y_ABORT("Not implemented");
}

inline ui64 TBoxedValueBase::GetListLength() const
{
    Y_ABORT("Not implemented");
}

inline ui64 TBoxedValueBase::GetEstimatedListLength() const
{
    Y_ABORT("Not implemented");
}

inline const TOpaqueListRepresentation* TBoxedValueBase::GetListRepresentation() const {
    return nullptr;
}

inline IBoxedValuePtr TBoxedValueBase::ReverseListImpl(const IValueBuilder& builder) const {
    Y_UNUSED(builder);
    return nullptr;
}

inline IBoxedValuePtr TBoxedValueBase::SkipListImpl(const IValueBuilder& builder, ui64 count) const {
    Y_UNUSED(builder);
    Y_UNUSED(count);
    return nullptr;
}

inline IBoxedValuePtr TBoxedValueBase::TakeListImpl(const IValueBuilder& builder, ui64 count) const {
    Y_UNUSED(builder);
    Y_UNUSED(count);
    return nullptr;
}

inline IBoxedValuePtr TBoxedValueBase::ToIndexDictImpl(const IValueBuilder& builder) const {
    Y_UNUSED(builder);
    return nullptr;
}

inline ui64 TBoxedValueBase::GetDictLength() const
{
    Y_ABORT("Not implemented");
}

inline TBoxedValue::TBoxedValue()
{
    UdfRegisterObject(this);
}

inline TBoxedValue::~TBoxedValue()
{
    UdfUnregisterObject(this);
}

inline void TBoxedValueLink::Link(TBoxedValueLink* root) {
    Left = root;
    Right = root->Right;
    Right->Left = Left->Right = this;
}

inline void TBoxedValueLink::Unlink() {
    std::tie(Right->Left, Left->Right) = std::make_pair(Left, Right);
    Left = Right = nullptr;
}

inline TUnboxedValue TBoxedValueBase::GetDictIterator() const
{
    Y_ABORT("Not implemented");
}

inline TUnboxedValue TBoxedValueBase::GetListIterator() const
{
    Y_ABORT("Not implemented");
}

inline TUnboxedValue TBoxedValueBase::GetKeysIterator() const
{
    Y_ABORT("Not implemented");
}

inline TUnboxedValue TBoxedValueBase::GetPayloadsIterator() const
{
    Y_ABORT("Not implemented");
}

inline bool TBoxedValueBase::Skip()
{
    TUnboxedValue stub;
    return Next(stub);
}

inline bool TBoxedValueBase::Next(TUnboxedValue&)
{
    Y_ABORT("Not implemented");
}

inline bool TBoxedValueBase::NextPair(TUnboxedValue&, TUnboxedValue&)
{
    Y_ABORT("Not implemented");
}

inline TUnboxedValue TBoxedValueBase::GetElement(ui32 index) const
{
    Y_UNUSED(index);
    Y_ABORT("Not implemented");
}

inline const TUnboxedValue* TBoxedValueBase::GetElements() const
{
    return nullptr;
}

inline void TBoxedValueBase::Apply(IApplyContext&) const
{
    Y_ABORT("Not implemented");
}

inline TStringRef TBoxedValueBase::GetResourceTag() const {
    Y_ABORT("Not implemented");
}

inline void* TBoxedValueBase::GetResource()
{
    Y_ABORT("Not implemented");
}

inline bool TBoxedValueBase::HasListItems() const {
    Y_ABORT("Not implemented");
}

inline bool TBoxedValueBase::HasDictItems() const {
    Y_ABORT("Not implemented");
}

inline ui32 TBoxedValueBase::GetVariantIndex() const {
    Y_ABORT("Not implemented");
}

inline bool TBoxedValueBase::Contains(const TUnboxedValuePod& key) const
{
    Y_UNUSED(key);
    Y_ABORT("Not implemented");
}

inline TUnboxedValue TBoxedValueBase::Lookup(const TUnboxedValuePod& key) const
{
    Y_UNUSED(key);
    Y_ABORT("Not implemented");
}

inline TUnboxedValue TBoxedValueBase::Run(const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const
{
    Y_UNUSED(valueBuilder);
    Y_UNUSED(args);
    Y_ABORT("Not implemented");
}

inline TUnboxedValue TBoxedValueBase::GetVariantItem() const {
    Y_ABORT("Not implemented");
}

inline EFetchStatus TBoxedValueBase::Fetch(TUnboxedValue& result) {
    Y_UNUSED(result);
    Y_ABORT("Not implemented");
}

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 3)
inline ui32 TBoxedValueBase::GetTraverseCount() const {
    Y_ABORT("Not implemented");
    return 0;
}

inline TUnboxedValue TBoxedValueBase::GetTraverseItem(ui32 index) const {
    Y_UNUSED(index);
    Y_ABORT("Not implemented");
}

inline TUnboxedValue TBoxedValueBase::Save() const {
    Y_ABORT("Not implemented");
}

inline void TBoxedValueBase::Load(const TStringRef& state) {
    Y_UNUSED(state);
    Y_ABORT("Not implemented");
}
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 11)
inline void TBoxedValueBase::Push(const TUnboxedValuePod& value) {
    Y_UNUSED(value);
    Y_ABORT("Not implemented");
}
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 12)
inline bool TBoxedValueBase::IsSortedDict() const {
    Y_ABORT("Not implemented");
}
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 19)
inline void TBoxedValueBase::Unused1() {
    Y_ABORT("Not implemented");
}

inline void TBoxedValueBase::Unused2() {
    Y_ABORT("Not implemented");
}

inline void TBoxedValueBase::Unused3() {
    Y_ABORT("Not implemented");
}

inline void TBoxedValueBase::Unused4() {
    Y_ABORT("Not implemented");
}

inline void TBoxedValueBase::Unused5() {
    Y_ABORT("Not implemented");
}

inline void TBoxedValueBase::Unused6() {
    Y_ABORT("Not implemented");
}
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 30)
inline EFetchStatus TBoxedValueBase::WideFetch(TUnboxedValue *result, ui32 width) {
    Y_UNUSED(result);
    Y_UNUSED(width);
    Y_ABORT("Not implemented");
}
#endif

#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 36)
inline bool TBoxedValueBase::Load2(const TUnboxedValue& value) {
    Y_UNUSED(value);
    Y_ABORT("Not implemented");
}
#endif

inline void TUnboxedValuePod::Dump(IOutputStream& out) const {
    switch (Raw.GetMarkers()) {
    case EMarkers::Empty:
        out << "Empty, count: " << (i64)Raw.Simple.Count;
        break;
    case EMarkers::Embedded:
        out << "Embedded, size: " << (ui32)Raw.Embedded.Size << ", buffer: " <<
            TString(Raw.Embedded.Buffer, sizeof(Raw.Embedded.Buffer)).Quote();
        break;
    case EMarkers::String: {
        out << "String, size: " << Raw.String.Size << ", offset: " << (Raw.String.Offset & 0xffffff) << ", buffer: ";
        auto ref = AsStringRef();
        out << TString(ref.Data(), ref.Size()).Quote();
        break;
    }
    case EMarkers::Boxed:
        out << "Boxed, pointer: " << (void*)Raw.Boxed.Value;
        break;
    }
}

} // namespace NUdf
} // namespace NYql

template<>
inline void Out<NYql::NUdf::TUnboxedValuePod>(class IOutputStream &o, const NYql::NUdf::TUnboxedValuePod& value) {
    value.Dump(o);
}

template<>
inline void Out<NYql::NUdf::TUnboxedValue>(class IOutputStream &o, const NYql::NUdf::TUnboxedValue& value) {
    value.Dump(o);
}

template<>
inline void Out<NYql::NUdf::EFetchStatus>(class IOutputStream &o, NYql::NUdf::EFetchStatus value) {
    switch (value) {
    case NYql::NUdf::EFetchStatus::Ok:
        o << "Ok";
        break;
    case NYql::NUdf::EFetchStatus::Yield:
        o << "Yield";
        break;
    case NYql::NUdf::EFetchStatus::Finish:
        o << "Finish";
        break;
    }
}

template<>
inline void Out<NYql::NUdf::TStringRef>(class IOutputStream &o, const NYql::NUdf::TStringRef& value) {
    o << TStringBuf(value.Data(), value.Size());
}