diff options
author | cherepashka <[email protected]> | 2025-05-21 22:35:01 +0300 |
---|---|---|
committer | cherepashka <[email protected]> | 2025-05-21 22:47:50 +0300 |
commit | b04fa4a193f3776d4a9cd992a81575a0cf996856 (patch) | |
tree | 860f5107fc9a6b3dbba5e98870231753e11c9bda | |
parent | 680267404b9924465250d6157bc00b0fd194a0c2 (diff) |
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
4 files changed, 55 insertions, 42 deletions
diff --git a/yt/yt/client/table_client/schema.h b/yt/yt/client/table_client/schema.h index 7c031488690..66f6ce11696 100644 --- a/yt/yt/client/table_client/schema.h +++ b/yt/yt/client/table_client/schema.h @@ -188,6 +188,17 @@ private: //////////////////////////////////////////////////////////////////////////////// +void FormatValue(TStringBuilderBase* builder, const TColumnSchema& schema, TStringBuf spec); + +void Serialize(const TColumnSchema& schema, NYson::IYsonConsumer* consumer); + +void ToProto(NProto::TColumnSchema* protoSchema, const TColumnSchema& schema); +void FromProto(TColumnSchema* schema, const NProto::TColumnSchema& protoSchema); + +void PrintTo(const TColumnSchema& columnSchema, std::ostream* os); + +//////////////////////////////////////////////////////////////////////////////// + class TDeletedColumn { public: @@ -200,18 +211,9 @@ public: //////////////////////////////////////////////////////////////////////////////// -void FormatValue(TStringBuilderBase* builder, const TColumnSchema& schema, TStringBuf spec); - -void Serialize(const TColumnSchema& schema, NYson::IYsonConsumer* consumer); - -void ToProto(NProto::TColumnSchema* protoSchema, const TColumnSchema& schema); -void FromProto(TColumnSchema* schema, const NProto::TColumnSchema& protoSchema); - void ToProto(NProto::TDeletedColumn* protoSchema, const TDeletedColumn& schema); void FromProto(TDeletedColumn* schema, const NProto::TDeletedColumn& protoSchema); -void PrintTo(const TColumnSchema& columnSchema, std::ostream* os); - //////////////////////////////////////////////////////////////////////////////// class TTableSchema final @@ -419,8 +421,7 @@ private: TColumnInfo(std::vector<TColumnSchema> columns, std::vector<TDeletedColumn> deletedColumns) : Columns(std::move(columns)) , DeletedColumns(std::move(deletedColumns)) - { - } + { } std::vector<TColumnSchema> Columns; std::vector<TDeletedColumn> DeletedColumns; @@ -447,8 +448,8 @@ void FormatValue(TStringBuilderBase* builder, const TTableSchema& schema, TStrin void FormatValue(TStringBuilderBase* builder, const TTableSchemaPtr& schema, TStringBuf spec); //! Returns serialized NTableClient.NProto.TTableSchemaExt. -std::string SerializeToWireProto(const TTableSchemaPtr& schema); std::string SerializeToWireProto(const TTableSchema& schema); +std::string SerializeToWireProto(const TTableSchemaPtr& schema); void DeserializeFromWireProto(TTableSchemaPtr* schema, const std::string& serializedProto); diff --git a/yt/yt/client/table_client/schema_serialization_helpers.cpp b/yt/yt/client/table_client/schema_serialization_helpers.cpp index d079832c771..4cde8509b06 100644 --- a/yt/yt/client/table_client/schema_serialization_helpers.cpp +++ b/yt/yt/client/table_client/schema_serialization_helpers.cpp @@ -1,22 +1,26 @@ #include "schema_serialization_helpers.h" - #include "comparator.h" #include <yt/yt/core/ytree/fluent.h> namespace NYT::NTableClient { -void Deserialize(TMaybeDeletedColumnSchema& schema, NYson::TYsonPullParserCursor* cursor) +using namespace NYson; +using namespace NYTree; + +//////////////////////////////////////////////////////////////////////////////// + +void Deserialize(TMaybeDeletedColumnSchema& schema, TYsonPullParserCursor* cursor) { TSerializableColumnSchema wrapper; wrapper.DeserializeFromCursor(cursor); schema = wrapper; } -void Deserialize(TMaybeDeletedColumnSchema& schema, NYTree::INodePtr node) +void Deserialize(TMaybeDeletedColumnSchema& schema, INodePtr node) { TSerializableColumnSchema wrapper; - Deserialize(static_cast<NYTree::TYsonStructLite&>(wrapper), node); + Deserialize(static_cast<TYsonStructLite&>(wrapper), node); schema = static_cast<TMaybeDeletedColumnSchema>(wrapper); } @@ -25,6 +29,8 @@ TDeletedColumn TMaybeDeletedColumnSchema::GetDeletedColumnSchema() const return TDeletedColumn(StableName()); } +//////////////////////////////////////////////////////////////////////////////// + void TSerializableColumnSchema::Register(TRegistrar registrar) { registrar.BaseClassParameter("name", &TThis::Name_) @@ -58,10 +64,10 @@ void TSerializableColumnSchema::Register(TRegistrar registrar) }); } -void TSerializableColumnSchema::DeserializeFromCursor(NYson::TYsonPullParserCursor* cursor) +void TSerializableColumnSchema::DeserializeFromCursor(TYsonPullParserCursor* cursor) { - cursor->ParseMap([&] (NYson::TYsonPullParserCursor* cursor) { - EnsureYsonToken("column schema attribute key", *cursor, NYson::EYsonItemType::StringValue); + cursor->ParseMap([&] (TYsonPullParserCursor* cursor) { + EnsureYsonToken("column schema attribute key", *cursor, EYsonItemType::StringValue); auto key = (*cursor)->UncheckedAsString(); if (key == TStringBuf("name")) { cursor->Next(); @@ -210,14 +216,16 @@ void TSerializableColumnSchema::RunPostprocessor() } } -void Serialize(const TColumnSchema& schema, NYson::IYsonConsumer* consumer) +//////////////////////////////////////////////////////////////////////////////// + +void Serialize(const TColumnSchema& schema, IYsonConsumer* consumer) { TSerializableColumnSchema wrapper; wrapper.SetColumnSchema(schema); - Serialize(static_cast<const NYTree::TYsonStructLite&>(wrapper), consumer); + Serialize(static_cast<const TYsonStructLite&>(wrapper), consumer); } -void Serialize(const TDeletedColumn& schema, NYson::IYsonConsumer* consumer) +void Serialize(const TDeletedColumn& schema, IYsonConsumer* consumer) { consumer->OnBeginMap(); consumer->OnKeyedItem("stable_name"); @@ -227,13 +235,13 @@ void Serialize(const TDeletedColumn& schema, NYson::IYsonConsumer* consumer) consumer->OnEndMap(); } -void Serialize(const TTableSchema& schema, NYson::IYsonConsumer* consumer) +void Serialize(const TTableSchema& schema, IYsonConsumer* consumer) { - auto position = NYTree::BuildYsonFluently(consumer) + auto position = BuildYsonFluently(consumer) .BeginAttributes() .Item("strict").Value(schema.IsStrict()) .Item("unique_keys").Value(schema.IsUniqueKeys()) - .DoIf(schema.HasNontrivialSchemaModification(), [&] (NYTree::TFluentMap fluent) { + .DoIf(schema.HasNontrivialSchemaModification(), [&] (TFluentMap fluent) { fluent.Item("schema_modification").Value(schema.GetSchemaModification()); }) .EndAttributes() @@ -249,12 +257,7 @@ void Serialize(const TTableSchema& schema, NYson::IYsonConsumer* consumer) position.EndList(); } -void Serialize(const TTableSchemaPtr& schema, NYson::IYsonConsumer* consumer) -{ - Serialize(*schema, consumer); -} - -void Deserialize(TTableSchema& schema, NYTree::INodePtr node) +void Deserialize(TTableSchema& schema, INodePtr node) { auto childNodes = node->AsList()->GetChildren(); @@ -263,7 +266,7 @@ void Deserialize(TTableSchema& schema, NYTree::INodePtr node) for (auto childNode : childNodes) { TSerializableColumnSchema wrapper; - Deserialize(static_cast<NYTree::TYsonStructLite&>(wrapper), childNode); + Deserialize(static_cast<TYsonStructLite&>(wrapper), childNode); if (wrapper.Deleted() && *wrapper.Deleted()) { deletedColumns.push_back(TDeletedColumn(wrapper.StableName())); } else { @@ -281,15 +284,15 @@ void Deserialize(TTableSchema& schema, NYTree::INodePtr node) deletedColumns); } -void Deserialize(TTableSchema& schema, NYson::TYsonPullParserCursor* cursor) +void Deserialize(TTableSchema& schema, TYsonPullParserCursor* cursor) { - bool strict = true; - bool uniqueKeys = false; - ETableSchemaModification modification = ETableSchemaModification::None; + auto strict = true; + auto uniqueKeys = false; + auto modification = ETableSchemaModification::None; - if ((*cursor)->GetType() == NYson::EYsonItemType::BeginAttributes) { - cursor->ParseAttributes([&] (NYson::TYsonPullParserCursor* cursor) { - EnsureYsonToken(TStringBuf("table schema attribute key"), *cursor, NYson::EYsonItemType::StringValue); + if ((*cursor)->GetType() == EYsonItemType::BeginAttributes) { + cursor->ParseAttributes([&] (TYsonPullParserCursor* cursor) { + EnsureYsonToken(TStringBuf("table schema attribute key"), *cursor, EYsonItemType::StringValue); auto key = (*cursor)->UncheckedAsString(); if (key == TStringBuf("strict")) { cursor->Next(); @@ -307,7 +310,7 @@ void Deserialize(TTableSchema& schema, NYson::TYsonPullParserCursor* cursor) }); } - EnsureYsonToken(TStringBuf("table schema"), *cursor, NYson::EYsonItemType::BeginList); + EnsureYsonToken(TStringBuf("table schema"), *cursor, EYsonItemType::BeginList); auto maybeDeletedColumns = ExtractTo<std::vector<TMaybeDeletedColumnSchema>>(cursor); @@ -325,14 +328,19 @@ void Deserialize(TTableSchema& schema, NYson::TYsonPullParserCursor* cursor) schema = TTableSchema(columns, strict, uniqueKeys, modification, deletedColumns); } -void Deserialize(TTableSchemaPtr& schema, NYTree::INodePtr node) +void Serialize(const TTableSchemaPtr& schema, IYsonConsumer* consumer) +{ + Serialize(*schema, consumer); +} + +void Deserialize(TTableSchemaPtr& schema, INodePtr node) { TTableSchema actualSchema; Deserialize(actualSchema, node); schema = New<TTableSchema>(std::move(actualSchema)); } -void Deserialize(TTableSchemaPtr& schema, NYson::TYsonPullParserCursor* cursor) +void Deserialize(TTableSchemaPtr& schema, TYsonPullParserCursor* cursor) { TTableSchema actualSchema; Deserialize(actualSchema, cursor); diff --git a/yt/yt/client/table_client/schema_serialization_helpers.h b/yt/yt/client/table_client/schema_serialization_helpers.h index 4aeca670370..cf6d17d4f55 100644 --- a/yt/yt/client/table_client/schema_serialization_helpers.h +++ b/yt/yt/client/table_client/schema_serialization_helpers.h @@ -9,6 +9,8 @@ namespace NYT::NTableClient { +//////////////////////////////////////////////////////////////////////////////// + struct TMaybeDeletedColumnSchema : public TColumnSchema { diff --git a/yt/yt/client/table_client/unittests/serialization_ut.cpp b/yt/yt/client/table_client/unittests/serialization_ut.cpp index ffa87259595..c3cc622b3e3 100644 --- a/yt/yt/client/table_client/unittests/serialization_ut.cpp +++ b/yt/yt/client/table_client/unittests/serialization_ut.cpp @@ -6,7 +6,9 @@ #include <yt/yt/library/named_value/named_value.h> #include <yt/yt/core/misc/blob_output.h> + #include <yt/yt/core/ytree/convert.h> + #include <yt/yt/core/test_framework/framework.h> namespace NYT::NTableClient { |