udf_value.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  1. #pragma once
  2. #include "udf_allocator.h"
  3. #include "udf_string.h"
  4. #include "udf_terminator.h"
  5. #include "udf_type_size_check.h"
  6. #include "udf_version.h"
  7. #include <yql/essentials/public/decimal/yql_decimal.h>
  8. #include <util/system/yassert.h> // FAIL, VERIFY_DEBUG
  9. #include <util/generic/utility.h> // Min, Max
  10. #include <util/generic/yexception.h> // Y_ENSURE
  11. #include <util/system/compiler.h> // Y_FORCE_INLINE
  12. #include <algorithm>
  13. #include <type_traits>
  14. class IOutputStream;
  15. namespace NYql {
  16. namespace NUdf {
  17. class TUnboxedValue;
  18. class TUnboxedValuePod;
  19. class TOpaqueListRepresentation;
  20. class IValueBuilder;
  21. enum class EFetchStatus : ui32 {
  22. Ok,
  23. Finish,
  24. Yield
  25. };
  26. ///////////////////////////////////////////////////////////////////////////////
  27. // IApplyContext
  28. ///////////////////////////////////////////////////////////////////////////////
  29. class IApplyContext {
  30. public:
  31. virtual ~IApplyContext() = default;
  32. };
  33. UDF_ASSERT_TYPE_SIZE(IApplyContext, 8);
  34. ///////////////////////////////////////////////////////////////////////////////
  35. // IBoxedValue
  36. ///////////////////////////////////////////////////////////////////////////////
  37. class IBoxedValue;
  38. using IBoxedValuePtr = TRefCountedPtr<IBoxedValue>;
  39. class IBoxedValue1
  40. {
  41. friend struct TBoxedValueAccessor;
  42. public:
  43. inline bool IsCompatibleTo(ui16 compatibilityVersion) const {
  44. return AbiCompatibility_ >= compatibilityVersion;
  45. }
  46. IBoxedValue1(const IBoxedValue1&) = delete;
  47. IBoxedValue1& operator=(const IBoxedValue1&) = delete;
  48. IBoxedValue1() = default;
  49. virtual ~IBoxedValue1() = default;
  50. private:
  51. // List accessors
  52. virtual bool HasFastListLength() const = 0;
  53. virtual ui64 GetListLength() const = 0;
  54. virtual ui64 GetEstimatedListLength() const = 0;
  55. virtual TUnboxedValue GetListIterator() const = 0;
  56. // customization of list operations, may return null @{
  57. virtual const TOpaqueListRepresentation* GetListRepresentation() const = 0;
  58. virtual IBoxedValuePtr ReverseListImpl(const IValueBuilder& builder) const = 0;
  59. virtual IBoxedValuePtr SkipListImpl(const IValueBuilder& builder, ui64 count) const = 0;
  60. virtual IBoxedValuePtr TakeListImpl(const IValueBuilder& builder, ui64 count) const = 0;
  61. virtual IBoxedValuePtr ToIndexDictImpl(const IValueBuilder& builder) const = 0;
  62. // @}
  63. // Dict accessors
  64. virtual ui64 GetDictLength() const = 0;
  65. virtual TUnboxedValue GetDictIterator() const = 0;
  66. virtual TUnboxedValue GetKeysIterator() const = 0; // May return empty.
  67. virtual TUnboxedValue GetPayloadsIterator() const = 0; // May return empty.
  68. virtual bool Contains(const TUnboxedValuePod& key) const = 0;
  69. virtual TUnboxedValue Lookup(const TUnboxedValuePod& key) const = 0;
  70. // Tuple or Struct accessors
  71. virtual TUnboxedValue GetElement(ui32 index) const = 0;
  72. virtual const TUnboxedValue* GetElements() const = 0; // May return nullptr.
  73. // Callable accessors
  74. virtual TUnboxedValue Run(const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const = 0;
  75. // Resource accessor
  76. virtual TStringRef GetResourceTag() const = 0;
  77. virtual void* GetResource() = 0;
  78. virtual bool HasListItems() const = 0;
  79. virtual bool HasDictItems() const = 0;
  80. virtual ui32 GetVariantIndex() const = 0;
  81. virtual TUnboxedValue GetVariantItem() const = 0;
  82. // Either Done/Yield with empty result or Ready with non-empty result should be returned
  83. virtual EFetchStatus Fetch(TUnboxedValue& result) = 0;
  84. // Any iterator.
  85. virtual bool Skip() = 0;
  86. // List iterator.
  87. virtual bool Next(TUnboxedValue& value) = 0;
  88. // Dict iterator.
  89. virtual bool NextPair(TUnboxedValue& key, TUnboxedValue& payload) = 0;
  90. virtual void Apply(IApplyContext& context) const = 0;
  91. public:
  92. // reference counting
  93. inline void Ref() noexcept;
  94. inline void UnRef() noexcept;
  95. inline void ReleaseRef() noexcept;
  96. inline void DeleteUnreferenced() noexcept;
  97. inline i32 RefCount() const noexcept;
  98. inline void SetUserMark(ui8 mark) noexcept;
  99. inline ui8 UserMark() const noexcept;
  100. inline i32 LockRef() noexcept;
  101. inline void UnlockRef(i32 prev) noexcept;
  102. private:
  103. i32 Refs_ = 0;
  104. const ui16 AbiCompatibility_ = MakeAbiCompatibilityVersion(UDF_ABI_VERSION_MAJOR, UDF_ABI_VERSION_MINOR);
  105. ui8 UserMark_ = 0;
  106. const ui8 Reserved_ = 0;
  107. };
  108. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 3)
  109. class IBoxedValue2 : public IBoxedValue1 {
  110. friend struct TBoxedValueAccessor;
  111. private:
  112. // Save/Load state
  113. virtual ui32 GetTraverseCount() const = 0;
  114. virtual TUnboxedValue GetTraverseItem(ui32 index) const = 0;
  115. virtual TUnboxedValue Save() const = 0;
  116. virtual void Load(const TStringRef& state) = 0;
  117. };
  118. #endif
  119. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 11)
  120. class IBoxedValue3 : public IBoxedValue2 {
  121. friend struct TBoxedValueAccessor;
  122. private:
  123. virtual void Push(const TUnboxedValuePod& value) = 0;
  124. };
  125. #endif
  126. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 12)
  127. class IBoxedValue4 : public IBoxedValue3 {
  128. friend struct TBoxedValueAccessor;
  129. private:
  130. virtual bool IsSortedDict() const = 0;
  131. };
  132. #endif
  133. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 19)
  134. class IBoxedValue5 : public IBoxedValue4 {
  135. friend struct TBoxedValueAccessor;
  136. private:
  137. virtual void Unused1() = 0;
  138. virtual void Unused2() = 0;
  139. virtual void Unused3() = 0;
  140. virtual void Unused4() = 0;
  141. virtual void Unused5() = 0;
  142. virtual void Unused6() = 0;
  143. };
  144. #endif
  145. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 30)
  146. class IBoxedValue6 : public IBoxedValue5 {
  147. friend struct TBoxedValueAccessor;
  148. private:
  149. virtual EFetchStatus WideFetch(TUnboxedValue* result, ui32 width) = 0;
  150. };
  151. #endif
  152. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 36)
  153. class IBoxedValue7 : public IBoxedValue6 {
  154. friend struct TBoxedValueAccessor;
  155. private:
  156. virtual bool Load2(const TUnboxedValue& state) = 0;
  157. };
  158. #endif
  159. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 36)
  160. class IBoxedValue : public IBoxedValue7 {
  161. protected:
  162. IBoxedValue();
  163. };
  164. #elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 30)
  165. class IBoxedValue : public IBoxedValue6 {
  166. protected:
  167. IBoxedValue();
  168. };
  169. #elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 19)
  170. class IBoxedValue : public IBoxedValue5 {
  171. protected:
  172. IBoxedValue();
  173. };
  174. #elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 12)
  175. class IBoxedValue : public IBoxedValue4 {
  176. protected:
  177. IBoxedValue();
  178. };
  179. #elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 11)
  180. class IBoxedValue : public IBoxedValue3 {
  181. protected:
  182. IBoxedValue();
  183. };
  184. #elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 3)
  185. class IBoxedValue : public IBoxedValue2 {
  186. protected:
  187. IBoxedValue();
  188. };
  189. #else
  190. class IBoxedValue : public IBoxedValue1 {
  191. protected:
  192. IBoxedValue();
  193. };
  194. #endif
  195. UDF_ASSERT_TYPE_SIZE(IBoxedValue, 16);
  196. UDF_ASSERT_TYPE_SIZE(IBoxedValuePtr, 8);
  197. ///////////////////////////////////////////////////////////////////////////////
  198. // TBoxedValueAccessor
  199. ///////////////////////////////////////////////////////////////////////////////
  200. struct TBoxedValueAccessor
  201. {
  202. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 36)
  203. #define METHOD_MAP(xx) \
  204. xx(HasFastListLength) \
  205. xx(GetListLength) \
  206. xx(GetEstimatedListLength) \
  207. xx(GetListIterator) \
  208. xx(GetListRepresentation) \
  209. xx(ReverseListImpl) \
  210. xx(SkipListImpl) \
  211. xx(TakeListImpl) \
  212. xx(ToIndexDictImpl) \
  213. xx(GetDictLength) \
  214. xx(GetDictIterator) \
  215. xx(GetKeysIterator) \
  216. xx(GetPayloadsIterator) \
  217. xx(Contains) \
  218. xx(Lookup) \
  219. xx(GetElement) \
  220. xx(GetElements) \
  221. xx(Run) \
  222. xx(GetResourceTag) \
  223. xx(GetResource) \
  224. xx(HasListItems) \
  225. xx(HasDictItems) \
  226. xx(GetVariantIndex) \
  227. xx(GetVariantItem) \
  228. xx(Fetch) \
  229. xx(Skip) \
  230. xx(Next) \
  231. xx(NextPair) \
  232. xx(Apply) \
  233. xx(GetTraverseCount) \
  234. xx(GetTraverseItem) \
  235. xx(Save) \
  236. xx(Load) \
  237. xx(Push) \
  238. xx(IsSortedDict) \
  239. xx(Unused1) \
  240. xx(Unused2) \
  241. xx(Unused3) \
  242. xx(Unused4) \
  243. xx(Unused5) \
  244. xx(Unused6) \
  245. xx(WideFetch) \
  246. xx(Load2)
  247. #elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 30)
  248. #define METHOD_MAP(xx) \
  249. xx(HasFastListLength) \
  250. xx(GetListLength) \
  251. xx(GetEstimatedListLength) \
  252. xx(GetListIterator) \
  253. xx(GetListRepresentation) \
  254. xx(ReverseListImpl) \
  255. xx(SkipListImpl) \
  256. xx(TakeListImpl) \
  257. xx(ToIndexDictImpl) \
  258. xx(GetDictLength) \
  259. xx(GetDictIterator) \
  260. xx(GetKeysIterator) \
  261. xx(GetPayloadsIterator) \
  262. xx(Contains) \
  263. xx(Lookup) \
  264. xx(GetElement) \
  265. xx(GetElements) \
  266. xx(Run) \
  267. xx(GetResourceTag) \
  268. xx(GetResource) \
  269. xx(HasListItems) \
  270. xx(HasDictItems) \
  271. xx(GetVariantIndex) \
  272. xx(GetVariantItem) \
  273. xx(Fetch) \
  274. xx(Skip) \
  275. xx(Next) \
  276. xx(NextPair) \
  277. xx(Apply) \
  278. xx(GetTraverseCount) \
  279. xx(GetTraverseItem) \
  280. xx(Save) \
  281. xx(Load) \
  282. xx(Push) \
  283. xx(IsSortedDict) \
  284. xx(Unused1) \
  285. xx(Unused2) \
  286. xx(Unused3) \
  287. xx(Unused4) \
  288. xx(Unused5) \
  289. xx(Unused6) \
  290. xx(WideFetch) \
  291. #elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 19)
  292. #define METHOD_MAP(xx) \
  293. xx(HasFastListLength) \
  294. xx(GetListLength) \
  295. xx(GetEstimatedListLength) \
  296. xx(GetListIterator) \
  297. xx(GetListRepresentation) \
  298. xx(ReverseListImpl) \
  299. xx(SkipListImpl) \
  300. xx(TakeListImpl) \
  301. xx(ToIndexDictImpl) \
  302. xx(GetDictLength) \
  303. xx(GetDictIterator) \
  304. xx(GetKeysIterator) \
  305. xx(GetPayloadsIterator) \
  306. xx(Contains) \
  307. xx(Lookup) \
  308. xx(GetElement) \
  309. xx(GetElements) \
  310. xx(Run) \
  311. xx(GetResourceTag) \
  312. xx(GetResource) \
  313. xx(HasListItems) \
  314. xx(HasDictItems) \
  315. xx(GetVariantIndex) \
  316. xx(GetVariantItem) \
  317. xx(Fetch) \
  318. xx(Skip) \
  319. xx(Next) \
  320. xx(NextPair) \
  321. xx(Apply) \
  322. xx(GetTraverseCount) \
  323. xx(GetTraverseItem) \
  324. xx(Save) \
  325. xx(Load) \
  326. xx(Push) \
  327. xx(IsSortedDict) \
  328. xx(Unused1) \
  329. xx(Unused2) \
  330. xx(Unused3) \
  331. xx(Unused4) \
  332. xx(Unused5) \
  333. xx(Unused6)
  334. #elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 12)
  335. #define METHOD_MAP(xx) \
  336. xx(HasFastListLength) \
  337. xx(GetListLength) \
  338. xx(GetEstimatedListLength) \
  339. xx(GetListIterator) \
  340. xx(GetListRepresentation) \
  341. xx(ReverseListImpl) \
  342. xx(SkipListImpl) \
  343. xx(TakeListImpl) \
  344. xx(ToIndexDictImpl) \
  345. xx(GetDictLength) \
  346. xx(GetDictIterator) \
  347. xx(GetKeysIterator) \
  348. xx(GetPayloadsIterator) \
  349. xx(Contains) \
  350. xx(Lookup) \
  351. xx(GetElement) \
  352. xx(GetElements) \
  353. xx(Run) \
  354. xx(GetResourceTag) \
  355. xx(GetResource) \
  356. xx(HasListItems) \
  357. xx(HasDictItems) \
  358. xx(GetVariantIndex) \
  359. xx(GetVariantItem) \
  360. xx(Fetch) \
  361. xx(Skip) \
  362. xx(Next) \
  363. xx(NextPair) \
  364. xx(Apply) \
  365. xx(GetTraverseCount) \
  366. xx(GetTraverseItem) \
  367. xx(Save) \
  368. xx(Load) \
  369. xx(Push) \
  370. xx(IsSortedDict)
  371. #elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 11)
  372. #define METHOD_MAP(xx) \
  373. xx(HasFastListLength) \
  374. xx(GetListLength) \
  375. xx(GetEstimatedListLength) \
  376. xx(GetListIterator) \
  377. xx(GetListRepresentation) \
  378. xx(ReverseListImpl) \
  379. xx(SkipListImpl) \
  380. xx(TakeListImpl) \
  381. xx(ToIndexDictImpl) \
  382. xx(GetDictLength) \
  383. xx(GetDictIterator) \
  384. xx(GetKeysIterator) \
  385. xx(GetPayloadsIterator) \
  386. xx(Contains) \
  387. xx(Lookup) \
  388. xx(GetElement) \
  389. xx(GetElements) \
  390. xx(Run) \
  391. xx(GetResourceTag) \
  392. xx(GetResource) \
  393. xx(HasListItems) \
  394. xx(HasDictItems) \
  395. xx(GetVariantIndex) \
  396. xx(GetVariantItem) \
  397. xx(Fetch) \
  398. xx(Skip) \
  399. xx(Next) \
  400. xx(NextPair) \
  401. xx(Apply) \
  402. xx(GetTraverseCount) \
  403. xx(GetTraverseItem) \
  404. xx(Save) \
  405. xx(Load) \
  406. xx(Push)
  407. #elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 3)
  408. #define METHOD_MAP(xx) \
  409. xx(HasFastListLength) \
  410. xx(GetListLength) \
  411. xx(GetEstimatedListLength) \
  412. xx(GetListIterator) \
  413. xx(GetListRepresentation) \
  414. xx(ReverseListImpl) \
  415. xx(SkipListImpl) \
  416. xx(TakeListImpl) \
  417. xx(ToIndexDictImpl) \
  418. xx(GetDictLength) \
  419. xx(GetDictIterator) \
  420. xx(GetKeysIterator) \
  421. xx(GetPayloadsIterator) \
  422. xx(Contains) \
  423. xx(Lookup) \
  424. xx(GetElement) \
  425. xx(GetElements) \
  426. xx(Run) \
  427. xx(GetResourceTag) \
  428. xx(GetResource) \
  429. xx(HasListItems) \
  430. xx(HasDictItems) \
  431. xx(GetVariantIndex) \
  432. xx(GetVariantItem) \
  433. xx(Fetch) \
  434. xx(Skip) \
  435. xx(Next) \
  436. xx(NextPair) \
  437. xx(Apply) \
  438. xx(GetTraverseCount) \
  439. xx(GetTraverseItem) \
  440. xx(Save) \
  441. xx(Load)
  442. #else
  443. #define METHOD_MAP(xx) \
  444. xx(HasFastListLength) \
  445. xx(GetListLength) \
  446. xx(GetEstimatedListLength) \
  447. xx(GetListIterator) \
  448. xx(GetListRepresentation) \
  449. xx(ReverseListImpl) \
  450. xx(SkipListImpl) \
  451. xx(TakeListImpl) \
  452. xx(ToIndexDictImpl) \
  453. xx(GetDictLength) \
  454. xx(GetDictIterator) \
  455. xx(GetKeysIterator) \
  456. xx(GetPayloadsIterator) \
  457. xx(Contains) \
  458. xx(Lookup) \
  459. xx(GetElement) \
  460. xx(GetElements) \
  461. xx(Run) \
  462. xx(GetResourceTag) \
  463. xx(GetResource) \
  464. xx(HasListItems) \
  465. xx(HasDictItems) \
  466. xx(GetVariantIndex) \
  467. xx(GetVariantItem) \
  468. xx(Fetch) \
  469. xx(Skip) \
  470. xx(Next) \
  471. xx(NextPair) \
  472. xx(Apply)
  473. #endif
  474. enum class EMethod : ui32 {
  475. #define MAP_HANDLER(xx) xx,
  476. METHOD_MAP(MAP_HANDLER)
  477. #undef MAP_HANDLER
  478. };
  479. template<typename Method>
  480. static uintptr_t GetMethodPtr(Method method) {
  481. uintptr_t ret;
  482. memcpy(&ret, &method, sizeof(uintptr_t));
  483. return ret;
  484. }
  485. static uintptr_t GetMethodPtr(EMethod method) {
  486. switch (method) {
  487. #define MAP_HANDLER(xx) case EMethod::xx: return GetMethodPtr(&IBoxedValue::xx);
  488. METHOD_MAP(MAP_HANDLER)
  489. #undef MAP_HANDLER
  490. }
  491. Y_ABORT("unknown method");
  492. }
  493. template<EMethod Method> static uintptr_t GetMethodPtr();
  494. // List accessors
  495. static inline bool HasFastListLength(const IBoxedValue& value);
  496. static inline ui64 GetListLength(const IBoxedValue& value);
  497. static inline ui64 GetEstimatedListLength(const IBoxedValue& value);
  498. static inline TUnboxedValue GetListIterator(const IBoxedValue& value);
  499. // customization of list operations, may return null @{
  500. static inline const TOpaqueListRepresentation* GetListRepresentation(const IBoxedValue& value);
  501. static inline IBoxedValuePtr ReverseListImpl(const IBoxedValue& value, const IValueBuilder& builder);
  502. static inline IBoxedValuePtr SkipListImpl(const IBoxedValue& value, const IValueBuilder& builder, ui64 count);
  503. static inline IBoxedValuePtr TakeListImpl(const IBoxedValue& value, const IValueBuilder& builder, ui64 count);
  504. static inline IBoxedValuePtr ToIndexDictImpl(const IBoxedValue& value, const IValueBuilder& builder);
  505. // @}
  506. // Dict accessors
  507. static inline ui64 GetDictLength(const IBoxedValue& value);
  508. static inline TUnboxedValue GetDictIterator(const IBoxedValue& value);
  509. static inline TUnboxedValue GetKeysIterator(const IBoxedValue& value);
  510. static inline TUnboxedValue GetPayloadsIterator(const IBoxedValue& value);
  511. static inline bool Contains(const IBoxedValue& value, const TUnboxedValuePod& key);
  512. static inline TUnboxedValue Lookup(const IBoxedValue& value, const TUnboxedValuePod& key);
  513. // Tuple or Struct accessors
  514. static inline TUnboxedValue GetElement(const IBoxedValue& value, ui32 index);
  515. static inline const TUnboxedValue* GetElements(const IBoxedValue& value);
  516. // Callable accessors
  517. static inline TUnboxedValue Run(const IBoxedValue& value, const IValueBuilder* valueBuilder, const TUnboxedValuePod* args);
  518. // Resource accessor
  519. static inline TStringRef GetResourceTag(const IBoxedValue& value);
  520. static inline void* GetResource(IBoxedValue& value);
  521. static inline bool HasListItems(const IBoxedValue& value);
  522. static inline bool HasDictItems(const IBoxedValue& value);
  523. static inline ui32 GetVariantIndex(const IBoxedValue& value);
  524. static inline TUnboxedValue GetVariantItem(const IBoxedValue& value);
  525. static inline EFetchStatus Fetch(IBoxedValue& value, TUnboxedValue& result);
  526. // Any iterator.
  527. static inline bool Skip(IBoxedValue& value);
  528. // List iterator.
  529. static inline bool Next(IBoxedValue& value, TUnboxedValue& result);
  530. // Dict iterator.
  531. static inline bool NextPair(IBoxedValue& value, TUnboxedValue& key, TUnboxedValue& payload);
  532. static inline void Apply(IBoxedValue& value, IApplyContext& context);
  533. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 3)
  534. // Save/Load state
  535. static inline ui32 GetTraverseCount(const IBoxedValue& value);
  536. static inline TUnboxedValue GetTraverseItem(const IBoxedValue& value, ui32 index);
  537. static inline TUnboxedValue Save(const IBoxedValue& value);
  538. static inline void Load(IBoxedValue& value, const TStringRef& state);
  539. #endif
  540. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 11)
  541. static inline void Push(IBoxedValue& value, const TUnboxedValuePod& data);
  542. #endif
  543. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 12)
  544. static inline bool IsSortedDict(IBoxedValue& value);
  545. #endif
  546. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 30)
  547. static inline EFetchStatus WideFetch(IBoxedValue& value, TUnboxedValue* result, ui32 width);
  548. #endif
  549. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 36)
  550. static inline bool Load2(IBoxedValue& value, const TUnboxedValue& data);
  551. #endif
  552. };
  553. #define MAP_HANDLER(xx) template<> inline uintptr_t TBoxedValueAccessor::GetMethodPtr<TBoxedValueAccessor::EMethod::xx>() { return GetMethodPtr(&IBoxedValue::xx); }
  554. METHOD_MAP(MAP_HANDLER)
  555. #undef MAP_HANDLER
  556. #undef METHOD_MAP
  557. ///////////////////////////////////////////////////////////////////////////////
  558. // TBoxedValue
  559. ///////////////////////////////////////////////////////////////////////////////
  560. class TBoxedValueBase: public IBoxedValue {
  561. private:
  562. // List accessors
  563. bool HasFastListLength() const override;
  564. ui64 GetListLength() const override;
  565. ui64 GetEstimatedListLength() const override;
  566. TUnboxedValue GetListIterator() const override;
  567. const TOpaqueListRepresentation* GetListRepresentation() const override;
  568. IBoxedValuePtr ReverseListImpl(const IValueBuilder& builder) const override;
  569. IBoxedValuePtr SkipListImpl(const IValueBuilder& builder, ui64 count) const override;
  570. IBoxedValuePtr TakeListImpl(const IValueBuilder& builder, ui64 count) const override;
  571. IBoxedValuePtr ToIndexDictImpl(const IValueBuilder& builder) const override;
  572. // Dict accessors
  573. ui64 GetDictLength() const override;
  574. TUnboxedValue GetDictIterator() const override;
  575. TUnboxedValue GetKeysIterator() const override;
  576. TUnboxedValue GetPayloadsIterator() const override;
  577. bool Contains(const TUnboxedValuePod& key) const override;
  578. TUnboxedValue Lookup(const TUnboxedValuePod& key) const override;
  579. // Tuple or Struct accessors
  580. TUnboxedValue GetElement(ui32 index) const override;
  581. const TUnboxedValue* GetElements() const override;
  582. // Callable accessors
  583. TUnboxedValue Run(const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const override;
  584. // Resource accessors
  585. TStringRef GetResourceTag() const override;
  586. void* GetResource() override;
  587. bool HasListItems() const override;
  588. bool HasDictItems() const override;
  589. ui32 GetVariantIndex() const override;
  590. TUnboxedValue GetVariantItem() const override;
  591. EFetchStatus Fetch(TUnboxedValue& result) override;
  592. // Any iterator.
  593. bool Skip() override;
  594. // List iterator.
  595. bool Next(TUnboxedValue& value) override;
  596. // Dict iterator.
  597. bool NextPair(TUnboxedValue& key, TUnboxedValue& payload) override;
  598. void Apply(IApplyContext& context) const override;
  599. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 3)
  600. // Save/Load state
  601. ui32 GetTraverseCount() const override;
  602. TUnboxedValue GetTraverseItem(ui32 index) const override;
  603. TUnboxedValue Save() const override;
  604. void Load(const TStringRef& state) override;
  605. #endif
  606. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 11)
  607. void Push(const TUnboxedValuePod& value) override;
  608. #endif
  609. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 12)
  610. bool IsSortedDict() const override;
  611. #endif
  612. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 19)
  613. void Unused1() override;
  614. void Unused2() override;
  615. void Unused3() override;
  616. void Unused4() override;
  617. void Unused5() override;
  618. void Unused6() override;
  619. #endif
  620. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 30)
  621. EFetchStatus WideFetch(TUnboxedValue* result, ui32 width) override;
  622. #endif
  623. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 36)
  624. bool Load2(const TUnboxedValue& value) override;
  625. #endif
  626. };
  627. class TBoxedValueLink: public TBoxedValueBase
  628. {
  629. public:
  630. void Link(TBoxedValueLink* root);
  631. void Unlink();
  632. void InitLinks() { Left = Right = this; }
  633. TBoxedValueLink* GetLeft() const { return Left; }
  634. TBoxedValueLink* GetRight() const { return Right; }
  635. private:
  636. TBoxedValueLink *Left = nullptr;
  637. TBoxedValueLink *Right = nullptr;
  638. };
  639. class TBoxedValue: public TBoxedValueLink, public TWithUdfAllocator
  640. {
  641. public:
  642. TBoxedValue();
  643. ~TBoxedValue();
  644. };
  645. class TManagedBoxedValue: public TBoxedValueBase, public TWithUdfAllocator
  646. {
  647. };
  648. UDF_ASSERT_TYPE_SIZE(TBoxedValue, 32);
  649. ///////////////////////////////////////////////////////////////////////////////
  650. // TUnboxedValuePod
  651. ///////////////////////////////////////////////////////////////////////////////
  652. struct TRawEmbeddedValue {
  653. char Buffer[0xE];
  654. ui8 Size;
  655. ui8 Meta;
  656. };
  657. struct TRawBoxedValue {
  658. IBoxedValue* Value;
  659. ui8 Reserved[7];
  660. ui8 Meta;
  661. };
  662. struct TRawStringValue {
  663. static constexpr ui32 OffsetLimit = 1 << 24;
  664. TStringValue::TData* Value;
  665. ui32 Size;
  666. union {
  667. struct {
  668. ui8 Skip[3];
  669. ui8 Meta;
  670. };
  671. ui32 Offset;
  672. };
  673. };
  674. class TUnboxedValuePod
  675. {
  676. friend class TUnboxedValue;
  677. public:
  678. enum class EMarkers : ui8 {
  679. Empty = 0,
  680. Embedded,
  681. String,
  682. Boxed,
  683. };
  684. inline TUnboxedValuePod() noexcept = default;
  685. inline ~TUnboxedValuePod() noexcept = default;
  686. inline TUnboxedValuePod(const TUnboxedValuePod& value) noexcept = default;
  687. inline TUnboxedValuePod(TUnboxedValuePod&& value) noexcept = default;
  688. inline TUnboxedValuePod& operator=(const TUnboxedValuePod& value) noexcept = default;
  689. inline TUnboxedValuePod& operator=(TUnboxedValuePod&& value) noexcept = default;
  690. inline TUnboxedValuePod(TUnboxedValue&&) = delete;
  691. inline TUnboxedValuePod& operator=(TUnboxedValue&&) = delete;
  692. template <typename T, typename = std::enable_if_t<TPrimitiveDataType<T>::Result>>
  693. inline explicit TUnboxedValuePod(T value);
  694. inline explicit TUnboxedValuePod(IBoxedValuePtr&& value);
  695. inline explicit TUnboxedValuePod(TStringValue&& value, ui32 size = Max<ui32>(), ui32 offset = 0U);
  696. void Dump(IOutputStream& out) const;
  697. // meta information
  698. inline explicit operator bool() const { return bool(Raw); }
  699. inline bool HasValue() const { return EMarkers::Empty != Raw.GetMarkers(); }
  700. inline bool IsString() const { return EMarkers::String == Raw.GetMarkers(); }
  701. inline bool IsBoxed() const { return EMarkers::Boxed == Raw.GetMarkers(); }
  702. inline bool IsEmbedded() const { return EMarkers::Embedded == Raw.GetMarkers(); }
  703. // Data accessors
  704. template <typename T, typename = std::enable_if_t<TPrimitiveDataType<T>::Result || std::is_same_v<T, NYql::NDecimal::TInt128>>>
  705. inline T Get() const;
  706. template <typename T, typename = std::enable_if_t<TPrimitiveDataType<T>::Result>>
  707. inline T GetOrDefault(T ifEmpty) const;
  708. inline explicit TUnboxedValuePod(NYql::NDecimal::TInt128 value);
  709. inline explicit TUnboxedValuePod(NYql::NDecimal::TUint128 value);
  710. inline NYql::NDecimal::TInt128 GetInt128() const;
  711. inline NYql::NDecimal::TUint128 GetUint128() const;
  712. inline const void* GetRawPtr() const;
  713. inline void* GetRawPtr();
  714. inline TStringRef AsStringRef() const&;
  715. inline TMutableStringRef AsStringRef() &;
  716. void AsStringRef() && = delete;
  717. inline TStringValue AsStringValue() const;
  718. inline IBoxedValuePtr AsBoxed() const;
  719. inline TStringValue::TData* AsRawStringValue() const;
  720. inline IBoxedValue* AsRawBoxed() const;
  721. inline bool UniqueBoxed() const;
  722. // special values
  723. inline static TUnboxedValuePod Void();
  724. inline static TUnboxedValuePod Zero();
  725. inline static TUnboxedValuePod Embedded(ui8 size);
  726. inline static TUnboxedValuePod Embedded(const TStringRef& value);
  727. inline static TUnboxedValuePod Invalid();
  728. inline static TUnboxedValuePod MakeFinish();
  729. inline static TUnboxedValuePod MakeYield();
  730. inline bool IsInvalid() const;
  731. inline bool IsFinish() const;
  732. inline bool IsYield() const;
  733. inline bool IsSpecial() const;
  734. inline TUnboxedValuePod MakeOptional() const;
  735. inline TUnboxedValuePod GetOptionalValue() const;
  736. template<bool IsOptional> inline TUnboxedValuePod GetOptionalValueIf() const;
  737. template<bool IsOptional> inline TUnboxedValuePod MakeOptionalIf() const;
  738. // List accessors
  739. inline bool HasFastListLength() const;
  740. inline ui64 GetListLength() const;
  741. inline ui64 GetEstimatedListLength() const;
  742. inline TUnboxedValue GetListIterator() const;
  743. inline bool HasListItems() const;
  744. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 11)
  745. inline void Push(const TUnboxedValuePod& value) const;
  746. #endif
  747. // Dict accessors
  748. inline ui64 GetDictLength() const;
  749. inline TUnboxedValue GetDictIterator() const;
  750. inline TUnboxedValue GetKeysIterator() const;
  751. inline TUnboxedValue GetPayloadsIterator() const;
  752. inline bool Contains(const TUnboxedValuePod& key) const;
  753. inline TUnboxedValue Lookup(const TUnboxedValuePod& key) const;
  754. inline bool HasDictItems() const;
  755. // Tuple or Struct accessors
  756. inline TUnboxedValue GetElement(ui32 index) const;
  757. inline const TUnboxedValue* GetElements() const;
  758. // Callable accessors
  759. inline TUnboxedValue Run(const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const;
  760. // Resource accessors
  761. inline TStringRef GetResourceTag() const;
  762. inline void* GetResource() const;
  763. inline ui32 GetVariantIndex() const;
  764. inline TUnboxedValue GetVariantItem() const;
  765. inline EFetchStatus Fetch(TUnboxedValue& result) const;
  766. // Any iterator.
  767. inline bool Skip() const;
  768. // List iterator.
  769. inline bool Next(TUnboxedValue& value) const;
  770. // Dict iterator.
  771. inline bool NextPair(TUnboxedValue& key, TUnboxedValue& payload) const;
  772. inline void Apply(IApplyContext& context) const;
  773. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 3)
  774. // Save/Load state
  775. inline ui32 GetTraverseCount() const;
  776. inline TUnboxedValue GetTraverseItem(ui32 index) const;
  777. inline TUnboxedValue Save() const;
  778. inline void Load(const TStringRef& state);
  779. #endif
  780. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 12)
  781. inline bool IsSortedDict() const;
  782. #endif
  783. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 30)
  784. inline EFetchStatus WideFetch(TUnboxedValue *result, ui32 width) const;
  785. #endif
  786. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 36)
  787. inline bool Load2(const TUnboxedValue& value);
  788. #endif
  789. inline bool TryMakeVariant(ui32 index);
  790. inline void SetTimezoneId(ui16 id);
  791. inline ui16 GetTimezoneId() const;
  792. protected:
  793. union TRaw {
  794. ui64 Halfs[2] = {0, 0};
  795. TRawEmbeddedValue Embedded;
  796. TRawBoxedValue Boxed;
  797. TRawStringValue String;
  798. struct {
  799. union {
  800. #define FIELD(type) type type##_;
  801. PRIMITIVE_VALUE_TYPES(FIELD);
  802. #undef FIELD
  803. const void* Void;
  804. ui64 Count;
  805. };
  806. union {
  807. ui64 FullMeta;
  808. struct {
  809. ui16 TimezoneId;
  810. ui8 Reserved[4];
  811. ui8 Size;
  812. ui8 Meta;
  813. };
  814. };
  815. } Simple;
  816. EMarkers GetMarkers() const {
  817. return static_cast<EMarkers>(0x3 & Simple.Meta);
  818. }
  819. ui8 GetIndex() const {
  820. return Simple.Meta >> 2;
  821. }
  822. explicit operator bool() const { return Simple.FullMeta | Simple.Count; }
  823. } Raw;
  824. public:
  825. inline void Ref() const noexcept;
  826. inline void UnRef() const noexcept;
  827. inline void ReleaseRef() const noexcept;
  828. inline void DeleteUnreferenced() const noexcept;
  829. inline i32 LockRef() const noexcept;
  830. inline void UnlockRef(i32 prev) const noexcept;
  831. inline i32 RefCount() const noexcept;
  832. static constexpr ui32 InternalBufferSize = sizeof(TRaw::Embedded.Buffer);
  833. static constexpr ui32 OffsetLimit = TRawStringValue::OffsetLimit;
  834. };
  835. UDF_ASSERT_TYPE_SIZE(TUnboxedValuePod, 16);
  836. static_assert(std::is_trivially_destructible<TUnboxedValuePod>::value, "Incompatible with LLVM codegeneration!");
  837. static_assert(std::is_trivially_copy_assignable<TUnboxedValuePod>::value, "Incompatible with LLVM codegeneration!");
  838. static_assert(std::is_trivially_move_assignable<TUnboxedValuePod>::value, "Incompatible with LLVM codegeneration!");
  839. static_assert(std::is_trivially_copy_constructible<TUnboxedValuePod>::value, "Incompatible with LLVM codegeneration!");
  840. static_assert(std::is_trivially_move_constructible<TUnboxedValuePod>::value, "Incompatible with LLVM codegeneration!");
  841. //////////////////////////////////////////////////////////////////////////////
  842. // TUnboxedValue
  843. ///////////////////////////////////////////////////////////////////////////////
  844. class TUnboxedValue : public TUnboxedValuePod
  845. {
  846. public:
  847. inline TUnboxedValue() noexcept = default;
  848. inline ~TUnboxedValue() noexcept;
  849. inline TUnboxedValue(const TUnboxedValuePod& value) noexcept;
  850. inline TUnboxedValue(TUnboxedValuePod&& value) noexcept;
  851. inline TUnboxedValue(const TUnboxedValue& value) noexcept;
  852. inline TUnboxedValue(TUnboxedValue&& value) noexcept;
  853. inline TUnboxedValue& operator=(const TUnboxedValue& value) noexcept;
  854. inline TUnboxedValue& operator=(TUnboxedValue&& value) noexcept;
  855. inline TUnboxedValuePod Release() noexcept;
  856. inline void Clear() noexcept;
  857. using TAllocator = TStdAllocatorForUdf<TUnboxedValue>;
  858. };
  859. UDF_ASSERT_TYPE_SIZE(TUnboxedValue, 16);
  860. ///////////////////////////////////////////////////////////////////////////////
  861. // TBoxedResource
  862. ///////////////////////////////////////////////////////////////////////////////
  863. template <typename TResourceData, const char* ResourceTag>
  864. class TBoxedResource: public TBoxedValue
  865. {
  866. public:
  867. template <typename... Args>
  868. inline TBoxedResource(Args&&... args)
  869. : ResourceData_(std::forward<Args>(args)...)
  870. {
  871. }
  872. inline TStringRef GetResourceTag() const override {
  873. return TStringRef(ResourceTag, std::strlen(ResourceTag));
  874. }
  875. inline void* GetResource() override {
  876. return Get();
  877. }
  878. inline TResourceData* Get() {
  879. return &ResourceData_;
  880. }
  881. inline static void Validate(const TUnboxedValuePod& value) {
  882. Y_DEBUG_ABORT_UNLESS(value.GetResourceTag() == TStringRef(ResourceTag, std::strlen(ResourceTag)));
  883. }
  884. private:
  885. TResourceData ResourceData_;
  886. };
  887. #define INCLUDE_UDF_VALUE_INL_H
  888. #include "udf_value_inl.h"
  889. #undef INCLUDE_UDF_VALUE_INL_H
  890. } // namespace NUdf
  891. } // namespace NYql
  892. template<>
  893. inline void Out<NYql::NUdf::TUnboxedValuePod>(class IOutputStream &o, const NYql::NUdf::TUnboxedValuePod& value);
  894. template<>
  895. inline void Out<NYql::NUdf::TUnboxedValue>(class IOutputStream &o, const NYql::NUdf::TUnboxedValue& value);
  896. template<>
  897. inline void Out<NYql::NUdf::EFetchStatus>(class IOutputStream &o, NYql::NUdf::EFetchStatus value);
  898. template<>
  899. inline void Out<NYql::NUdf::TStringRef>(class IOutputStream &o, const NYql::NUdf::TStringRef& value);
  900. #include "udf_terminator.h"
  901. #include <util/stream/output.h>
  902. #include <tuple>
  903. namespace NYql {
  904. namespace NUdf {
  905. //////////////////////////////////////////////////////////////////////////////
  906. // TBoxedValue
  907. //////////////////////////////////////////////////////////////////////////////
  908. inline bool TBoxedValueBase::HasFastListLength() const
  909. {
  910. Y_ABORT("Not implemented");
  911. }
  912. inline ui64 TBoxedValueBase::GetListLength() const
  913. {
  914. Y_ABORT("Not implemented");
  915. }
  916. inline ui64 TBoxedValueBase::GetEstimatedListLength() const
  917. {
  918. Y_ABORT("Not implemented");
  919. }
  920. inline const TOpaqueListRepresentation* TBoxedValueBase::GetListRepresentation() const {
  921. return nullptr;
  922. }
  923. inline IBoxedValuePtr TBoxedValueBase::ReverseListImpl(const IValueBuilder& builder) const {
  924. Y_UNUSED(builder);
  925. return nullptr;
  926. }
  927. inline IBoxedValuePtr TBoxedValueBase::SkipListImpl(const IValueBuilder& builder, ui64 count) const {
  928. Y_UNUSED(builder);
  929. Y_UNUSED(count);
  930. return nullptr;
  931. }
  932. inline IBoxedValuePtr TBoxedValueBase::TakeListImpl(const IValueBuilder& builder, ui64 count) const {
  933. Y_UNUSED(builder);
  934. Y_UNUSED(count);
  935. return nullptr;
  936. }
  937. inline IBoxedValuePtr TBoxedValueBase::ToIndexDictImpl(const IValueBuilder& builder) const {
  938. Y_UNUSED(builder);
  939. return nullptr;
  940. }
  941. inline ui64 TBoxedValueBase::GetDictLength() const
  942. {
  943. Y_ABORT("Not implemented");
  944. }
  945. inline TBoxedValue::TBoxedValue()
  946. {
  947. UdfRegisterObject(this);
  948. }
  949. inline TBoxedValue::~TBoxedValue()
  950. {
  951. UdfUnregisterObject(this);
  952. }
  953. inline void TBoxedValueLink::Link(TBoxedValueLink* root) {
  954. Left = root;
  955. Right = root->Right;
  956. Right->Left = Left->Right = this;
  957. }
  958. inline void TBoxedValueLink::Unlink() {
  959. std::tie(Right->Left, Left->Right) = std::make_pair(Left, Right);
  960. Left = Right = nullptr;
  961. }
  962. inline TUnboxedValue TBoxedValueBase::GetDictIterator() const
  963. {
  964. Y_ABORT("Not implemented");
  965. }
  966. inline TUnboxedValue TBoxedValueBase::GetListIterator() const
  967. {
  968. Y_ABORT("Not implemented");
  969. }
  970. inline TUnboxedValue TBoxedValueBase::GetKeysIterator() const
  971. {
  972. Y_ABORT("Not implemented");
  973. }
  974. inline TUnboxedValue TBoxedValueBase::GetPayloadsIterator() const
  975. {
  976. Y_ABORT("Not implemented");
  977. }
  978. inline bool TBoxedValueBase::Skip()
  979. {
  980. TUnboxedValue stub;
  981. return Next(stub);
  982. }
  983. inline bool TBoxedValueBase::Next(TUnboxedValue&)
  984. {
  985. Y_ABORT("Not implemented");
  986. }
  987. inline bool TBoxedValueBase::NextPair(TUnboxedValue&, TUnboxedValue&)
  988. {
  989. Y_ABORT("Not implemented");
  990. }
  991. inline TUnboxedValue TBoxedValueBase::GetElement(ui32 index) const
  992. {
  993. Y_UNUSED(index);
  994. Y_ABORT("Not implemented");
  995. }
  996. inline const TUnboxedValue* TBoxedValueBase::GetElements() const
  997. {
  998. return nullptr;
  999. }
  1000. inline void TBoxedValueBase::Apply(IApplyContext&) const
  1001. {
  1002. Y_ABORT("Not implemented");
  1003. }
  1004. inline TStringRef TBoxedValueBase::GetResourceTag() const {
  1005. Y_ABORT("Not implemented");
  1006. }
  1007. inline void* TBoxedValueBase::GetResource()
  1008. {
  1009. Y_ABORT("Not implemented");
  1010. }
  1011. inline bool TBoxedValueBase::HasListItems() const {
  1012. Y_ABORT("Not implemented");
  1013. }
  1014. inline bool TBoxedValueBase::HasDictItems() const {
  1015. Y_ABORT("Not implemented");
  1016. }
  1017. inline ui32 TBoxedValueBase::GetVariantIndex() const {
  1018. Y_ABORT("Not implemented");
  1019. }
  1020. inline bool TBoxedValueBase::Contains(const TUnboxedValuePod& key) const
  1021. {
  1022. Y_UNUSED(key);
  1023. Y_ABORT("Not implemented");
  1024. }
  1025. inline TUnboxedValue TBoxedValueBase::Lookup(const TUnboxedValuePod& key) const
  1026. {
  1027. Y_UNUSED(key);
  1028. Y_ABORT("Not implemented");
  1029. }
  1030. inline TUnboxedValue TBoxedValueBase::Run(const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const
  1031. {
  1032. Y_UNUSED(valueBuilder);
  1033. Y_UNUSED(args);
  1034. Y_ABORT("Not implemented");
  1035. }
  1036. inline TUnboxedValue TBoxedValueBase::GetVariantItem() const {
  1037. Y_ABORT("Not implemented");
  1038. }
  1039. inline EFetchStatus TBoxedValueBase::Fetch(TUnboxedValue& result) {
  1040. Y_UNUSED(result);
  1041. Y_ABORT("Not implemented");
  1042. }
  1043. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 3)
  1044. inline ui32 TBoxedValueBase::GetTraverseCount() const {
  1045. Y_ABORT("Not implemented");
  1046. return 0;
  1047. }
  1048. inline TUnboxedValue TBoxedValueBase::GetTraverseItem(ui32 index) const {
  1049. Y_UNUSED(index);
  1050. Y_ABORT("Not implemented");
  1051. }
  1052. inline TUnboxedValue TBoxedValueBase::Save() const {
  1053. Y_ABORT("Not implemented");
  1054. }
  1055. inline void TBoxedValueBase::Load(const TStringRef& state) {
  1056. Y_UNUSED(state);
  1057. Y_ABORT("Not implemented");
  1058. }
  1059. #endif
  1060. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 11)
  1061. inline void TBoxedValueBase::Push(const TUnboxedValuePod& value) {
  1062. Y_UNUSED(value);
  1063. Y_ABORT("Not implemented");
  1064. }
  1065. #endif
  1066. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 12)
  1067. inline bool TBoxedValueBase::IsSortedDict() const {
  1068. Y_ABORT("Not implemented");
  1069. }
  1070. #endif
  1071. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 19)
  1072. inline void TBoxedValueBase::Unused1() {
  1073. Y_ABORT("Not implemented");
  1074. }
  1075. inline void TBoxedValueBase::Unused2() {
  1076. Y_ABORT("Not implemented");
  1077. }
  1078. inline void TBoxedValueBase::Unused3() {
  1079. Y_ABORT("Not implemented");
  1080. }
  1081. inline void TBoxedValueBase::Unused4() {
  1082. Y_ABORT("Not implemented");
  1083. }
  1084. inline void TBoxedValueBase::Unused5() {
  1085. Y_ABORT("Not implemented");
  1086. }
  1087. inline void TBoxedValueBase::Unused6() {
  1088. Y_ABORT("Not implemented");
  1089. }
  1090. #endif
  1091. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 30)
  1092. inline EFetchStatus TBoxedValueBase::WideFetch(TUnboxedValue *result, ui32 width) {
  1093. Y_UNUSED(result);
  1094. Y_UNUSED(width);
  1095. Y_ABORT("Not implemented");
  1096. }
  1097. #endif
  1098. #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 36)
  1099. inline bool TBoxedValueBase::Load2(const TUnboxedValue& value) {
  1100. Y_UNUSED(value);
  1101. Y_ABORT("Not implemented");
  1102. }
  1103. #endif
  1104. inline void TUnboxedValuePod::Dump(IOutputStream& out) const {
  1105. switch (Raw.GetMarkers()) {
  1106. case EMarkers::Empty:
  1107. out << "Empty, count: " << (i64)Raw.Simple.Count;
  1108. break;
  1109. case EMarkers::Embedded:
  1110. out << "Embedded, size: " << (ui32)Raw.Embedded.Size << ", buffer: " <<
  1111. TString(Raw.Embedded.Buffer, sizeof(Raw.Embedded.Buffer)).Quote();
  1112. break;
  1113. case EMarkers::String: {
  1114. out << "String, size: " << Raw.String.Size << ", offset: " << (Raw.String.Offset & 0xffffff) << ", buffer: ";
  1115. auto ref = AsStringRef();
  1116. out << TString(ref.Data(), ref.Size()).Quote();
  1117. break;
  1118. }
  1119. case EMarkers::Boxed:
  1120. out << "Boxed, pointer: " << (void*)Raw.Boxed.Value;
  1121. break;
  1122. }
  1123. }
  1124. } // namespace NUdf
  1125. } // namespace NYql
  1126. template<>
  1127. inline void Out<NYql::NUdf::TUnboxedValuePod>(class IOutputStream &o, const NYql::NUdf::TUnboxedValuePod& value) {
  1128. value.Dump(o);
  1129. }
  1130. template<>
  1131. inline void Out<NYql::NUdf::TUnboxedValue>(class IOutputStream &o, const NYql::NUdf::TUnboxedValue& value) {
  1132. value.Dump(o);
  1133. }
  1134. template<>
  1135. inline void Out<NYql::NUdf::EFetchStatus>(class IOutputStream &o, NYql::NUdf::EFetchStatus value) {
  1136. switch (value) {
  1137. case NYql::NUdf::EFetchStatus::Ok:
  1138. o << "Ok";
  1139. break;
  1140. case NYql::NUdf::EFetchStatus::Yield:
  1141. o << "Yield";
  1142. break;
  1143. case NYql::NUdf::EFetchStatus::Finish:
  1144. o << "Finish";
  1145. break;
  1146. }
  1147. }
  1148. template<>
  1149. inline void Out<NYql::NUdf::TStringRef>(class IOutputStream &o, const NYql::NUdf::TStringRef& value) {
  1150. o << TStringBuf(value.Data(), value.Size());
  1151. }