Skip to content

Commit b04fa4a

Browse files
author
cherepashka
committed
YT-24418: Code rearrangements around TTableSchema (logically it is zero diff)
Logical zero-diff (code rearrangement) for reducing code in future PRs related to constrained schemas commit_hash:c22b5bbdcac4a942a0284ef53f14559ef0b91551
1 parent 6802674 commit b04fa4a

File tree

4 files changed

+55
-42
lines changed

4 files changed

+55
-42
lines changed

yt/yt/client/table_client/schema.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@ class TColumnSchema
188188

189189
////////////////////////////////////////////////////////////////////////////////
190190

191+
void FormatValue(TStringBuilderBase* builder, const TColumnSchema& schema, TStringBuf spec);
192+
193+
void Serialize(const TColumnSchema& schema, NYson::IYsonConsumer* consumer);
194+
195+
void ToProto(NProto::TColumnSchema* protoSchema, const TColumnSchema& schema);
196+
void FromProto(TColumnSchema* schema, const NProto::TColumnSchema& protoSchema);
197+
198+
void PrintTo(const TColumnSchema& columnSchema, std::ostream* os);
199+
200+
////////////////////////////////////////////////////////////////////////////////
201+
191202
class TDeletedColumn
192203
{
193204
public:
@@ -200,18 +211,9 @@ class TDeletedColumn
200211

201212
////////////////////////////////////////////////////////////////////////////////
202213

203-
void FormatValue(TStringBuilderBase* builder, const TColumnSchema& schema, TStringBuf spec);
204-
205-
void Serialize(const TColumnSchema& schema, NYson::IYsonConsumer* consumer);
206-
207-
void ToProto(NProto::TColumnSchema* protoSchema, const TColumnSchema& schema);
208-
void FromProto(TColumnSchema* schema, const NProto::TColumnSchema& protoSchema);
209-
210214
void ToProto(NProto::TDeletedColumn* protoSchema, const TDeletedColumn& schema);
211215
void FromProto(TDeletedColumn* schema, const NProto::TDeletedColumn& protoSchema);
212216

213-
void PrintTo(const TColumnSchema& columnSchema, std::ostream* os);
214-
215217
////////////////////////////////////////////////////////////////////////////////
216218

217219
class TTableSchema final
@@ -419,8 +421,7 @@ class TTableSchema final
419421
TColumnInfo(std::vector<TColumnSchema> columns, std::vector<TDeletedColumn> deletedColumns)
420422
: Columns(std::move(columns))
421423
, DeletedColumns(std::move(deletedColumns))
422-
{
423-
}
424+
{ }
424425

425426
std::vector<TColumnSchema> Columns;
426427
std::vector<TDeletedColumn> DeletedColumns;
@@ -447,8 +448,8 @@ void FormatValue(TStringBuilderBase* builder, const TTableSchema& schema, TStrin
447448
void FormatValue(TStringBuilderBase* builder, const TTableSchemaPtr& schema, TStringBuf spec);
448449

449450
//! Returns serialized NTableClient.NProto.TTableSchemaExt.
450-
std::string SerializeToWireProto(const TTableSchemaPtr& schema);
451451
std::string SerializeToWireProto(const TTableSchema& schema);
452+
std::string SerializeToWireProto(const TTableSchemaPtr& schema);
452453

453454
void DeserializeFromWireProto(TTableSchemaPtr* schema, const std::string& serializedProto);
454455

yt/yt/client/table_client/schema_serialization_helpers.cpp

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
#include "schema_serialization_helpers.h"
2-
32
#include "comparator.h"
43

54
#include <yt/yt/core/ytree/fluent.h>
65

76
namespace NYT::NTableClient {
87

9-
void Deserialize(TMaybeDeletedColumnSchema& schema, NYson::TYsonPullParserCursor* cursor)
8+
using namespace NYson;
9+
using namespace NYTree;
10+
11+
////////////////////////////////////////////////////////////////////////////////
12+
13+
void Deserialize(TMaybeDeletedColumnSchema& schema, TYsonPullParserCursor* cursor)
1014
{
1115
TSerializableColumnSchema wrapper;
1216
wrapper.DeserializeFromCursor(cursor);
1317
schema = wrapper;
1418
}
1519

16-
void Deserialize(TMaybeDeletedColumnSchema& schema, NYTree::INodePtr node)
20+
void Deserialize(TMaybeDeletedColumnSchema& schema, INodePtr node)
1721
{
1822
TSerializableColumnSchema wrapper;
19-
Deserialize(static_cast<NYTree::TYsonStructLite&>(wrapper), node);
23+
Deserialize(static_cast<TYsonStructLite&>(wrapper), node);
2024
schema = static_cast<TMaybeDeletedColumnSchema>(wrapper);
2125
}
2226

@@ -25,6 +29,8 @@ TDeletedColumn TMaybeDeletedColumnSchema::GetDeletedColumnSchema() const
2529
return TDeletedColumn(StableName());
2630
}
2731

32+
////////////////////////////////////////////////////////////////////////////////
33+
2834
void TSerializableColumnSchema::Register(TRegistrar registrar)
2935
{
3036
registrar.BaseClassParameter("name", &TThis::Name_)
@@ -58,10 +64,10 @@ void TSerializableColumnSchema::Register(TRegistrar registrar)
5864
});
5965
}
6066

61-
void TSerializableColumnSchema::DeserializeFromCursor(NYson::TYsonPullParserCursor* cursor)
67+
void TSerializableColumnSchema::DeserializeFromCursor(TYsonPullParserCursor* cursor)
6268
{
63-
cursor->ParseMap([&] (NYson::TYsonPullParserCursor* cursor) {
64-
EnsureYsonToken("column schema attribute key", *cursor, NYson::EYsonItemType::StringValue);
69+
cursor->ParseMap([&] (TYsonPullParserCursor* cursor) {
70+
EnsureYsonToken("column schema attribute key", *cursor, EYsonItemType::StringValue);
6571
auto key = (*cursor)->UncheckedAsString();
6672
if (key == TStringBuf("name")) {
6773
cursor->Next();
@@ -210,14 +216,16 @@ void TSerializableColumnSchema::RunPostprocessor()
210216
}
211217
}
212218

213-
void Serialize(const TColumnSchema& schema, NYson::IYsonConsumer* consumer)
219+
////////////////////////////////////////////////////////////////////////////////
220+
221+
void Serialize(const TColumnSchema& schema, IYsonConsumer* consumer)
214222
{
215223
TSerializableColumnSchema wrapper;
216224
wrapper.SetColumnSchema(schema);
217-
Serialize(static_cast<const NYTree::TYsonStructLite&>(wrapper), consumer);
225+
Serialize(static_cast<const TYsonStructLite&>(wrapper), consumer);
218226
}
219227

220-
void Serialize(const TDeletedColumn& schema, NYson::IYsonConsumer* consumer)
228+
void Serialize(const TDeletedColumn& schema, IYsonConsumer* consumer)
221229
{
222230
consumer->OnBeginMap();
223231
consumer->OnKeyedItem("stable_name");
@@ -227,13 +235,13 @@ void Serialize(const TDeletedColumn& schema, NYson::IYsonConsumer* consumer)
227235
consumer->OnEndMap();
228236
}
229237

230-
void Serialize(const TTableSchema& schema, NYson::IYsonConsumer* consumer)
238+
void Serialize(const TTableSchema& schema, IYsonConsumer* consumer)
231239
{
232-
auto position = NYTree::BuildYsonFluently(consumer)
240+
auto position = BuildYsonFluently(consumer)
233241
.BeginAttributes()
234242
.Item("strict").Value(schema.IsStrict())
235243
.Item("unique_keys").Value(schema.IsUniqueKeys())
236-
.DoIf(schema.HasNontrivialSchemaModification(), [&] (NYTree::TFluentMap fluent) {
244+
.DoIf(schema.HasNontrivialSchemaModification(), [&] (TFluentMap fluent) {
237245
fluent.Item("schema_modification").Value(schema.GetSchemaModification());
238246
})
239247
.EndAttributes()
@@ -249,12 +257,7 @@ void Serialize(const TTableSchema& schema, NYson::IYsonConsumer* consumer)
249257
position.EndList();
250258
}
251259

252-
void Serialize(const TTableSchemaPtr& schema, NYson::IYsonConsumer* consumer)
253-
{
254-
Serialize(*schema, consumer);
255-
}
256-
257-
void Deserialize(TTableSchema& schema, NYTree::INodePtr node)
260+
void Deserialize(TTableSchema& schema, INodePtr node)
258261
{
259262
auto childNodes = node->AsList()->GetChildren();
260263

@@ -263,7 +266,7 @@ void Deserialize(TTableSchema& schema, NYTree::INodePtr node)
263266

264267
for (auto childNode : childNodes) {
265268
TSerializableColumnSchema wrapper;
266-
Deserialize(static_cast<NYTree::TYsonStructLite&>(wrapper), childNode);
269+
Deserialize(static_cast<TYsonStructLite&>(wrapper), childNode);
267270
if (wrapper.Deleted() && *wrapper.Deleted()) {
268271
deletedColumns.push_back(TDeletedColumn(wrapper.StableName()));
269272
} else {
@@ -281,15 +284,15 @@ void Deserialize(TTableSchema& schema, NYTree::INodePtr node)
281284
deletedColumns);
282285
}
283286

284-
void Deserialize(TTableSchema& schema, NYson::TYsonPullParserCursor* cursor)
287+
void Deserialize(TTableSchema& schema, TYsonPullParserCursor* cursor)
285288
{
286-
bool strict = true;
287-
bool uniqueKeys = false;
288-
ETableSchemaModification modification = ETableSchemaModification::None;
289+
auto strict = true;
290+
auto uniqueKeys = false;
291+
auto modification = ETableSchemaModification::None;
289292

290-
if ((*cursor)->GetType() == NYson::EYsonItemType::BeginAttributes) {
291-
cursor->ParseAttributes([&] (NYson::TYsonPullParserCursor* cursor) {
292-
EnsureYsonToken(TStringBuf("table schema attribute key"), *cursor, NYson::EYsonItemType::StringValue);
293+
if ((*cursor)->GetType() == EYsonItemType::BeginAttributes) {
294+
cursor->ParseAttributes([&] (TYsonPullParserCursor* cursor) {
295+
EnsureYsonToken(TStringBuf("table schema attribute key"), *cursor, EYsonItemType::StringValue);
293296
auto key = (*cursor)->UncheckedAsString();
294297
if (key == TStringBuf("strict")) {
295298
cursor->Next();
@@ -307,7 +310,7 @@ void Deserialize(TTableSchema& schema, NYson::TYsonPullParserCursor* cursor)
307310
});
308311
}
309312

310-
EnsureYsonToken(TStringBuf("table schema"), *cursor, NYson::EYsonItemType::BeginList);
313+
EnsureYsonToken(TStringBuf("table schema"), *cursor, EYsonItemType::BeginList);
311314

312315
auto maybeDeletedColumns = ExtractTo<std::vector<TMaybeDeletedColumnSchema>>(cursor);
313316

@@ -325,14 +328,19 @@ void Deserialize(TTableSchema& schema, NYson::TYsonPullParserCursor* cursor)
325328
schema = TTableSchema(columns, strict, uniqueKeys, modification, deletedColumns);
326329
}
327330

328-
void Deserialize(TTableSchemaPtr& schema, NYTree::INodePtr node)
331+
void Serialize(const TTableSchemaPtr& schema, IYsonConsumer* consumer)
332+
{
333+
Serialize(*schema, consumer);
334+
}
335+
336+
void Deserialize(TTableSchemaPtr& schema, INodePtr node)
329337
{
330338
TTableSchema actualSchema;
331339
Deserialize(actualSchema, node);
332340
schema = New<TTableSchema>(std::move(actualSchema));
333341
}
334342

335-
void Deserialize(TTableSchemaPtr& schema, NYson::TYsonPullParserCursor* cursor)
343+
void Deserialize(TTableSchemaPtr& schema, TYsonPullParserCursor* cursor)
336344
{
337345
TTableSchema actualSchema;
338346
Deserialize(actualSchema, cursor);

yt/yt/client/table_client/schema_serialization_helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace NYT::NTableClient {
1111

12+
////////////////////////////////////////////////////////////////////////////////
13+
1214
struct TMaybeDeletedColumnSchema
1315
: public TColumnSchema
1416
{

yt/yt/client/table_client/unittests/serialization_ut.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#include <yt/yt/library/named_value/named_value.h>
77

88
#include <yt/yt/core/misc/blob_output.h>
9+
910
#include <yt/yt/core/ytree/convert.h>
11+
1012
#include <yt/yt/core/test_framework/framework.h>
1113

1214
namespace NYT::NTableClient {

0 commit comments

Comments
 (0)