serialize.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. #include "serialize.h"
  2. #include "common.h"
  3. #include "fluent.h"
  4. #include <library/cpp/yson/parser.h>
  5. #include <library/cpp/yson/node/node_io.h>
  6. #include <library/cpp/yson/node/serialize.h>
  7. #include <library/cpp/type_info/type_io.h>
  8. #include <util/generic/string.h>
  9. namespace NYT {
  10. ////////////////////////////////////////////////////////////////////////////////
  11. // const auto& nodeMap = node.AsMap();
  12. #define DESERIALIZE_ITEM(NAME, MEMBER) \
  13. if (const auto* item = nodeMap.FindPtr(NAME)) { \
  14. Deserialize(MEMBER, *item); \
  15. }
  16. // const auto& attributesMap = node.GetAttributes().AsMap();
  17. #define DESERIALIZE_ATTR(NAME, MEMBER) \
  18. if (const auto* attr = attributesMap.FindPtr(NAME)) { \
  19. Deserialize(MEMBER, *attr); \
  20. }
  21. ////////////////////////////////////////////////////////////////////////////////
  22. void Serialize(const TSortColumn& sortColumn, NYson::IYsonConsumer* consumer)
  23. {
  24. if (sortColumn.SortOrder() == ESortOrder::SO_ASCENDING) {
  25. Serialize(sortColumn.Name(), consumer);
  26. } else {
  27. BuildYsonFluently(consumer).BeginMap()
  28. .Item("name").Value(sortColumn.Name())
  29. .Item("sort_order").Value(ToString(sortColumn.SortOrder()))
  30. .EndMap();
  31. }
  32. }
  33. void Deserialize(TSortColumn& sortColumn, const TNode& node)
  34. {
  35. if (node.IsString()) {
  36. sortColumn = TSortColumn(node.AsString());
  37. } else if (node.IsMap()) {
  38. const auto& name = node["name"].AsString();
  39. const auto& sortOrderString = node["sort_order"].AsString();
  40. sortColumn = TSortColumn(name, ::FromString<ESortOrder>(sortOrderString));
  41. } else {
  42. ythrow yexception() << "Expected sort column to be string or map, got " << node.GetType();
  43. }
  44. }
  45. template <class T, class TDerived>
  46. void SerializeOneOrMany(const TOneOrMany<T, TDerived>& oneOrMany, NYson::IYsonConsumer* consumer)
  47. {
  48. BuildYsonFluently(consumer).List(oneOrMany.Parts_);
  49. }
  50. template <class T, class TDerived>
  51. void DeserializeOneOrMany(TOneOrMany<T, TDerived>& oneOrMany, const TNode& node)
  52. {
  53. Deserialize(oneOrMany.Parts_, node);
  54. }
  55. void Serialize(const TKey& key, NYson::IYsonConsumer* consumer)
  56. {
  57. SerializeOneOrMany(key, consumer);
  58. }
  59. void Deserialize(TKey& key, const TNode& node)
  60. {
  61. DeserializeOneOrMany(key, node);
  62. }
  63. void Serialize(const TSortColumns& sortColumns, NYson::IYsonConsumer* consumer)
  64. {
  65. SerializeOneOrMany(sortColumns, consumer);
  66. }
  67. void Deserialize(TSortColumns& sortColumns, const TNode& node)
  68. {
  69. DeserializeOneOrMany(sortColumns, node);
  70. }
  71. void Serialize(const TColumnNames& columnNames, NYson::IYsonConsumer* consumer)
  72. {
  73. SerializeOneOrMany(columnNames, consumer);
  74. }
  75. void Deserialize(TColumnNames& columnNames, const TNode& node)
  76. {
  77. DeserializeOneOrMany(columnNames, node);
  78. }
  79. ////////////////////////////////////////////////////////////////////////////////
  80. void Deserialize(EValueType& valueType, const TNode& node)
  81. {
  82. const auto& nodeStr = node.AsString();
  83. static const THashMap<TString, EValueType> str2ValueType = {
  84. {"int8", VT_INT8},
  85. {"int16", VT_INT16},
  86. {"int32", VT_INT32},
  87. {"int64", VT_INT64},
  88. {"uint8", VT_UINT8},
  89. {"uint16", VT_UINT16},
  90. {"uint32", VT_UINT32},
  91. {"uint64", VT_UINT64},
  92. {"boolean", VT_BOOLEAN},
  93. {"double", VT_DOUBLE},
  94. {"string", VT_STRING},
  95. {"utf8", VT_UTF8},
  96. {"any", VT_ANY},
  97. {"null", VT_NULL},
  98. {"void", VT_VOID},
  99. {"date", VT_DATE},
  100. {"datetime", VT_DATETIME},
  101. {"timestamp", VT_TIMESTAMP},
  102. {"interval", VT_INTERVAL},
  103. {"float", VT_FLOAT},
  104. {"json", VT_JSON},
  105. };
  106. auto it = str2ValueType.find(nodeStr);
  107. if (it == str2ValueType.end()) {
  108. ythrow yexception() << "Invalid value type '" << nodeStr << "'";
  109. }
  110. valueType = it->second;
  111. }
  112. void Deserialize(ESortOrder& sortOrder, const TNode& node)
  113. {
  114. sortOrder = FromString<ESortOrder>(node.AsString());
  115. }
  116. void Deserialize(EOptimizeForAttr& optimizeFor, const TNode& node)
  117. {
  118. optimizeFor = FromString<EOptimizeForAttr>(node.AsString());
  119. }
  120. void Deserialize(EErasureCodecAttr& erasureCodec, const TNode& node)
  121. {
  122. erasureCodec = FromString<EErasureCodecAttr>(node.AsString());
  123. }
  124. void Deserialize(ESchemaModificationAttr& schemaModification, const TNode& node)
  125. {
  126. schemaModification = FromString<ESchemaModificationAttr>(node.AsString());
  127. }
  128. void Serialize(const TColumnSchema& columnSchema, NYson::IYsonConsumer* consumer)
  129. {
  130. BuildYsonFluently(consumer).BeginMap()
  131. .Item("name").Value(columnSchema.Name())
  132. .DoIf(!columnSchema.RawTypeV3().Defined(),
  133. [&] (TFluentMap fluent) {
  134. fluent.Item("type").Value(NDetail::ToString(columnSchema.Type()));
  135. fluent.Item("required").Value(columnSchema.Required());
  136. if (columnSchema.Type() == VT_ANY
  137. && *columnSchema.TypeV3() != *NTi::Optional(NTi::Yson()))
  138. {
  139. // A lot of user canonize serialized schema.
  140. // To be backward compatible we only set type_v3 for new types.
  141. fluent.Item("type_v3").Value(columnSchema.TypeV3());
  142. }
  143. }
  144. )
  145. .DoIf(columnSchema.RawTypeV3().Defined(), [&] (TFluentMap fluent) {
  146. const auto& rawTypeV3 = *columnSchema.RawTypeV3();
  147. fluent.Item("type_v3").Value(rawTypeV3);
  148. // We going set old fields `type` and `required` to be compatible
  149. // with old clusters that doesn't support type_v3 yet.
  150. // if type is simple return its name otherwise return empty optional
  151. auto isRequired = [](TStringBuf simpleType) {
  152. return simpleType != "null" && simpleType != "void";
  153. };
  154. auto getSimple = [] (const TNode& typeV3) -> TMaybe<TString> {
  155. static const THashMap<TString,TString> typeV3ToOld = {
  156. {"bool", "boolean"},
  157. {"yson", "any"},
  158. };
  159. TMaybe<TString> result;
  160. if (typeV3.IsString()) {
  161. result = typeV3.AsString();
  162. } else if (typeV3.IsMap() && typeV3.Size() == 1) {
  163. Y_ABORT_UNLESS(typeV3["type_name"].IsString(), "invalid type is passed");
  164. result = typeV3["type_name"].AsString();
  165. }
  166. if (result) {
  167. auto it = typeV3ToOld.find(*result);
  168. if (it != typeV3ToOld.end()) {
  169. result = it->second;
  170. }
  171. }
  172. return result;
  173. };
  174. auto simplify = [&](const TNode& typeV3) -> TMaybe<std::pair<TString, bool>> {
  175. auto simple = getSimple(typeV3);
  176. if (simple) {
  177. return std::make_pair(*simple, isRequired(*simple));
  178. }
  179. if (typeV3.IsMap() && typeV3["type_name"] == "optional") {
  180. auto simpleItem = getSimple(typeV3["item"]);
  181. if (simpleItem && isRequired(*simpleItem)) {
  182. return std::make_pair(*simpleItem, false);
  183. }
  184. }
  185. return {};
  186. };
  187. auto simplified = simplify(rawTypeV3);
  188. if (simplified) {
  189. const auto& [simpleType, required] = *simplified;
  190. fluent
  191. .Item("type").Value(simpleType)
  192. .Item("required").Value(required);
  193. return;
  194. }
  195. })
  196. .DoIf(columnSchema.SortOrder().Defined(), [&] (TFluentMap fluent) {
  197. fluent.Item("sort_order").Value(ToString(*columnSchema.SortOrder()));
  198. })
  199. .DoIf(columnSchema.Lock().Defined(), [&] (TFluentMap fluent) {
  200. fluent.Item("lock").Value(*columnSchema.Lock());
  201. })
  202. .DoIf(columnSchema.Expression().Defined(), [&] (TFluentMap fluent) {
  203. fluent.Item("expression").Value(*columnSchema.Expression());
  204. })
  205. .DoIf(columnSchema.Aggregate().Defined(), [&] (TFluentMap fluent) {
  206. fluent.Item("aggregate").Value(*columnSchema.Aggregate());
  207. })
  208. .DoIf(columnSchema.Group().Defined(), [&] (TFluentMap fluent) {
  209. fluent.Item("group").Value(*columnSchema.Group());
  210. })
  211. .EndMap();
  212. }
  213. void Deserialize(TColumnSchema& columnSchema, const TNode& node)
  214. {
  215. const auto& nodeMap = node.AsMap();
  216. DESERIALIZE_ITEM("name", columnSchema.Name_);
  217. DESERIALIZE_ITEM("type_v3", columnSchema.RawTypeV3_);
  218. DESERIALIZE_ITEM("sort_order", columnSchema.SortOrder_);
  219. DESERIALIZE_ITEM("lock", columnSchema.Lock_);
  220. DESERIALIZE_ITEM("expression", columnSchema.Expression_);
  221. DESERIALIZE_ITEM("aggregate", columnSchema.Aggregate_);
  222. DESERIALIZE_ITEM("group", columnSchema.Group_);
  223. if (nodeMap.contains("type_v3")) {
  224. NTi::TTypePtr type;
  225. DESERIALIZE_ITEM("type_v3", type);
  226. columnSchema.Type(type);
  227. } else {
  228. EValueType oldType = VT_INT64;
  229. bool required = false;
  230. DESERIALIZE_ITEM("type", oldType);
  231. DESERIALIZE_ITEM("required", required);
  232. columnSchema.Type(ToTypeV3(oldType, required));
  233. }
  234. }
  235. void Serialize(const TTableSchema& tableSchema, NYson::IYsonConsumer* consumer)
  236. {
  237. BuildYsonFluently(consumer).BeginAttributes()
  238. .Item("strict").Value(tableSchema.Strict())
  239. .Item("unique_keys").Value(tableSchema.UniqueKeys())
  240. .EndAttributes()
  241. .List(tableSchema.Columns());
  242. }
  243. void Deserialize(TTableSchema& tableSchema, const TNode& node)
  244. {
  245. const auto& attributesMap = node.GetAttributes().AsMap();
  246. DESERIALIZE_ATTR("strict", tableSchema.Strict_);
  247. DESERIALIZE_ATTR("unique_keys", tableSchema.UniqueKeys_);
  248. Deserialize(tableSchema.Columns_, node);
  249. }
  250. ////////////////////////////////////////////////////////////////////////////////
  251. void Serialize(const TKeyBound& keyBound, NYson::IYsonConsumer* consumer)
  252. {
  253. BuildYsonFluently(consumer).BeginList()
  254. .Item().Value(ToString(keyBound.Relation()))
  255. .Item().Value(keyBound.Key())
  256. .EndList();
  257. }
  258. void Deserialize(TKeyBound& keyBound, const TNode& node)
  259. {
  260. const auto& nodeList = node.AsList();
  261. Y_ENSURE(nodeList.size() == 2);
  262. const auto& relationNode = nodeList[0];
  263. keyBound.Relation(::FromString<ERelation>(relationNode.AsString()));
  264. const auto& keyNode = nodeList[1];
  265. TKey key;
  266. Deserialize(key, keyNode);
  267. keyBound.Key(std::move(key));
  268. }
  269. ////////////////////////////////////////////////////////////////////////////////
  270. void Serialize(const TReadLimit& readLimit, NYson::IYsonConsumer* consumer)
  271. {
  272. BuildYsonFluently(consumer).BeginMap()
  273. .DoIf(readLimit.KeyBound_.Defined(), [&] (TFluentMap fluent) {
  274. fluent.Item("key_bound").Value(*readLimit.KeyBound_);
  275. })
  276. .DoIf(readLimit.Key_.Defined(), [&] (TFluentMap fluent) {
  277. fluent.Item("key").Value(*readLimit.Key_);
  278. })
  279. .DoIf(readLimit.RowIndex_.Defined(), [&] (TFluentMap fluent) {
  280. fluent.Item("row_index").Value(*readLimit.RowIndex_);
  281. })
  282. .DoIf(readLimit.Offset_.Defined(), [&] (TFluentMap fluent) {
  283. fluent.Item("offset").Value(*readLimit.Offset_);
  284. })
  285. .DoIf(readLimit.TabletIndex_.Defined(), [&] (TFluentMap fluent) {
  286. fluent.Item("tablet_index").Value(*readLimit.TabletIndex_);
  287. })
  288. .EndMap();
  289. }
  290. void Deserialize(TReadLimit& readLimit, const TNode& node)
  291. {
  292. const auto& nodeMap = node.AsMap();
  293. DESERIALIZE_ITEM("key_bound", readLimit.KeyBound_);
  294. DESERIALIZE_ITEM("key", readLimit.Key_);
  295. DESERIALIZE_ITEM("row_index", readLimit.RowIndex_);
  296. DESERIALIZE_ITEM("offset", readLimit.Offset_);
  297. DESERIALIZE_ITEM("tablet_index", readLimit.TabletIndex_);
  298. }
  299. void Serialize(const TReadRange& readRange, NYson::IYsonConsumer* consumer)
  300. {
  301. BuildYsonFluently(consumer).BeginMap()
  302. .DoIf(!IsTrivial(readRange.LowerLimit_), [&] (TFluentMap fluent) {
  303. fluent.Item("lower_limit").Value(readRange.LowerLimit_);
  304. })
  305. .DoIf(!IsTrivial(readRange.UpperLimit_), [&] (TFluentMap fluent) {
  306. fluent.Item("upper_limit").Value(readRange.UpperLimit_);
  307. })
  308. .DoIf(!IsTrivial(readRange.Exact_), [&] (TFluentMap fluent) {
  309. fluent.Item("exact").Value(readRange.Exact_);
  310. })
  311. .EndMap();
  312. }
  313. void Deserialize(TReadRange& readRange, const TNode& node)
  314. {
  315. const auto& nodeMap = node.AsMap();
  316. DESERIALIZE_ITEM("lower_limit", readRange.LowerLimit_);
  317. DESERIALIZE_ITEM("upper_limit", readRange.UpperLimit_);
  318. DESERIALIZE_ITEM("exact", readRange.Exact_);
  319. }
  320. void Serialize(const THashMap<TString, TString>& renameColumns, NYson::IYsonConsumer* consumer)
  321. {
  322. BuildYsonFluently(consumer)
  323. .DoMapFor(renameColumns, [] (TFluentMap fluent, const auto& item) {
  324. fluent.Item(item.first).Value(item.second);
  325. });
  326. }
  327. void Serialize(const TRichYPath& path, NYson::IYsonConsumer* consumer)
  328. {
  329. BuildYsonFluently(consumer).BeginAttributes()
  330. .DoIf(path.GetRanges().Defined(), [&] (TFluentAttributes fluent) {
  331. fluent.Item("ranges").List(*path.GetRanges());
  332. })
  333. .DoIf(path.Columns_.Defined(), [&] (TFluentAttributes fluent) {
  334. fluent.Item("columns").Value(*path.Columns_);
  335. })
  336. .DoIf(path.Append_.Defined(), [&] (TFluentAttributes fluent) {
  337. fluent.Item("append").Value(*path.Append_);
  338. })
  339. .DoIf(path.PartiallySorted_.Defined(), [&] (TFluentAttributes fluent) {
  340. fluent.Item("partially_sorted").Value(*path.PartiallySorted_);
  341. })
  342. .DoIf(!path.SortedBy_.Parts_.empty(), [&] (TFluentAttributes fluent) {
  343. fluent.Item("sorted_by").Value(path.SortedBy_);
  344. })
  345. .DoIf(path.Teleport_.Defined(), [&] (TFluentAttributes fluent) {
  346. fluent.Item("teleport").Value(*path.Teleport_);
  347. })
  348. .DoIf(path.Primary_.Defined(), [&] (TFluentAttributes fluent) {
  349. fluent.Item("primary").Value(*path.Primary_);
  350. })
  351. .DoIf(path.Foreign_.Defined(), [&] (TFluentAttributes fluent) {
  352. fluent.Item("foreign").Value(*path.Foreign_);
  353. })
  354. .DoIf(path.RowCountLimit_.Defined(), [&] (TFluentAttributes fluent) {
  355. fluent.Item("row_count_limit").Value(*path.RowCountLimit_);
  356. })
  357. .DoIf(path.FileName_.Defined(), [&] (TFluentAttributes fluent) {
  358. fluent.Item("file_name").Value(*path.FileName_);
  359. })
  360. .DoIf(path.OriginalPath_.Defined(), [&] (TFluentAttributes fluent) {
  361. fluent.Item("original_path").Value(*path.OriginalPath_);
  362. })
  363. .DoIf(path.Executable_.Defined(), [&] (TFluentAttributes fluent) {
  364. fluent.Item("executable").Value(*path.Executable_);
  365. })
  366. .DoIf(path.Format_.Defined(), [&] (TFluentAttributes fluent) {
  367. fluent.Item("format").Value(*path.Format_);
  368. })
  369. .DoIf(path.Schema_.Defined(), [&] (TFluentAttributes fluent) {
  370. fluent.Item("schema").Value(*path.Schema_);
  371. })
  372. .DoIf(path.Timestamp_.Defined(), [&] (TFluentAttributes fluent) {
  373. fluent.Item("timestamp").Value(*path.Timestamp_);
  374. })
  375. .DoIf(path.CompressionCodec_.Defined(), [&] (TFluentAttributes fluent) {
  376. fluent.Item("compression_codec").Value(*path.CompressionCodec_);
  377. })
  378. .DoIf(path.ErasureCodec_.Defined(), [&] (TFluentAttributes fluent) {
  379. fluent.Item("erasure_codec").Value(ToString(*path.ErasureCodec_));
  380. })
  381. .DoIf(path.SchemaModification_.Defined(), [&] (TFluentAttributes fluent) {
  382. fluent.Item("schema_modification").Value(ToString(*path.SchemaModification_));
  383. })
  384. .DoIf(path.OptimizeFor_.Defined(), [&] (TFluentAttributes fluent) {
  385. fluent.Item("optimize_for").Value(ToString(*path.OptimizeFor_));
  386. })
  387. .DoIf(path.TransactionId_.Defined(), [&] (TFluentAttributes fluent) {
  388. fluent.Item("transaction_id").Value(GetGuidAsString(*path.TransactionId_));
  389. })
  390. .DoIf(path.RenameColumns_.Defined(), [&] (TFluentAttributes fluent) {
  391. fluent.Item("rename_columns").Value(*path.RenameColumns_);
  392. })
  393. .DoIf(path.BypassArtifactCache_.Defined(), [&] (TFluentAttributes fluent) {
  394. fluent.Item("bypass_artifact_cache").Value(*path.BypassArtifactCache_);
  395. })
  396. .EndAttributes()
  397. .Value(path.Path_);
  398. }
  399. void Deserialize(TRichYPath& path, const TNode& node)
  400. {
  401. path = {};
  402. const auto& attributesMap = node.GetAttributes().AsMap();
  403. DESERIALIZE_ATTR("ranges", path.MutableRanges());
  404. DESERIALIZE_ATTR("columns", path.Columns_);
  405. DESERIALIZE_ATTR("append", path.Append_);
  406. DESERIALIZE_ATTR("partially_sorted", path.PartiallySorted_);
  407. DESERIALIZE_ATTR("sorted_by", path.SortedBy_);
  408. DESERIALIZE_ATTR("teleport", path.Teleport_);
  409. DESERIALIZE_ATTR("primary", path.Primary_);
  410. DESERIALIZE_ATTR("foreign", path.Foreign_);
  411. DESERIALIZE_ATTR("row_count_limit", path.RowCountLimit_);
  412. DESERIALIZE_ATTR("file_name", path.FileName_);
  413. DESERIALIZE_ATTR("original_path", path.OriginalPath_);
  414. DESERIALIZE_ATTR("executable", path.Executable_);
  415. DESERIALIZE_ATTR("format", path.Format_);
  416. DESERIALIZE_ATTR("schema", path.Schema_);
  417. DESERIALIZE_ATTR("timestamp", path.Timestamp_);
  418. DESERIALIZE_ATTR("compression_codec", path.CompressionCodec_);
  419. DESERIALIZE_ATTR("erasure_codec", path.ErasureCodec_);
  420. DESERIALIZE_ATTR("schema_modification", path.SchemaModification_);
  421. DESERIALIZE_ATTR("optimize_for", path.OptimizeFor_);
  422. DESERIALIZE_ATTR("transaction_id", path.TransactionId_);
  423. DESERIALIZE_ATTR("rename_columns", path.RenameColumns_);
  424. DESERIALIZE_ATTR("bypass_artifact_cache", path.BypassArtifactCache_);
  425. Deserialize(path.Path_, node);
  426. }
  427. void Serialize(const TAttributeFilter& filter, NYson::IYsonConsumer* consumer)
  428. {
  429. BuildYsonFluently(consumer).List(filter.Attributes_);
  430. }
  431. void Deserialize(TTableColumnarStatistics& statistics, const TNode& node)
  432. {
  433. const auto& nodeMap = node.AsMap();
  434. DESERIALIZE_ITEM("column_data_weights", statistics.ColumnDataWeight);
  435. DESERIALIZE_ITEM("legacy_chunks_data_weight", statistics.LegacyChunksDataWeight);
  436. DESERIALIZE_ITEM("timestamp_total_weight", statistics.TimestampTotalWeight);
  437. }
  438. void Deserialize(TMultiTablePartition::TStatistics& statistics, const TNode& node)
  439. {
  440. const auto& nodeMap = node.AsMap();
  441. DESERIALIZE_ITEM("chunk_count", statistics.ChunkCount);
  442. DESERIALIZE_ITEM("data_weight", statistics.DataWeight);
  443. DESERIALIZE_ITEM("row_count", statistics.RowCount);
  444. }
  445. void Deserialize(TMultiTablePartition& partition, const TNode& node)
  446. {
  447. const auto& nodeMap = node.AsMap();
  448. DESERIALIZE_ITEM("table_ranges", partition.TableRanges);
  449. DESERIALIZE_ITEM("aggregate_statistics", partition.AggregateStatistics);
  450. }
  451. void Deserialize(TMultiTablePartitions& partitions, const TNode& node)
  452. {
  453. const auto& nodeMap = node.AsMap();
  454. DESERIALIZE_ITEM("partitions", partitions.Partitions);
  455. }
  456. void Serialize(const TGUID& value, NYson::IYsonConsumer* consumer)
  457. {
  458. BuildYsonFluently(consumer).Value(GetGuidAsString(value));
  459. }
  460. void Deserialize(TGUID& value, const TNode& node)
  461. {
  462. value = GetGuid(node.AsString());
  463. }
  464. void Deserialize(TTabletInfo& value, const TNode& node)
  465. {
  466. auto nodeMap = node.AsMap();
  467. DESERIALIZE_ITEM("total_row_count", value.TotalRowCount)
  468. DESERIALIZE_ITEM("trimmed_row_count", value.TrimmedRowCount)
  469. DESERIALIZE_ITEM("barrier_timestamp", value.BarrierTimestamp)
  470. }
  471. void Serialize(const NTi::TTypePtr& type, NYson::IYsonConsumer* consumer)
  472. {
  473. auto yson = NTi::NIo::SerializeYson(type.Get());
  474. ::NYson::ParseYsonStringBuffer(yson, consumer);
  475. }
  476. void Deserialize(NTi::TTypePtr& type, const TNode& node)
  477. {
  478. auto yson = NodeToYsonString(node, NYson::EYsonFormat::Binary);
  479. type = NTi::NIo::DeserializeYson(*NTi::HeapFactory(), yson);
  480. }
  481. #undef DESERIALIZE_ITEM
  482. #undef DESERIALIZE_ATTR
  483. ////////////////////////////////////////////////////////////////////////////////
  484. } // namespace NYT