serialize.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  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. static const auto optionalYson = NTi::Optional(NTi::Yson());
  135. fluent.Item("type").Value(NDetail::ToString(columnSchema.Type()));
  136. fluent.Item("required").Value(columnSchema.Required());
  137. if (
  138. (columnSchema.Type() == VT_ANY && *columnSchema.TypeV3() != *optionalYson) ||
  139. // See https://github.com/ytsaurus/ytsaurus/issues/173
  140. columnSchema.TypeV3()->IsDecimal() ||
  141. (columnSchema.TypeV3()->IsOptional() && columnSchema.TypeV3()->AsOptional()->GetItemType()->IsDecimal()))
  142. {
  143. // A lot of user canonize serialized schema.
  144. // To be backward compatible we only set type_v3 for new types.
  145. fluent.Item("type_v3").Value(columnSchema.TypeV3());
  146. }
  147. }
  148. )
  149. .DoIf(columnSchema.RawTypeV3().Defined(), [&] (TFluentMap fluent) {
  150. const auto& rawTypeV3 = *columnSchema.RawTypeV3();
  151. fluent.Item("type_v3").Value(rawTypeV3);
  152. // We going set old fields `type` and `required` to be compatible
  153. // with old clusters that doesn't support type_v3 yet.
  154. // if type is simple return its name otherwise return empty optional
  155. auto isRequired = [](TStringBuf simpleType) {
  156. return simpleType != "null" && simpleType != "void";
  157. };
  158. auto getSimple = [] (const TNode& typeV3) -> TMaybe<TString> {
  159. static const THashMap<TString,TString> typeV3ToOld = {
  160. {"bool", "boolean"},
  161. {"yson", "any"},
  162. };
  163. TMaybe<TString> result;
  164. if (typeV3.IsString()) {
  165. result = typeV3.AsString();
  166. } else if (typeV3.IsMap() && typeV3.Size() == 1) {
  167. Y_ABORT_UNLESS(typeV3["type_name"].IsString(), "invalid type is passed");
  168. result = typeV3["type_name"].AsString();
  169. }
  170. if (result) {
  171. auto it = typeV3ToOld.find(*result);
  172. if (it != typeV3ToOld.end()) {
  173. result = it->second;
  174. }
  175. }
  176. return result;
  177. };
  178. auto simplify = [&](const TNode& typeV3) -> TMaybe<std::pair<TString, bool>> {
  179. auto simple = getSimple(typeV3);
  180. if (simple) {
  181. return std::pair(*simple, isRequired(*simple));
  182. }
  183. if (typeV3.IsMap() && typeV3["type_name"] == "optional") {
  184. auto simpleItem = getSimple(typeV3["item"]);
  185. if (simpleItem && isRequired(*simpleItem)) {
  186. return std::pair(*simpleItem, false);
  187. }
  188. }
  189. return {};
  190. };
  191. auto simplified = simplify(rawTypeV3);
  192. if (simplified) {
  193. const auto& [simpleType, required] = *simplified;
  194. fluent
  195. .Item("type").Value(simpleType)
  196. .Item("required").Value(required);
  197. return;
  198. }
  199. })
  200. .DoIf(columnSchema.SortOrder().Defined(), [&] (TFluentMap fluent) {
  201. fluent.Item("sort_order").Value(ToString(*columnSchema.SortOrder()));
  202. })
  203. .DoIf(columnSchema.Lock().Defined(), [&] (TFluentMap fluent) {
  204. fluent.Item("lock").Value(*columnSchema.Lock());
  205. })
  206. .DoIf(columnSchema.Expression().Defined(), [&] (TFluentMap fluent) {
  207. fluent.Item("expression").Value(*columnSchema.Expression());
  208. })
  209. .DoIf(columnSchema.Aggregate().Defined(), [&] (TFluentMap fluent) {
  210. fluent.Item("aggregate").Value(*columnSchema.Aggregate());
  211. })
  212. .DoIf(columnSchema.Group().Defined(), [&] (TFluentMap fluent) {
  213. fluent.Item("group").Value(*columnSchema.Group());
  214. })
  215. .DoIf(columnSchema.StableName().Defined(), [&] (TFluentMap fluent) {
  216. fluent.Item("stable_name").Value(*columnSchema.StableName());
  217. })
  218. .DoIf(columnSchema.Deleted().Defined(), [&] (TFluentMap fluent) {
  219. fluent.Item("deleted").Value(*columnSchema.Deleted());
  220. })
  221. .EndMap();
  222. }
  223. void Deserialize(TColumnSchema& columnSchema, const TNode& node)
  224. {
  225. const auto& nodeMap = node.AsMap();
  226. DESERIALIZE_ITEM("name", columnSchema.Name_);
  227. DESERIALIZE_ITEM("type_v3", columnSchema.RawTypeV3_);
  228. DESERIALIZE_ITEM("sort_order", columnSchema.SortOrder_);
  229. DESERIALIZE_ITEM("lock", columnSchema.Lock_);
  230. DESERIALIZE_ITEM("expression", columnSchema.Expression_);
  231. DESERIALIZE_ITEM("aggregate", columnSchema.Aggregate_);
  232. DESERIALIZE_ITEM("group", columnSchema.Group_);
  233. DESERIALIZE_ITEM("stable_name", columnSchema.StableName_);
  234. DESERIALIZE_ITEM("deleted", columnSchema.Deleted_);
  235. if (nodeMap.contains("type_v3")) {
  236. NTi::TTypePtr type;
  237. DESERIALIZE_ITEM("type_v3", type);
  238. columnSchema.Type(type);
  239. } else {
  240. EValueType oldType = VT_INT64;
  241. bool required = false;
  242. DESERIALIZE_ITEM("type", oldType);
  243. DESERIALIZE_ITEM("required", required);
  244. columnSchema.Type(ToTypeV3(oldType, required));
  245. }
  246. }
  247. void Serialize(const TTableSchema& tableSchema, NYson::IYsonConsumer* consumer)
  248. {
  249. BuildYsonFluently(consumer).BeginAttributes()
  250. .Item("strict").Value(tableSchema.Strict())
  251. .Item("unique_keys").Value(tableSchema.UniqueKeys())
  252. .EndAttributes()
  253. .List(tableSchema.Columns());
  254. }
  255. void Deserialize(TTableSchema& tableSchema, const TNode& node)
  256. {
  257. const auto& attributesMap = node.GetAttributes().AsMap();
  258. DESERIALIZE_ATTR("strict", tableSchema.Strict_);
  259. DESERIALIZE_ATTR("unique_keys", tableSchema.UniqueKeys_);
  260. Deserialize(tableSchema.Columns_, node);
  261. }
  262. ////////////////////////////////////////////////////////////////////////////////
  263. void Serialize(const TKeyBound& keyBound, NYson::IYsonConsumer* consumer)
  264. {
  265. BuildYsonFluently(consumer).BeginList()
  266. .Item().Value(ToString(keyBound.Relation()))
  267. .Item().Value(keyBound.Key())
  268. .EndList();
  269. }
  270. void Deserialize(TKeyBound& keyBound, const TNode& node)
  271. {
  272. const auto& nodeList = node.AsList();
  273. Y_ENSURE(nodeList.size() == 2);
  274. const auto& relationNode = nodeList[0];
  275. keyBound.Relation(::FromString<ERelation>(relationNode.AsString()));
  276. const auto& keyNode = nodeList[1];
  277. TKey key;
  278. Deserialize(key, keyNode);
  279. keyBound.Key(std::move(key));
  280. }
  281. ////////////////////////////////////////////////////////////////////////////////
  282. void Serialize(const TReadLimit& readLimit, NYson::IYsonConsumer* consumer)
  283. {
  284. BuildYsonFluently(consumer).BeginMap()
  285. .DoIf(readLimit.KeyBound_.Defined(), [&] (TFluentMap fluent) {
  286. fluent.Item("key_bound").Value(*readLimit.KeyBound_);
  287. })
  288. .DoIf(readLimit.Key_.Defined(), [&] (TFluentMap fluent) {
  289. fluent.Item("key").Value(*readLimit.Key_);
  290. })
  291. .DoIf(readLimit.RowIndex_.Defined(), [&] (TFluentMap fluent) {
  292. fluent.Item("row_index").Value(*readLimit.RowIndex_);
  293. })
  294. .DoIf(readLimit.Offset_.Defined(), [&] (TFluentMap fluent) {
  295. fluent.Item("offset").Value(*readLimit.Offset_);
  296. })
  297. .DoIf(readLimit.TabletIndex_.Defined(), [&] (TFluentMap fluent) {
  298. fluent.Item("tablet_index").Value(*readLimit.TabletIndex_);
  299. })
  300. .EndMap();
  301. }
  302. void Deserialize(TReadLimit& readLimit, const TNode& node)
  303. {
  304. const auto& nodeMap = node.AsMap();
  305. DESERIALIZE_ITEM("key_bound", readLimit.KeyBound_);
  306. DESERIALIZE_ITEM("key", readLimit.Key_);
  307. DESERIALIZE_ITEM("row_index", readLimit.RowIndex_);
  308. DESERIALIZE_ITEM("offset", readLimit.Offset_);
  309. DESERIALIZE_ITEM("tablet_index", readLimit.TabletIndex_);
  310. }
  311. void Serialize(const TReadRange& readRange, NYson::IYsonConsumer* consumer)
  312. {
  313. BuildYsonFluently(consumer).BeginMap()
  314. .DoIf(!IsTrivial(readRange.LowerLimit_), [&] (TFluentMap fluent) {
  315. fluent.Item("lower_limit").Value(readRange.LowerLimit_);
  316. })
  317. .DoIf(!IsTrivial(readRange.UpperLimit_), [&] (TFluentMap fluent) {
  318. fluent.Item("upper_limit").Value(readRange.UpperLimit_);
  319. })
  320. .DoIf(!IsTrivial(readRange.Exact_), [&] (TFluentMap fluent) {
  321. fluent.Item("exact").Value(readRange.Exact_);
  322. })
  323. .EndMap();
  324. }
  325. void Deserialize(TReadRange& readRange, const TNode& node)
  326. {
  327. const auto& nodeMap = node.AsMap();
  328. DESERIALIZE_ITEM("lower_limit", readRange.LowerLimit_);
  329. DESERIALIZE_ITEM("upper_limit", readRange.UpperLimit_);
  330. DESERIALIZE_ITEM("exact", readRange.Exact_);
  331. }
  332. void Serialize(const THashMap<TString, TString>& renameColumns, NYson::IYsonConsumer* consumer)
  333. {
  334. BuildYsonFluently(consumer)
  335. .DoMapFor(renameColumns, [] (TFluentMap fluent, const auto& item) {
  336. fluent.Item(item.first).Value(item.second);
  337. });
  338. }
  339. void Serialize(const TRichYPath& path, NYson::IYsonConsumer* consumer)
  340. {
  341. BuildYsonFluently(consumer).BeginAttributes()
  342. .DoIf(path.GetRanges().Defined(), [&] (TFluentAttributes fluent) {
  343. fluent.Item("ranges").List(*path.GetRanges());
  344. })
  345. .DoIf(path.Columns_.Defined(), [&] (TFluentAttributes fluent) {
  346. fluent.Item("columns").Value(*path.Columns_);
  347. })
  348. .DoIf(path.Append_.Defined(), [&] (TFluentAttributes fluent) {
  349. fluent.Item("append").Value(*path.Append_);
  350. })
  351. .DoIf(path.PartiallySorted_.Defined(), [&] (TFluentAttributes fluent) {
  352. fluent.Item("partially_sorted").Value(*path.PartiallySorted_);
  353. })
  354. .DoIf(!path.SortedBy_.Parts_.empty(), [&] (TFluentAttributes fluent) {
  355. fluent.Item("sorted_by").Value(path.SortedBy_);
  356. })
  357. .DoIf(path.Teleport_.Defined(), [&] (TFluentAttributes fluent) {
  358. fluent.Item("teleport").Value(*path.Teleport_);
  359. })
  360. .DoIf(path.Primary_.Defined(), [&] (TFluentAttributes fluent) {
  361. fluent.Item("primary").Value(*path.Primary_);
  362. })
  363. .DoIf(path.Foreign_.Defined(), [&] (TFluentAttributes fluent) {
  364. fluent.Item("foreign").Value(*path.Foreign_);
  365. })
  366. .DoIf(path.RowCountLimit_.Defined(), [&] (TFluentAttributes fluent) {
  367. fluent.Item("row_count_limit").Value(*path.RowCountLimit_);
  368. })
  369. .DoIf(path.FileName_.Defined(), [&] (TFluentAttributes fluent) {
  370. fluent.Item("file_name").Value(*path.FileName_);
  371. })
  372. .DoIf(path.OriginalPath_.Defined(), [&] (TFluentAttributes fluent) {
  373. fluent.Item("original_path").Value(*path.OriginalPath_);
  374. })
  375. .DoIf(path.Executable_.Defined(), [&] (TFluentAttributes fluent) {
  376. fluent.Item("executable").Value(*path.Executable_);
  377. })
  378. .DoIf(path.Format_.Defined(), [&] (TFluentAttributes fluent) {
  379. fluent.Item("format").Value(*path.Format_);
  380. })
  381. .DoIf(path.Schema_.Defined(), [&] (TFluentAttributes fluent) {
  382. fluent.Item("schema").Value(*path.Schema_);
  383. })
  384. .DoIf(path.Timestamp_.Defined(), [&] (TFluentAttributes fluent) {
  385. fluent.Item("timestamp").Value(*path.Timestamp_);
  386. })
  387. .DoIf(path.CompressionCodec_.Defined(), [&] (TFluentAttributes fluent) {
  388. fluent.Item("compression_codec").Value(*path.CompressionCodec_);
  389. })
  390. .DoIf(path.ErasureCodec_.Defined(), [&] (TFluentAttributes fluent) {
  391. fluent.Item("erasure_codec").Value(ToString(*path.ErasureCodec_));
  392. })
  393. .DoIf(path.SchemaModification_.Defined(), [&] (TFluentAttributes fluent) {
  394. fluent.Item("schema_modification").Value(ToString(*path.SchemaModification_));
  395. })
  396. .DoIf(path.OptimizeFor_.Defined(), [&] (TFluentAttributes fluent) {
  397. fluent.Item("optimize_for").Value(ToString(*path.OptimizeFor_));
  398. })
  399. .DoIf(path.TransactionId_.Defined(), [&] (TFluentAttributes fluent) {
  400. fluent.Item("transaction_id").Value(GetGuidAsString(*path.TransactionId_));
  401. })
  402. .DoIf(path.RenameColumns_.Defined(), [&] (TFluentAttributes fluent) {
  403. fluent.Item("rename_columns").Value(*path.RenameColumns_);
  404. })
  405. .DoIf(path.BypassArtifactCache_.Defined(), [&] (TFluentAttributes fluent) {
  406. fluent.Item("bypass_artifact_cache").Value(*path.BypassArtifactCache_);
  407. })
  408. .EndAttributes()
  409. .Value(path.Path_);
  410. }
  411. void Deserialize(TRichYPath& path, const TNode& node)
  412. {
  413. path = {};
  414. const auto& attributesMap = node.GetAttributes().AsMap();
  415. DESERIALIZE_ATTR("ranges", path.MutableRanges());
  416. DESERIALIZE_ATTR("columns", path.Columns_);
  417. DESERIALIZE_ATTR("append", path.Append_);
  418. DESERIALIZE_ATTR("partially_sorted", path.PartiallySorted_);
  419. DESERIALIZE_ATTR("sorted_by", path.SortedBy_);
  420. DESERIALIZE_ATTR("teleport", path.Teleport_);
  421. DESERIALIZE_ATTR("primary", path.Primary_);
  422. DESERIALIZE_ATTR("foreign", path.Foreign_);
  423. DESERIALIZE_ATTR("row_count_limit", path.RowCountLimit_);
  424. DESERIALIZE_ATTR("file_name", path.FileName_);
  425. DESERIALIZE_ATTR("original_path", path.OriginalPath_);
  426. DESERIALIZE_ATTR("executable", path.Executable_);
  427. DESERIALIZE_ATTR("format", path.Format_);
  428. DESERIALIZE_ATTR("schema", path.Schema_);
  429. DESERIALIZE_ATTR("timestamp", path.Timestamp_);
  430. DESERIALIZE_ATTR("compression_codec", path.CompressionCodec_);
  431. DESERIALIZE_ATTR("erasure_codec", path.ErasureCodec_);
  432. DESERIALIZE_ATTR("schema_modification", path.SchemaModification_);
  433. DESERIALIZE_ATTR("optimize_for", path.OptimizeFor_);
  434. DESERIALIZE_ATTR("transaction_id", path.TransactionId_);
  435. DESERIALIZE_ATTR("rename_columns", path.RenameColumns_);
  436. DESERIALIZE_ATTR("bypass_artifact_cache", path.BypassArtifactCache_);
  437. Deserialize(path.Path_, node);
  438. }
  439. void Serialize(const TAttributeFilter& filter, NYson::IYsonConsumer* consumer)
  440. {
  441. BuildYsonFluently(consumer).List(filter.Attributes_);
  442. }
  443. void Deserialize(TTableColumnarStatistics& statistics, const TNode& node)
  444. {
  445. const auto& nodeMap = node.AsMap();
  446. DESERIALIZE_ITEM("column_data_weights", statistics.ColumnDataWeight);
  447. DESERIALIZE_ITEM("legacy_chunks_data_weight", statistics.LegacyChunksDataWeight);
  448. DESERIALIZE_ITEM("timestamp_total_weight", statistics.TimestampTotalWeight);
  449. }
  450. void Deserialize(TMultiTablePartition::TStatistics& statistics, const TNode& node)
  451. {
  452. const auto& nodeMap = node.AsMap();
  453. DESERIALIZE_ITEM("chunk_count", statistics.ChunkCount);
  454. DESERIALIZE_ITEM("data_weight", statistics.DataWeight);
  455. DESERIALIZE_ITEM("row_count", statistics.RowCount);
  456. }
  457. void Deserialize(TMultiTablePartition& partition, const TNode& node)
  458. {
  459. const auto& nodeMap = node.AsMap();
  460. DESERIALIZE_ITEM("table_ranges", partition.TableRanges);
  461. DESERIALIZE_ITEM("aggregate_statistics", partition.AggregateStatistics);
  462. }
  463. void Deserialize(TMultiTablePartitions& partitions, const TNode& node)
  464. {
  465. const auto& nodeMap = node.AsMap();
  466. DESERIALIZE_ITEM("partitions", partitions.Partitions);
  467. }
  468. void Serialize(const TGUID& value, NYson::IYsonConsumer* consumer)
  469. {
  470. BuildYsonFluently(consumer).Value(GetGuidAsString(value));
  471. }
  472. void Deserialize(TGUID& value, const TNode& node)
  473. {
  474. value = GetGuid(node.AsString());
  475. }
  476. void Deserialize(TTabletInfo& value, const TNode& node)
  477. {
  478. auto nodeMap = node.AsMap();
  479. DESERIALIZE_ITEM("total_row_count", value.TotalRowCount)
  480. DESERIALIZE_ITEM("trimmed_row_count", value.TrimmedRowCount)
  481. DESERIALIZE_ITEM("barrier_timestamp", value.BarrierTimestamp)
  482. }
  483. void Serialize(const NTi::TTypePtr& type, NYson::IYsonConsumer* consumer)
  484. {
  485. auto yson = NTi::NIo::SerializeYson(type.Get());
  486. ::NYson::ParseYsonStringBuffer(yson, consumer);
  487. }
  488. void Deserialize(NTi::TTypePtr& type, const TNode& node)
  489. {
  490. auto yson = NodeToYsonString(node, NYson::EYsonFormat::Binary);
  491. type = NTi::NIo::DeserializeYson(*NTi::HeapFactory(), yson);
  492. }
  493. #undef DESERIALIZE_ITEM
  494. #undef DESERIALIZE_ATTR
  495. ////////////////////////////////////////////////////////////////////////////////
  496. } // namespace NYT