common.h 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. #pragma once
  2. ///
  3. /// @file yt/cpp/mapreduce/interface/common.h
  4. ///
  5. /// Header containing miscellaneous structs and classes used in library.
  6. #include "fwd.h"
  7. #include <library/cpp/type_info/type_info.h>
  8. #include <library/cpp/yson/node/node.h>
  9. #include <util/generic/guid.h>
  10. #include <util/generic/map.h>
  11. #include <util/generic/maybe.h>
  12. #include <util/generic/ptr.h>
  13. #include <util/generic/vector.h>
  14. #include <google/protobuf/message.h>
  15. #include <initializer_list>
  16. #include <type_traits>
  17. namespace NYT {
  18. ////////////////////////////////////////////////////////////////////////////////
  19. /// @cond Doxygen_Suppress
  20. #define FLUENT_FIELD(type, name) \
  21. type name##_; \
  22. TSelf& name(const type& value) \
  23. { \
  24. name##_ = value; \
  25. return static_cast<TSelf&>(*this); \
  26. } \
  27. static_assert(true)
  28. #define FLUENT_FIELD_ENCAPSULATED(type, name) \
  29. private: \
  30. type name##_; \
  31. public: \
  32. TSelf& name(const type& value) & \
  33. { \
  34. name##_ = value; \
  35. return static_cast<TSelf&>(*this); \
  36. } \
  37. TSelf name(const type& value) && \
  38. { \
  39. name##_ = value; \
  40. return static_cast<TSelf&>(*this); \
  41. } \
  42. const type& name() const & \
  43. { \
  44. return name##_; \
  45. } \
  46. type name() && \
  47. { \
  48. return name##_; \
  49. } \
  50. static_assert(true)
  51. #define FLUENT_FIELD_OPTION(type, name) \
  52. TMaybe<type> name##_; \
  53. TSelf& name(const type& value) \
  54. { \
  55. name##_ = value; \
  56. return static_cast<TSelf&>(*this); \
  57. } \
  58. static_assert(true)
  59. #define FLUENT_FIELD_OPTION_ENCAPSULATED(type, name) \
  60. private: \
  61. TMaybe<type> name##_; \
  62. public: \
  63. TSelf& name(const type& value) & \
  64. { \
  65. name##_ = value; \
  66. return static_cast<TSelf&>(*this); \
  67. } \
  68. TSelf name(const type& value) && \
  69. { \
  70. name##_ = value; \
  71. return static_cast<TSelf&>(*this); \
  72. } \
  73. TSelf& Reset##name() & \
  74. { \
  75. name##_ = Nothing(); \
  76. return static_cast<TSelf&>(*this); \
  77. } \
  78. TSelf Reset##name() && \
  79. { \
  80. name##_ = Nothing(); \
  81. return static_cast<TSelf&>(*this); \
  82. } \
  83. const TMaybe<type>& name() const& \
  84. { \
  85. return name##_; \
  86. } \
  87. TMaybe<type> name() && \
  88. { \
  89. return name##_; \
  90. } \
  91. static_assert(true)
  92. #define FLUENT_FIELD_DEFAULT(type, name, defaultValue) \
  93. type name##_ = defaultValue; \
  94. TSelf& name(const type& value) \
  95. { \
  96. name##_ = value; \
  97. return static_cast<TSelf&>(*this); \
  98. } \
  99. static_assert(true)
  100. #define FLUENT_FIELD_DEFAULT_ENCAPSULATED(type, name, defaultValue) \
  101. private: \
  102. type name##_ = defaultValue; \
  103. public: \
  104. TSelf& name(const type& value) & \
  105. { \
  106. name##_ = value; \
  107. return static_cast<TSelf&>(*this); \
  108. } \
  109. TSelf name(const type& value) && \
  110. { \
  111. name##_ = value; \
  112. return static_cast<TSelf&>(*this); \
  113. } \
  114. const type& name() const & \
  115. { \
  116. return name##_; \
  117. } \
  118. type name() && \
  119. { \
  120. return name##_; \
  121. } \
  122. static_assert(true)
  123. #define FLUENT_VECTOR_FIELD(type, name) \
  124. TVector<type> name##s_; \
  125. TSelf& Add##name(const type& value) \
  126. { \
  127. name##s_.push_back(value); \
  128. return static_cast<TSelf&>(*this);\
  129. } \
  130. TSelf& name##s(TVector<type> values) \
  131. { \
  132. name##s_ = std::move(values); \
  133. return static_cast<TSelf&>(*this);\
  134. } \
  135. static_assert(true)
  136. #define FLUENT_OPTIONAL_VECTOR_FIELD_ENCAPSULATED(type, name) \
  137. private: \
  138. TMaybe<TVector<type>> name##s_; \
  139. public: \
  140. const TMaybe<TVector<type>>& name##s() const & { \
  141. return name##s_; \
  142. } \
  143. TMaybe<TVector<type>>& name##s() & { \
  144. return name##s_; \
  145. } \
  146. TMaybe<TVector<type>> name##s() && { \
  147. return std::move(name##s_); \
  148. } \
  149. TSelf& Add##name(const type& value) & \
  150. { \
  151. if (name##s_.Empty()) { \
  152. name##s_.ConstructInPlace(); \
  153. } \
  154. name##s_->push_back(value); \
  155. return static_cast<TSelf&>(*this);\
  156. } \
  157. TSelf Add##name(const type& value) && \
  158. { \
  159. if (name##s_.Empty()) { \
  160. name##s_.ConstructInPlace(); \
  161. } \
  162. name##s_->push_back(value); \
  163. return static_cast<TSelf&&>(*this);\
  164. } \
  165. TSelf& name##s(TVector<type> values) & \
  166. { \
  167. name##s_ = std::move(values); \
  168. return static_cast<TSelf&>(*this);\
  169. } \
  170. TSelf name##s(TVector<type> values) && \
  171. { \
  172. name##s_ = std::move(values); \
  173. return static_cast<TSelf&&>(*this);\
  174. } \
  175. TSelf& name##s(TNothing) & \
  176. { \
  177. name##s_ = Nothing(); \
  178. return static_cast<TSelf&>(*this);\
  179. } \
  180. TSelf name##s(TNothing) && \
  181. { \
  182. name##s_ = Nothing(); \
  183. return static_cast<TSelf&&>(*this);\
  184. } \
  185. TSelf& Reset##name##s() & \
  186. { \
  187. name##s_ = Nothing(); \
  188. return static_cast<TSelf&>(*this);\
  189. } \
  190. TSelf Reset##name##s() && \
  191. { \
  192. name##s_ = Nothing(); \
  193. return static_cast<TSelf&&>(*this);\
  194. } \
  195. static_assert(true)
  196. #define FLUENT_VECTOR_FIELD_ENCAPSULATED(type, name) \
  197. private: \
  198. TVector<type> name##s_; \
  199. public: \
  200. TSelf& Add##name(const type& value) & \
  201. { \
  202. name##s_.push_back(value); \
  203. return static_cast<TSelf&>(*this);\
  204. } \
  205. TSelf Add##name(const type& value) && \
  206. { \
  207. name##s_.push_back(value); \
  208. return static_cast<TSelf&>(*this);\
  209. } \
  210. TSelf& name##s(TVector<type> value) & \
  211. { \
  212. name##s_ = std::move(value); \
  213. return static_cast<TSelf&>(*this);\
  214. } \
  215. TSelf name##s(TVector<type> value) && \
  216. { \
  217. name##s_ = std::move(value); \
  218. return static_cast<TSelf&>(*this);\
  219. } \
  220. const TVector<type>& name##s() const & \
  221. { \
  222. return name##s_; \
  223. } \
  224. TVector<type> name##s() && \
  225. { \
  226. return name##s_; \
  227. } \
  228. static_assert(true)
  229. #define FLUENT_MAP_FIELD(keytype, valuetype, name) \
  230. TMap<keytype,valuetype> name##_; \
  231. TSelf& Add##name(const keytype& key, const valuetype& value) \
  232. { \
  233. name##_.emplace(key, value); \
  234. return static_cast<TSelf&>(*this);\
  235. } \
  236. static_assert(true)
  237. /// @endcond
  238. ////////////////////////////////////////////////////////////////////////////////
  239. ///
  240. /// @brief Convenience class that keeps sequence of items.
  241. ///
  242. /// Designed to be used as function parameter.
  243. ///
  244. /// Users of such function can then pass:
  245. /// - single item,
  246. /// - initializer list of items,
  247. /// - vector of items;
  248. /// as argument to this function.
  249. ///
  250. /// Example:
  251. /// ```
  252. /// void Foo(const TOneOrMany<int>& arg);
  253. /// ...
  254. /// Foo(1); // ok
  255. /// Foo({1, 2, 3}); // ok
  256. /// ```
  257. template <class T, class TDerived>
  258. struct TOneOrMany
  259. {
  260. /// @cond Doxygen_Suppress
  261. using TSelf = std::conditional_t<std::is_void_v<TDerived>, TOneOrMany, TDerived>;
  262. /// @endcond
  263. /// Initialize with empty sequence.
  264. TOneOrMany() = default;
  265. // Initialize from initializer list.
  266. template<class U>
  267. TOneOrMany(std::initializer_list<U> il)
  268. {
  269. Parts_.assign(il.begin(), il.end());
  270. }
  271. /// Put arguments to sequence
  272. template <class U, class... TArgs>
  273. requires std::is_convertible_v<U, T>
  274. TOneOrMany(U&& arg, TArgs&&... args)
  275. {
  276. Add(arg, std::forward<TArgs>(args)...);
  277. }
  278. /// Initialize from vector.
  279. TOneOrMany(TVector<T> args)
  280. : Parts_(std::move(args))
  281. { }
  282. /// @brief Order is defined the same way as in TVector
  283. bool operator==(const TOneOrMany& rhs) const
  284. {
  285. // N.B. We would like to make this method to be `= default`,
  286. // but this breaks MSVC compiler for the cases when T doesn't
  287. // support comparison.
  288. return Parts_ == rhs.Parts_;
  289. }
  290. ///
  291. /// @{
  292. ///
  293. /// @brief Add all arguments to sequence
  294. template <class U, class... TArgs>
  295. requires std::is_convertible_v<U, T>
  296. TSelf& Add(U&& part, TArgs&&... args) &
  297. {
  298. Parts_.push_back(std::forward<U>(part));
  299. if constexpr (sizeof...(args) > 0) {
  300. [[maybe_unused]] int dummy[sizeof...(args)] = {(Parts_.push_back(std::forward<TArgs>(args)), 0) ... };
  301. }
  302. return static_cast<TSelf&>(*this);
  303. }
  304. template <class U, class... TArgs>
  305. requires std::is_convertible_v<U, T>
  306. TSelf Add(U&& part, TArgs&&... args) &&
  307. {
  308. return std::move(Add(std::forward<U>(part), std::forward<TArgs>(args)...));
  309. }
  310. /// @}
  311. /// Content of sequence.
  312. TVector<T> Parts_;
  313. };
  314. ////////////////////////////////////////////////////////////////////////////////
  315. ///
  316. /// @brief Type of the value that can occur in YT table.
  317. ///
  318. /// @ref NYT::TTableSchema
  319. /// https://ytsaurus.tech/docs/en/user-guide/storage/data-types
  320. enum EValueType : int
  321. {
  322. /// Int64, signed integer of 64 bits.
  323. VT_INT64,
  324. /// Uint64, unsigned integer of 64 bits.
  325. VT_UINT64,
  326. /// Double, floating point number of double precision (64 bits).
  327. VT_DOUBLE,
  328. /// Boolean, `true` or `false`.
  329. VT_BOOLEAN,
  330. /// String, arbitrary byte sequence.
  331. VT_STRING,
  332. /// Any, arbitrary yson document.
  333. VT_ANY,
  334. /// Int8, signed integer of 8 bits.
  335. VT_INT8,
  336. /// Int16, signed integer of 16 bits.
  337. VT_INT16,
  338. /// Int32, signed integer of 32 bits.
  339. VT_INT32,
  340. /// Uint8, unsigned integer of 8 bits.
  341. VT_UINT8,
  342. /// Uint16, unsigned integer of 16 bits.
  343. VT_UINT16,
  344. /// Uint32, unsigned integer of 32 bits.
  345. VT_UINT32,
  346. /// Utf8, byte sequence that is valid utf8.
  347. VT_UTF8,
  348. /// Null, absence of value (almost never used in schemas)
  349. VT_NULL,
  350. /// Void, absence of value (almost never used in schemas) the difference between null, and void is yql-specific.
  351. VT_VOID,
  352. /// Date, number of days since Unix epoch (unsigned)
  353. VT_DATE,
  354. /// Datetime, number of seconds since Unix epoch (unsigned)
  355. VT_DATETIME,
  356. /// Timestamp, number of milliseconds since Unix epoch (unsigned)
  357. VT_TIMESTAMP,
  358. /// Interval, difference between two timestamps (signed)
  359. VT_INTERVAL,
  360. /// Float, floating point number (32 bits)
  361. VT_FLOAT,
  362. /// Json, sequence of bytes that is valid json.
  363. VT_JSON,
  364. // Date32, number of days shifted from Unix epoch, which is 0 (signed)
  365. VT_DATE32,
  366. // Datetime64, number of seconds shifted from Unix epoch, which is 0 (signed)
  367. VT_DATETIME64,
  368. // Timestamp64, number of milliseconds shifted from Unix epoch, which is 0 (signed)
  369. VT_TIMESTAMP64,
  370. // Interval64, difference between two timestamps64 (signed)
  371. VT_INTERVAL64,
  372. // Universally unique identifier according to RFC-4122.
  373. VT_UUID,
  374. };
  375. ///
  376. /// @brief Sort order.
  377. ///
  378. /// @ref NYT::TTableSchema
  379. enum ESortOrder : int
  380. {
  381. /// Ascending sort order.
  382. SO_ASCENDING /* "ascending" */,
  383. /// Descending sort order.
  384. SO_DESCENDING /* "descending" */,
  385. };
  386. ///
  387. /// @brief Value of "optimize_for" attribute.
  388. ///
  389. /// @ref NYT::TRichYPath
  390. enum EOptimizeForAttr : i8
  391. {
  392. /// Optimize for scan
  393. OF_SCAN_ATTR /* "scan" */,
  394. /// Optimize for lookup
  395. OF_LOOKUP_ATTR /* "lookup" */,
  396. };
  397. ///
  398. /// @brief Value of "erasure_codec" attribute.
  399. ///
  400. /// @ref NYT::TRichYPath
  401. enum EErasureCodecAttr : i8
  402. {
  403. /// @cond Doxygen_Suppress
  404. EC_NONE_ATTR /* "none" */,
  405. EC_REED_SOLOMON_6_3_ATTR /* "reed_solomon_6_3" */,
  406. EC_LRC_12_2_2_ATTR /* "lrc_12_2_2" */,
  407. EC_ISA_LRC_12_2_2_ATTR /* "isa_lrc_12_2_2" */,
  408. /// @endcond
  409. };
  410. ///
  411. /// @brief Value of "schema_modification" attribute.
  412. ///
  413. /// @ref NYT::TRichYPath
  414. enum ESchemaModificationAttr : i8
  415. {
  416. SM_NONE_ATTR /* "none" */,
  417. SM_UNVERSIONED_UPDATE /* "unversioned_update" */,
  418. };
  419. ////////////////////////////////////////////////////////////////////////////////
  420. ///
  421. /// @brief Table key column description.
  422. ///
  423. /// The description includes column name and sort order.
  424. ///
  425. /// @anchor TSortOrder_backward_compatibility
  426. /// @note
  427. /// Many functions that use `TSortOrder` as argument used to take `TString`
  428. /// (the only allowed sort order was "ascending" and user didn't have to specify it).
  429. /// @note
  430. /// This class is designed to provide backward compatibility for such code and therefore
  431. /// objects of this class can be constructed and assigned from TString-like objects only.
  432. ///
  433. /// @see NYT::TSortOperationSpec
  434. class TSortColumn
  435. {
  436. public:
  437. /// @cond Doxygen_Suppress
  438. using TSelf = TSortColumn;
  439. /// @endcond
  440. /// Column name
  441. FLUENT_FIELD_ENCAPSULATED(TString, Name);
  442. /// Sort order
  443. FLUENT_FIELD_DEFAULT_ENCAPSULATED(ESortOrder, SortOrder, ESortOrder::SO_ASCENDING);
  444. ///
  445. /// @{
  446. ///
  447. /// @brief Construct object from name and sort order
  448. ///
  449. /// Constructors are intentionally implicit so `TSortColumn` can be compatible with old code.
  450. /// @ref TSortOrder_backward_compatibility
  451. TSortColumn(TStringBuf name = {}, ESortOrder sortOrder = ESortOrder::SO_ASCENDING);
  452. TSortColumn(const TString& name, ESortOrder sortOrder = ESortOrder::SO_ASCENDING);
  453. TSortColumn(const char* name, ESortOrder sortOrder = ESortOrder::SO_ASCENDING);
  454. /// @}
  455. /// Check that sort order is ascending, throw exception otherwise.
  456. const TSortColumn& EnsureAscending() const;
  457. /// @brief Convert sort to yson representation as YT API expects it.
  458. TNode ToNode() const;
  459. /// @brief Comparison is default and checks both name and sort order.
  460. bool operator == (const TSortColumn& rhs) const = default;
  461. ///
  462. /// @{
  463. ///
  464. /// @brief Assign object from column name, and set sort order to `ascending`.
  465. ///
  466. /// This is backward compatibility methods.
  467. ///
  468. /// @ref TSortOrder_backward_compatibility
  469. TSortColumn& operator = (TStringBuf name);
  470. TSortColumn& operator = (const TString& name);
  471. TSortColumn& operator = (const char* name);
  472. /// @}
  473. bool operator == (const TStringBuf rhsName) const;
  474. bool operator == (const TString& rhsName) const;
  475. bool operator == (const char* rhsName) const;
  476. // Intentionally implicit conversions.
  477. operator TString() const;
  478. operator TStringBuf() const;
  479. operator std::string() const;
  480. Y_SAVELOAD_DEFINE(Name_, SortOrder_);
  481. };
  482. ///
  483. /// @brief List of @ref TSortColumn
  484. ///
  485. /// Contains a bunch of helper methods such as constructing from single object.
  486. class TSortColumns
  487. : public TOneOrMany<TSortColumn, TSortColumns>
  488. {
  489. public:
  490. using TOneOrMany<TSortColumn, TSortColumns>::TOneOrMany;
  491. /// Construct empty list.
  492. TSortColumns();
  493. ///
  494. /// @{
  495. ///
  496. /// @brief Construct list of ascending sort order columns by their names.
  497. ///
  498. /// Required for backward compatibility.
  499. ///
  500. /// @ref TSortOrder_backward_compatibility
  501. TSortColumns(const TVector<TString>& names);
  502. TSortColumns(const TColumnNames& names);
  503. /// @}
  504. ///
  505. /// @brief Implicit conversion to column list.
  506. ///
  507. /// If all columns has ascending sort order return list of their names.
  508. /// Throw exception otherwise.
  509. ///
  510. /// Required for backward compatibility.
  511. ///
  512. /// @ref TSortOrder_backward_compatibility
  513. operator TColumnNames() const;
  514. /// Make sure that all columns are of ascending sort order.
  515. const TSortColumns& EnsureAscending() const;
  516. /// Get list of column names.
  517. TVector<TString> GetNames() const;
  518. };
  519. ////////////////////////////////////////////////////////////////////////////////
  520. /// Helper function to create new style type from old style one.
  521. NTi::TTypePtr ToTypeV3(EValueType type, bool required);
  522. ///
  523. /// @brief Single column description
  524. ///
  525. /// Each field describing column has setter and getter.
  526. ///
  527. /// Example reading field:
  528. /// ```
  529. /// ... columnSchema.Name() ...
  530. /// ```
  531. ///
  532. /// Example setting field:
  533. /// ```
  534. /// columnSchema.Name("my-column").Type(VT_INT64); // set name and type
  535. /// ```
  536. ///
  537. /// @ref https://ytsaurus.tech/docs/en/user-guide/storage/static-schema
  538. class TColumnSchema
  539. {
  540. public:
  541. /// @cond Doxygen_Suppress
  542. using TSelf = TColumnSchema;
  543. /// @endcond
  544. ///
  545. /// @brief Construct empty column schemas
  546. ///
  547. /// @note
  548. /// Such schema cannot be used in schema as it it doesn't have name.
  549. TColumnSchema();
  550. ///
  551. /// @{
  552. ///
  553. /// @brief Copy and move constructors are default.
  554. TColumnSchema(const TColumnSchema&) = default;
  555. TColumnSchema& operator=(const TColumnSchema&) = default;
  556. /// @}
  557. FLUENT_FIELD_ENCAPSULATED(TString, Name);
  558. ///
  559. /// @brief Functions to work with type in old manner.
  560. ///
  561. /// @deprecated New code is recommended to work with types using @ref NTi::TTypePtr from type_info library.
  562. TColumnSchema& Type(EValueType type) &;
  563. TColumnSchema Type(EValueType type) &&;
  564. EValueType Type() const;
  565. /// @brief Set and get column type.
  566. /// @{
  567. TColumnSchema& Type(const NTi::TTypePtr& type) &;
  568. TColumnSchema Type(const NTi::TTypePtr& type) &&;
  569. TColumnSchema& TypeV3(const NTi::TTypePtr& type) &;
  570. TColumnSchema TypeV3(const NTi::TTypePtr& type) &&;
  571. NTi::TTypePtr TypeV3() const;
  572. /// @}
  573. /// Column sort order
  574. FLUENT_FIELD_OPTION_ENCAPSULATED(ESortOrder, SortOrder);
  575. ///
  576. /// @brief Lock group name
  577. ///
  578. /// @ref https://ytsaurus.tech/docs/en/user-guide/dynamic-tables/sorted-dynamic-tables#locking-rows
  579. FLUENT_FIELD_OPTION_ENCAPSULATED(TString, Lock);
  580. /// Expression defining column value
  581. FLUENT_FIELD_OPTION_ENCAPSULATED(TString, Expression);
  582. /// Aggregating function name
  583. FLUENT_FIELD_OPTION_ENCAPSULATED(TString, Aggregate);
  584. ///
  585. /// @brief Storage group name
  586. ///
  587. /// @ref https://ytsaurus.tech/docs/en/user-guide/storage/static-schema
  588. FLUENT_FIELD_OPTION_ENCAPSULATED(TString, Group);
  589. // StableName for renamed and deleted columns.
  590. FLUENT_FIELD_OPTION_ENCAPSULATED(TString, StableName);
  591. /// Deleted column
  592. FLUENT_FIELD_OPTION_ENCAPSULATED(bool, Deleted);
  593. ///
  594. /// @brief Column requiredness.
  595. ///
  596. /// Required columns doesn't accept NULL values.
  597. /// Usually if column is required it means that it has Optional<...> type
  598. bool Required() const;
  599. ///
  600. /// @{
  601. ///
  602. /// @brief Set type in old-style manner
  603. TColumnSchema& Type(EValueType type, bool required) &;
  604. TColumnSchema Type(EValueType type, bool required) &&;
  605. /// @}
  606. ///
  607. /// @{
  608. ///
  609. /// @brief Raw yson representation of column type
  610. /// @deprecated Prefer to use `TypeV3` methods.
  611. const TMaybe<TNode>& RawTypeV3() const;
  612. TColumnSchema& RawTypeV3(TNode rawTypeV3)&;
  613. TColumnSchema RawTypeV3(TNode rawTypeV3)&&;
  614. /// @}
  615. private:
  616. friend void Deserialize(TColumnSchema& columnSchema, const TNode& node);
  617. NTi::TTypePtr TypeV3_;
  618. TMaybe<TNode> RawTypeV3_;
  619. };
  620. /// Equality check checks all fields of column schema.
  621. bool operator==(const TColumnSchema& lhs, const TColumnSchema& rhs);
  622. ///
  623. /// @brief Description of table schema
  624. ///
  625. /// @see https://ytsaurus.tech/docs/en/user-guide/storage/static-schema
  626. class TTableSchema
  627. {
  628. public:
  629. /// @cond Doxygen_Suppress
  630. using TSelf = TTableSchema;
  631. /// @endcond
  632. /// Column schema
  633. FLUENT_VECTOR_FIELD_ENCAPSULATED(TColumnSchema, Column);
  634. ///
  635. /// @brief Strictness of the schema
  636. ///
  637. /// Strict schemas are not allowed to have columns not described in schema.
  638. /// Nonstrict schemas are allowed to have such columns, all such missing columns are assumed to have
  639. /// type any (or optional<yson> in type_v3 terminology).
  640. FLUENT_FIELD_DEFAULT_ENCAPSULATED(bool, Strict, true);
  641. ///
  642. /// @brief Whether keys are unique
  643. ///
  644. /// This flag can be set only for schemas that have sorted columns.
  645. /// If flag is set table cannot have multiple rows with same key.
  646. FLUENT_FIELD_DEFAULT_ENCAPSULATED(bool, UniqueKeys, false);
  647. /// Get modifiable column list
  648. TVector<TColumnSchema>& MutableColumns();
  649. /// Check if schema has any described column
  650. [[nodiscard]] bool Empty() const;
  651. /// Add column
  652. TTableSchema& AddColumn(const TString& name, const NTi::TTypePtr& type, ESortOrder sortOrder) &;
  653. /// @copydoc NYT::TTableSchema::AddColumn(const TString&, const NTi::TTypePtr&, ESortOrder)&;
  654. TTableSchema AddColumn(const TString& name, const NTi::TTypePtr& type, ESortOrder sortOrder) &&;
  655. /// @copydoc NYT::TTableSchema::AddColumn(const TString&, const NTi::TTypePtr&, ESortOrder)&;
  656. TTableSchema& AddColumn(const TString& name, const NTi::TTypePtr& type) &;
  657. /// @copydoc NYT::TTableSchema::AddColumn(const TString&, const NTi::TTypePtr&, ESortOrder)&;
  658. TTableSchema AddColumn(const TString& name, const NTi::TTypePtr& type) &&;
  659. /// Add optional column of specified type
  660. TTableSchema& AddColumn(const TString& name, EValueType type, ESortOrder sortOrder) &;
  661. /// @copydoc NYT::TTableSchema::AddColumn(const TString&, EValueType, ESortOrder)&;
  662. TTableSchema AddColumn(const TString& name, EValueType type, ESortOrder sortOrder) &&;
  663. /// @copydoc NYT::TTableSchema::AddColumn(const TString&, EValueType, ESortOrder)&;
  664. TTableSchema& AddColumn(const TString& name, EValueType type) &;
  665. /// @copydoc NYT::TTableSchema::AddColumn(const TString&, EValueType, ESortOrder)&;
  666. TTableSchema AddColumn(const TString& name, EValueType type) &&;
  667. ///
  668. /// @brief Make table schema sorted by specified columns
  669. ///
  670. /// Resets old key columns if any
  671. TTableSchema& SortBy(const TSortColumns& columns) &;
  672. /// @copydoc NYT::TTableSchema::SortBy(const TSortColumns&)&;
  673. TTableSchema SortBy(const TSortColumns& columns) &&;
  674. /// Get yson description of table schema
  675. [[nodiscard]] TNode ToNode() const;
  676. /// Parse schema from yson node
  677. static NYT::TTableSchema FromNode(const TNode& node);
  678. friend void Deserialize(TTableSchema& tableSchema, const TNode& node);
  679. };
  680. /// Check for equality of all columns and all schema attributes
  681. bool operator==(const TTableSchema& lhs, const TTableSchema& rhs);
  682. // Pretty printer for unittests
  683. void PrintTo(const TTableSchema& schema, std::ostream* out);
  684. /// Create table schema by protobuf message descriptor
  685. TTableSchema CreateTableSchema(
  686. const ::google::protobuf::Descriptor& messageDescriptor,
  687. const TSortColumns& sortColumns = TSortColumns(),
  688. bool keepFieldsWithoutExtension = true);
  689. /// Create table schema by protobuf message type
  690. template <class TProtoType, typename = std::enable_if_t<std::is_base_of_v<::google::protobuf::Message, TProtoType>>>
  691. inline TTableSchema CreateTableSchema(
  692. const TSortColumns& sortColumns = TSortColumns(),
  693. bool keepFieldsWithoutExtension = true)
  694. {
  695. static_assert(
  696. std::is_base_of_v<::google::protobuf::Message, TProtoType>,
  697. "Template argument must be derived from ::google::protobuf::Message");
  698. return CreateTableSchema(
  699. *TProtoType::descriptor(),
  700. sortColumns,
  701. keepFieldsWithoutExtension);
  702. }
  703. ///
  704. /// @brief Create strict table schema from `struct` type.
  705. ///
  706. /// Names and types of columns are taken from struct member names and types.
  707. /// `Strict` flag is set to true, all other attribute of schema and columns
  708. /// are left with default values
  709. TTableSchema CreateTableSchema(NTi::TTypePtr type);
  710. ////////////////////////////////////////////////////////////////////////////////
  711. ///
  712. /// @brief Enumeration describing comparison operation used in key bound.
  713. ///
  714. /// ERelation is a part of @ref NYT::TKeyBound that can be used as
  715. /// lower or upper key limit in @ref TReadLimit.
  716. ///
  717. /// Relations `Less` and `LessOrEqual` are for upper limit and
  718. /// relations `Greater` and `GreaterOrEqual` are for lower limit.
  719. ///
  720. /// It is a error to use relation in the limit of wrong kind.
  721. ///
  722. /// @see https://ytsaurus.tech/docs/en/user-guide/storage/ypath#rich_ypath
  723. enum class ERelation
  724. {
  725. ///
  726. /// @brief Relation "less"
  727. ///
  728. /// Specifies range of keys that are before specified key.
  729. /// Can only be used in upper limit.
  730. Less /* "<" */,
  731. ///
  732. /// @brief Relation "less or equal"
  733. ///
  734. /// Specifies range of keys that are before or equal specified key.
  735. /// Can only be used in upper limit.
  736. LessOrEqual /* "<=" */,
  737. ///
  738. /// @brief Relation "greater"
  739. ///
  740. /// Specifies range of keys that are after specified key.
  741. /// Can only be used in lower limit.
  742. Greater /* ">" */,
  743. ///
  744. /// @brief Relation "greater or equal"
  745. ///
  746. /// Specifies range of keys that are after or equal than specified key.
  747. /// Can only be used in lower limit.
  748. GreaterOrEqual /* ">=" */,
  749. };
  750. ///
  751. /// @brief Key with relation specifying interval of keys in lower or upper limit of @ref NYT::TReadRange
  752. ///
  753. /// @see https://ytsaurus.tech/docs/en/user-guide/common/ypath#rich_ypath
  754. struct TKeyBound
  755. {
  756. /// @cond Doxygen_Suppress
  757. using TSelf = TKeyBound;
  758. explicit TKeyBound(ERelation relation = ERelation::Less, TKey key = TKey{});
  759. FLUENT_FIELD_DEFAULT_ENCAPSULATED(ERelation, Relation, ERelation::Less);
  760. FLUENT_FIELD_DEFAULT_ENCAPSULATED(TKey, Key, TKey{});
  761. /// @endcond
  762. };
  763. ///
  764. /// @brief Description of the read limit.
  765. ///
  766. /// It is actually a variant and must store exactly one field.
  767. ///
  768. /// @see https://ytsaurus.tech/docs/en/user-guide/common/ypath#rich_ypath
  769. struct TReadLimit
  770. {
  771. /// @cond Doxygen_Suppress
  772. using TSelf = TReadLimit;
  773. /// @endcond
  774. ///
  775. /// @brief KeyBound specifies table key and whether to include it
  776. ///
  777. /// It can be used in lower or upper limit when reading tables.
  778. FLUENT_FIELD_OPTION(TKeyBound, KeyBound);
  779. ///
  780. /// @brief Table key
  781. ///
  782. /// It can be used in exact, lower or upper limit when reading tables.
  783. FLUENT_FIELD_OPTION(TKey, Key);
  784. ///
  785. /// @brief Row index
  786. ///
  787. /// It can be used in exact, lower or upper limit when reading tables.
  788. FLUENT_FIELD_OPTION(i64, RowIndex);
  789. ///
  790. /// @brief File offset
  791. ///
  792. /// It can be used in lower or upper limit when reading files.
  793. FLUENT_FIELD_OPTION(i64, Offset);
  794. ///
  795. /// @brief Tablet index
  796. ///
  797. /// It can be used in lower or upper limit in dynamic table operations
  798. FLUENT_FIELD_OPTION(i64, TabletIndex);
  799. };
  800. ///
  801. /// @brief Range of a table or a file
  802. ///
  803. /// @see https://ytsaurus.tech/docs/en/user-guide/common/ypath#rich_ypath
  804. struct TReadRange
  805. {
  806. using TSelf = TReadRange;
  807. ///
  808. /// @brief Lower limit of the range
  809. ///
  810. /// It is usually inclusive (except when @ref NYT::TKeyBound with relation @ref NYT::ERelation::Greater is used).
  811. FLUENT_FIELD(TReadLimit, LowerLimit);
  812. ///
  813. /// @brief Lower limit of the range
  814. ///
  815. /// It is usually exclusive (except when @ref NYT::TKeyBound with relation @ref NYT::ERelation::LessOrEqual is used).
  816. FLUENT_FIELD(TReadLimit, UpperLimit);
  817. /// Exact key or row index.
  818. FLUENT_FIELD(TReadLimit, Exact);
  819. /// Create read range from row indexes.
  820. static TReadRange FromRowIndices(i64 lowerLimit, i64 upperLimit)
  821. {
  822. return TReadRange()
  823. .LowerLimit(TReadLimit().RowIndex(lowerLimit))
  824. .UpperLimit(TReadLimit().RowIndex(upperLimit));
  825. }
  826. /// Create read range from keys.
  827. static TReadRange FromKeys(const TKey& lowerKeyInclusive, const TKey& upperKeyExclusive)
  828. {
  829. return TReadRange()
  830. .LowerLimit(TReadLimit().Key(lowerKeyInclusive))
  831. .UpperLimit(TReadLimit().Key(upperKeyExclusive));
  832. }
  833. };
  834. ///
  835. /// @brief Path with additional attributes.
  836. ///
  837. /// Allows to specify additional attributes for path used in some operations.
  838. ///
  839. /// @see https://ytsaurus.tech/docs/en/user-guide/storage/ypath#rich_ypath
  840. struct TRichYPath
  841. {
  842. /// @cond Doxygen_Suppress
  843. using TSelf = TRichYPath;
  844. /// @endcond
  845. /// Path itself.
  846. FLUENT_FIELD(TYPath, Path);
  847. /// Specifies that path should be appended not overwritten
  848. FLUENT_FIELD_OPTION(bool, Append);
  849. /// @deprecated Deprecated attribute.
  850. FLUENT_FIELD_OPTION(bool, PartiallySorted);
  851. /// Specifies that path is expected to be sorted by these columns.
  852. FLUENT_FIELD(TSortColumns, SortedBy);
  853. /// Add range to read.
  854. TRichYPath& AddRange(TReadRange range)
  855. {
  856. if (!Ranges_) {
  857. Ranges_.ConstructInPlace();
  858. }
  859. Ranges_->push_back(std::move(range));
  860. return *this;
  861. }
  862. TRichYPath& ResetRanges()
  863. {
  864. Ranges_.Clear();
  865. return *this;
  866. }
  867. ///
  868. /// @{
  869. ///
  870. /// Return ranges to read.
  871. ///
  872. /// NOTE: Nothing (in TMaybe) and empty TVector are different ranges.
  873. /// Nothing represents universal range (reader reads all table rows).
  874. /// Empty TVector represents empty range (reader returns empty set of rows).
  875. const TMaybe<TVector<TReadRange>>& GetRanges() const
  876. {
  877. return Ranges_;
  878. }
  879. TMaybe<TVector<TReadRange>>& MutableRanges()
  880. {
  881. return Ranges_;
  882. }
  883. ///
  884. /// @{
  885. ///
  886. /// Get range view, that is a convenient way to iterate through all ranges.
  887. TArrayRef<TReadRange> MutableRangesView()
  888. {
  889. if (Ranges_.Defined()) {
  890. return TArrayRef(Ranges_->data(), Ranges_->size());
  891. } else {
  892. return {};
  893. }
  894. }
  895. TArrayRef<const TReadRange> GetRangesView() const
  896. {
  897. if (Ranges_.Defined()) {
  898. return TArrayRef(Ranges_->data(), Ranges_->size());
  899. } else {
  900. return {};
  901. }
  902. }
  903. /// @}
  904. /// @{
  905. ///
  906. /// Get range by index.
  907. const TReadRange& GetRange(ssize_t i) const
  908. {
  909. return Ranges_.GetRef()[i];
  910. }
  911. TReadRange& MutableRange(ssize_t i)
  912. {
  913. return Ranges_.GetRef()[i];
  914. }
  915. /// @}
  916. ///
  917. /// @brief Specifies columns that should be read.
  918. ///
  919. /// If it's set to Nothing then all columns will be read.
  920. /// If empty TColumnNames is specified then each read row will be empty.
  921. FLUENT_FIELD_OPTION(TColumnNames, Columns);
  922. FLUENT_FIELD_OPTION(bool, Teleport);
  923. FLUENT_FIELD_OPTION(bool, Primary);
  924. FLUENT_FIELD_OPTION(bool, Foreign);
  925. FLUENT_FIELD_OPTION(i64, RowCountLimit);
  926. FLUENT_FIELD_OPTION(TString, FileName);
  927. /// Specifies original path to be shown in Web UI
  928. FLUENT_FIELD_OPTION(TYPath, OriginalPath);
  929. ///
  930. /// @brief Specifies that this path points to executable file
  931. ///
  932. /// Used in operation specs.
  933. FLUENT_FIELD_OPTION(bool, Executable);
  934. ///
  935. /// @brief Specify format to use when loading table.
  936. ///
  937. /// Used in operation specs.
  938. FLUENT_FIELD_OPTION(TNode, Format);
  939. /// @brief Specifies table schema that will be set on the path
  940. FLUENT_FIELD_OPTION(TTableSchema, Schema);
  941. /// Specifies compression codec that will be set on the path
  942. FLUENT_FIELD_OPTION(TString, CompressionCodec);
  943. /// Specifies erasure codec that will be set on the path
  944. FLUENT_FIELD_OPTION(EErasureCodecAttr, ErasureCodec);
  945. /// Specifies schema modification that will be set on the path
  946. FLUENT_FIELD_OPTION(ESchemaModificationAttr, SchemaModification);
  947. /// Specifies optimize_for attribute that will be set on the path
  948. FLUENT_FIELD_OPTION(EOptimizeForAttr, OptimizeFor);
  949. ///
  950. /// @brief Do not put file used in operation into node cache
  951. ///
  952. /// If BypassArtifactCache == true, file will be loaded into the job's sandbox bypassing the cache on the YT node.
  953. /// It helps jobs that use tmpfs to start faster,
  954. /// because files will be loaded into tmpfs directly bypassing disk cache
  955. FLUENT_FIELD_OPTION(bool, BypassArtifactCache);
  956. ///
  957. /// @brief Timestamp of dynamic table.
  958. ///
  959. /// NOTE: it is _not_ unix timestamp
  960. /// (instead it's transaction timestamp, that is more complex structure).
  961. FLUENT_FIELD_OPTION(i64, Timestamp);
  962. ///
  963. /// @brief Specify transaction that should be used to access this path.
  964. ///
  965. /// Allows to start cross-transactional operations.
  966. FLUENT_FIELD_OPTION(TTransactionId, TransactionId);
  967. ///
  968. /// @brief Wether to create operation output path.
  969. ///
  970. /// If set to `true` output path is created by YT server.
  971. /// If set to `false` output path is not created explicitly (and operation will fail if it doesn't exist)
  972. /// If attribute is not set output path is created by this library using explicit master call.
  973. FLUENT_FIELD_OPTION(bool, Create);
  974. using TRenameColumnsDescriptor = THashMap<TString, TString>;
  975. /// Specifies columnar mapping which will be applied to columns before transfer to job.
  976. FLUENT_FIELD_OPTION(TRenameColumnsDescriptor, RenameColumns);
  977. /// Specifies cluster for the YPath
  978. FLUENT_FIELD_OPTION(TString, Cluster);
  979. /// Create empty path with no attributes
  980. TRichYPath()
  981. { }
  982. ///
  983. /// @{
  984. ///
  985. /// @brief Create path from string
  986. TRichYPath(const char* path)
  987. : Path_(path)
  988. { }
  989. TRichYPath(const TYPath& path)
  990. : Path_(path)
  991. { }
  992. /// @}
  993. private:
  994. TMaybe<TVector<TReadRange>> Ranges_;
  995. };
  996. ///
  997. /// @ref Create copy of @ref NYT::TRichYPath with schema derived from proto message.
  998. ///
  999. ///
  1000. template <typename TProtoType>
  1001. TRichYPath WithSchema(const TRichYPath& path, const TSortColumns& sortBy = TSortColumns())
  1002. {
  1003. static_assert(std::is_base_of_v<::google::protobuf::Message, TProtoType>, "TProtoType must be Protobuf message");
  1004. auto schemedPath = path;
  1005. if (!schemedPath.Schema_) {
  1006. schemedPath.Schema(CreateTableSchema<TProtoType>(sortBy));
  1007. }
  1008. return schemedPath;
  1009. }
  1010. ///
  1011. /// @brief Create copy of @ref NYT::TRichYPath with schema derived from TRowType if possible.
  1012. ///
  1013. /// If TRowType is protobuf message schema is derived from it and set to returned path.
  1014. /// Otherwise schema of original path is left unchanged (and probably unset).
  1015. template <typename TRowType>
  1016. TRichYPath MaybeWithSchema(const TRichYPath& path, const TSortColumns& sortBy = TSortColumns())
  1017. {
  1018. if constexpr (std::is_base_of_v<::google::protobuf::Message, TRowType>) {
  1019. return WithSchema<TRowType>(path, sortBy);
  1020. } else {
  1021. return path;
  1022. }
  1023. }
  1024. ///
  1025. /// @brief Get the list of ranges related to path in compatibility mode.
  1026. ///
  1027. /// - If path is missing ranges, empty list is returned.
  1028. /// - If path has associated range list and the list is not empty, function returns this list.
  1029. /// - If path has associated range list and this list is empty, exception is thrown.
  1030. ///
  1031. /// Before YT-17683 RichYPath didn't support empty range list and empty range actually meant universal range.
  1032. /// This function emulates this old behavior.
  1033. ///
  1034. /// @see https://st.yandex-team.ru/YT-17683
  1035. const TVector<TReadRange>& GetRangesCompat(const TRichYPath& path);
  1036. ////////////////////////////////////////////////////////////////////////////////
  1037. /// Statistics about table columns.
  1038. struct TTableColumnarStatistics
  1039. {
  1040. /// Total data weight for all chunks for each of requested columns.
  1041. THashMap<TString, i64> ColumnDataWeight;
  1042. /// Estimated number of unique elements for each column.
  1043. THashMap<TString, ui64> ColumnEstimatedUniqueCounts;
  1044. /// Total weight of all old chunks that don't keep columnar statistics.
  1045. i64 LegacyChunksDataWeight = 0;
  1046. /// Timestamps total weight (only for dynamic tables).
  1047. TMaybe<i64> TimestampTotalWeight;
  1048. };
  1049. ////////////////////////////////////////////////////////////////////////////////
  1050. /// Description of a partition.
  1051. struct TMultiTablePartition
  1052. {
  1053. struct TStatistics
  1054. {
  1055. i64 ChunkCount = 0;
  1056. i64 DataWeight = 0;
  1057. i64 RowCount = 0;
  1058. };
  1059. /// Ranges of input tables for this partition.
  1060. TVector<TRichYPath> TableRanges;
  1061. /// Aggregate statistics of all the table ranges in the partition.
  1062. TStatistics AggregateStatistics;
  1063. };
  1064. /// Table partitions from GetTablePartitions command.
  1065. struct TMultiTablePartitions
  1066. {
  1067. /// Disjoint partitions into which the input tables were divided.
  1068. TVector<TMultiTablePartition> Partitions;
  1069. };
  1070. ////////////////////////////////////////////////////////////////////////////////
  1071. ///
  1072. /// @brief Contains information about tablet
  1073. ///
  1074. /// @see NYT::IClient::GetTabletInfos
  1075. struct TTabletInfo
  1076. {
  1077. ///
  1078. /// @brief Indicates the total number of rows added to the tablet (including trimmed ones).
  1079. ///
  1080. /// Currently only provided for ordered tablets.
  1081. i64 TotalRowCount = 0;
  1082. ///
  1083. /// @brief Contains the number of front rows that are trimmed and are not guaranteed to be accessible.
  1084. ///
  1085. /// Only makes sense for ordered tablet.
  1086. i64 TrimmedRowCount = 0;
  1087. ///
  1088. /// @brief Tablet cell barrier timestamp, which lags behind the current timestamp
  1089. ///
  1090. /// It is guaranteed that all transactions with commit timestamp not exceeding the barrier are fully committed;
  1091. /// e.g. all their added rows are visible (and are included in @ref NYT::TTabletInfo::TotalRowCount).
  1092. /// Mostly makes sense for ordered tablets.
  1093. ui64 BarrierTimestamp;
  1094. };
  1095. ////////////////////////////////////////////////////////////////////////////////
  1096. /// List of attributes to retrieve in operations like @ref NYT::ICypressClient::Get
  1097. struct TAttributeFilter
  1098. {
  1099. /// @cond Doxygen_Suppress
  1100. using TSelf = TAttributeFilter;
  1101. /// @endcond
  1102. /// List of attributes.
  1103. FLUENT_VECTOR_FIELD(TString, Attribute);
  1104. };
  1105. ////////////////////////////////////////////////////////////////////////////////
  1106. ///
  1107. /// @brief Check if none of the fields of @ref NYT::TReadLimit is set.
  1108. ///
  1109. /// @return true if any field of readLimit is set and false otherwise.
  1110. bool IsTrivial(const TReadLimit& readLimit);
  1111. /// Convert yson node type to table schema type
  1112. EValueType NodeTypeToValueType(TNode::EType nodeType);
  1113. ////////////////////////////////////////////////////////////////////////////////
  1114. ///
  1115. /// @brief Enumeration for specifying how reading from master is performed.
  1116. ///
  1117. /// Used in operations like NYT::ICypressClient::Get
  1118. enum class EMasterReadKind : int
  1119. {
  1120. ///
  1121. /// @brief Reading from leader.
  1122. ///
  1123. /// Should almost never be used since it's expensive and for regular uses has no difference from
  1124. /// "follower" read.
  1125. Leader /* "leader" */,
  1126. /// @brief Reading from master follower (default).
  1127. Follower /* "follower" */,
  1128. Cache /* "cache" */,
  1129. MasterCache /* "master_cache" */,
  1130. };
  1131. ////////////////////////////////////////////////////////////////////////////////
  1132. /// @cond Doxygen_Suppress
  1133. namespace NDetail {
  1134. // MUST NOT BE USED BY CLIENTS
  1135. // TODO: we should use default GENERATE_ENUM_SERIALIZATION
  1136. TString ToString(EValueType type);
  1137. } // namespace NDetail
  1138. /// @endcond
  1139. ////////////////////////////////////////////////////////////////////////////////
  1140. } // namespace NYT