serialize.cpp 21 KB

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