serialize.cpp 21 KB

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