Browse Source

Intermediate changes

robot-piglet 1 year ago
parent
commit
2e3fc003e4

+ 36 - 42
yt/yt/client/api/rpc_proxy/helpers.cpp

@@ -77,9 +77,9 @@ void ToProto(
 {
     proto->set_read_from(static_cast<NProto::EMasterReadKind>(options.ReadFrom));
     proto->set_disable_per_user_cache(options.DisablePerUserCache);
-    proto->set_expire_after_successful_update_time(NYT::ToProto<i64>(options.ExpireAfterSuccessfulUpdateTime));
-    proto->set_expire_after_failed_update_time(NYT::ToProto<i64>(options.ExpireAfterFailedUpdateTime));
-    proto->set_success_staleness_bound(NYT::ToProto<i64>(options.SuccessStalenessBound));
+    proto->set_expire_after_successful_update_time(ToProto<i64>(options.ExpireAfterSuccessfulUpdateTime));
+    proto->set_expire_after_failed_update_time(ToProto<i64>(options.ExpireAfterFailedUpdateTime));
+    proto->set_success_staleness_bound(ToProto<i64>(options.SuccessStalenessBound));
     if (options.CacheStickyGroupSize) {
         proto->set_cache_sticky_group_size(*options.CacheStickyGroupSize);
     }
@@ -120,7 +120,7 @@ void ToProto(
 {
     protoOptions->set_read_from(static_cast<NProto::ETabletReadKind>(options.ReadFrom));
     if (options.CachedSyncReplicasTimeout) {
-        protoOptions->set_cached_sync_replicas_timeout(NYT::ToProto<i64>(*options.CachedSyncReplicasTimeout));
+        protoOptions->set_cached_sync_replicas_timeout(ToProto<i64>(*options.CachedSyncReplicasTimeout));
     }
 }
 
@@ -235,7 +235,7 @@ void ToProto(
         proto->set_subject_name(*result.SubjectName);
     }
 
-    NYT::ToProto(proto->mutable_missing_subjects(), result.MissingSubjects);
+    ToProto(proto->mutable_missing_subjects(), result.MissingSubjects);
 }
 
 void FromProto(
@@ -251,7 +251,7 @@ void FromProto(
         result->SubjectName.reset();
     }
 
-    NYT::FromProto(&result->MissingSubjects, proto.missing_subjects());
+    FromProto(&result->MissingSubjects, proto.missing_subjects());
 }
 
 void ToProto(
@@ -259,7 +259,7 @@ void ToProto(
     const NApi::TListOperationsResult& result)
 {
     proto->Clear();
-    NYT::ToProto(proto->mutable_operations(), result.Operations);
+    ToProto(proto->mutable_operations(), result.Operations);
 
     if (result.PoolTreeCounts) {
         auto* poolTreeCounts = proto->mutable_pool_tree_counts()->mutable_entries();
@@ -311,7 +311,7 @@ void FromProto(
     NApi::TListOperationsResult* result,
     const NProto::TListOperationsResult& proto)
 {
-    NYT::FromProto(&result->Operations, proto.operations());
+    FromProto(&result->Operations, proto.operations());
 
     if (proto.has_pool_tree_counts()) {
         result->PoolTreeCounts.emplace();
@@ -382,7 +382,7 @@ void ToProto(
     const NApi::TListJobsResult& result)
 {
     proto->Clear();
-    NYT::ToProto(proto->mutable_jobs(), result.Jobs);
+    ToProto(proto->mutable_jobs(), result.Jobs);
 
     if (result.CypressJobCount) {
         proto->set_cypress_job_count(*result.CypressJobCount);
@@ -395,14 +395,14 @@ void ToProto(
     }
 
     ToProto(proto->mutable_statistics(), result.Statistics);
-    NYT::ToProto(proto->mutable_errors(), result.Errors);
+    ToProto(proto->mutable_errors(), result.Errors);
 }
 
 void FromProto(
     NApi::TListJobsResult* result,
     const NProto::TListJobsResult& proto)
 {
-    NYT::FromProto(&result->Jobs, proto.jobs());
+    FromProto(&result->Jobs, proto.jobs());
 
     if (proto.has_cypress_job_count()) {
         result->CypressJobCount = proto.cypress_job_count();
@@ -421,7 +421,7 @@ void FromProto(
     }
 
     FromProto(&result->Statistics, proto.statistics());
-    NYT::FromProto(&result->Errors, proto.errors());
+    FromProto(&result->Errors, proto.errors());
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -430,9 +430,9 @@ void FromProto(
 
 void ToProto(NProto::TColumnSchema* protoSchema, const NTableClient::TColumnSchema& schema)
 {
-    protoSchema->set_stable_name(schema.StableName().Get());
+    protoSchema->set_stable_name(schema.StableName().Underlying());
     protoSchema->set_name(schema.Name());
-    protoSchema->set_type(NYT::ToProto<int>(GetPhysicalType(schema.CastToV1Type())));
+    protoSchema->set_type(ToProto<int>(GetPhysicalType(schema.CastToV1Type())));
     auto typeV3Yson = ConvertToYsonString(TTypeV3LogicalTypeWrapper{schema.LogicalType()});
     protoSchema->set_type_v3(typeV3Yson.ToString());
     if (schema.Lock()) {
@@ -451,7 +451,7 @@ void ToProto(NProto::TColumnSchema* protoSchema, const NTableClient::TColumnSche
         protoSchema->clear_aggregate();
     }
     if (schema.SortOrder()) {
-        protoSchema->set_sort_order(NYT::ToProto<int>(*schema.SortOrder()));
+        protoSchema->set_sort_order(ToProto<int>(*schema.SortOrder()));
     } else {
         protoSchema->clear_sort_order();
     }
@@ -477,8 +477,8 @@ void FromProto(NTableClient::TColumnSchema* schema, const NProto::TColumnSchema&
     schema->SetName(protoSchema.name());
     schema->SetStableName(
         protoSchema.has_stable_name()
-        ? TStableName(protoSchema.stable_name())
-        : TStableName(protoSchema.name()));
+        ? TColumnStableName(protoSchema.stable_name())
+        : TColumnStableName(protoSchema.name()));
 
     auto physicalType = CheckedEnumCast<EValueType>(protoSchema.type());
 
@@ -491,10 +491,10 @@ void FromProto(NTableClient::TColumnSchema* schema, const NProto::TColumnSchema&
                 << TErrorAttribute("type_v3", ToString(*columnType))
                 << TErrorAttribute("required", protoSchema.required());
         }
-        if (protoSchema.has_logical_type() && v1Type != NYT::FromProto<ESimpleLogicalValueType>(protoSchema.logical_type())) {
+        if (protoSchema.has_logical_type() && v1Type != FromProto<ESimpleLogicalValueType>(protoSchema.logical_type())) {
             THROW_ERROR_EXCEPTION("Fields \"type_v3\" and \"logical_type\" do not match")
                 << TErrorAttribute("type_v3", ToString(*columnType))
-                << TErrorAttribute("logical_type", NYT::FromProto<ESimpleLogicalValueType>(protoSchema.logical_type()));
+                << TErrorAttribute("logical_type", FromProto<ESimpleLogicalValueType>(protoSchema.logical_type()));
         }
         if (protoSchema.has_type() && GetPhysicalType(v1Type) != physicalType) {
             THROW_ERROR_EXCEPTION("Fields \"type_v3\" and \"logical_type\" do not match")
@@ -528,8 +528,6 @@ void FromProto(NTableClient::TColumnSchema* schema, const NProto::TColumnSchema&
 
 void ToProto(NProto::TTableSchema* protoSchema, const NTableClient::TTableSchema& schema)
 {
-    using NYT::ToProto;
-
     ToProto(protoSchema->mutable_columns(), schema.Columns());
     protoSchema->set_strict(schema.GetStrict());
     protoSchema->set_unique_keys(schema.GetUniqueKeys());
@@ -537,8 +535,6 @@ void ToProto(NProto::TTableSchema* protoSchema, const NTableClient::TTableSchema
 
 void FromProto(NTableClient::TTableSchema* schema, const NProto::TTableSchema& protoSchema)
 {
-    using NYT::FromProto;
-
     *schema = NTableClient::TTableSchema(
         FromProto<std::vector<NTableClient::TColumnSchema>>(protoSchema.columns()),
         protoSchema.strict(),
@@ -569,8 +565,6 @@ void ToProto(NProto::TTabletInfo* protoTabletInfo, const NTabletClient::TTabletI
 
 void FromProto(NTabletClient::TTabletInfo* tabletInfo, const NProto::TTabletInfo& protoTabletInfo)
 {
-    using NYT::FromProto;
-
     tabletInfo->TabletId =
         FromProto<TTabletId>(protoTabletInfo.tablet_id());
     tabletInfo->MountRevision = protoTabletInfo.mount_revision();
@@ -599,7 +593,7 @@ void ToProto(
     protoStatistics->set_incomplete_output(statistics.IncompleteOutput);
     protoStatistics->set_memory_usage(statistics.MemoryUsage);
 
-    NYT::ToProto(protoStatistics->mutable_inner_statistics(), statistics.InnerStatistics);
+    ToProto(protoStatistics->mutable_inner_statistics(), statistics.InnerStatistics);
 }
 
 void FromProto(
@@ -620,7 +614,7 @@ void FromProto(
     statistics->IncompleteOutput = protoStatistics.incomplete_output();
     statistics->MemoryUsage = protoStatistics.memory_usage();
 
-    NYT::FromProto(&statistics->InnerStatistics, protoStatistics.inner_statistics());
+    FromProto(&statistics->InnerStatistics, protoStatistics.inner_statistics());
 }
 
 void ToProto(NProto::TOperation* protoOperation, const NApi::TOperation& operation)
@@ -638,10 +632,10 @@ void ToProto(NProto::TOperation* protoOperation, const NApi::TOperation& operati
     }
 
     if (operation.StartTime) {
-        protoOperation->set_start_time(NYT::ToProto<i64>(*operation.StartTime));
+        protoOperation->set_start_time(ToProto<i64>(*operation.StartTime));
     }
     if (operation.FinishTime) {
-        protoOperation->set_finish_time(NYT::ToProto<i64>(*operation.FinishTime));
+        protoOperation->set_finish_time(ToProto<i64>(*operation.FinishTime));
     }
 
     if (operation.AuthenticatedUser) {
@@ -719,7 +713,7 @@ void ToProto(NProto::TOperation* protoOperation, const NApi::TOperation& operati
 void FromProto(NApi::TOperation* operation, const NProto::TOperation& protoOperation)
 {
     if (protoOperation.has_id()) {
-        operation->Id = NYT::FromProto<NScheduler::TOperationId>(protoOperation.id());
+        operation->Id = FromProto<NScheduler::TOperationId>(protoOperation.id());
     } else {
         operation->Id.reset();
     }
@@ -883,10 +877,10 @@ void ToProto(NProto::TJob* protoJob, const NApi::TJob& job)
     }
 
     if (job.StartTime) {
-        protoJob->set_start_time(NYT::ToProto<i64>(*job.StartTime));
+        protoJob->set_start_time(ToProto<i64>(*job.StartTime));
     }
     if (job.FinishTime) {
-        protoJob->set_finish_time(NYT::ToProto<i64>(*job.FinishTime));
+        protoJob->set_finish_time(ToProto<i64>(*job.FinishTime));
     }
 
     if (job.Address) {
@@ -1150,10 +1144,10 @@ void FromProto(
     const NChunkClient::TFetchChunkSpecConfigPtr& fetchChunkSpecConfig,
     const NProto::TFetchChunkSpecConfig& protoFetchChunkSpecConfig)
 {
-    NYT::FromProto(
+    FromProto(
         &fetchChunkSpecConfig->MaxChunksPerFetch,
         protoFetchChunkSpecConfig.max_chunk_per_fetch());
-    NYT::FromProto(
+    FromProto(
         &fetchChunkSpecConfig->MaxChunksPerLocateRequest,
         protoFetchChunkSpecConfig.max_chunk_per_locate_request());
 }
@@ -1163,7 +1157,7 @@ void ToProto(
     const NChunkClient::TFetcherConfigPtr& fetcherConfig)
 {
     protoFetcherConfig->set_node_rpc_timeout(
-        NYT::ToProto<i64>(fetcherConfig->NodeRpcTimeout));
+        ToProto<i64>(fetcherConfig->NodeRpcTimeout));
 }
 
 void FromProto(
@@ -1179,7 +1173,7 @@ void ToProto(
 {
     protoStatistics->Clear();
 
-    NYT::ToProto(protoStatistics->mutable_column_data_weights(), statistics.ColumnDataWeights);
+    ToProto(protoStatistics->mutable_column_data_weights(), statistics.ColumnDataWeights);
     if (statistics.TimestampTotalWeight) {
         protoStatistics->set_timestamp_total_weight(*statistics.TimestampTotalWeight);
     }
@@ -1187,7 +1181,7 @@ void ToProto(
 
     NYT::NTableClient::ToProto(protoStatistics->mutable_column_min_values(), statistics.ColumnMinValues);
     NYT::NTableClient::ToProto(protoStatistics->mutable_column_max_values(), statistics.ColumnMaxValues);
-    NYT::ToProto(protoStatistics->mutable_column_non_null_value_counts(), statistics.ColumnNonNullValueCounts);
+    ToProto(protoStatistics->mutable_column_non_null_value_counts(), statistics.ColumnNonNullValueCounts);
 
     if (statistics.ChunkRowCount) {
         protoStatistics->set_chunk_row_count(*statistics.ChunkRowCount);
@@ -1201,7 +1195,7 @@ void FromProto(
     NTableClient::TColumnarStatistics* statistics,
     const NProto::TColumnarStatistics& protoStatistics)
 {
-    NYT::FromProto(&statistics->ColumnDataWeights, protoStatistics.column_data_weights());
+    FromProto(&statistics->ColumnDataWeights, protoStatistics.column_data_weights());
     if (protoStatistics.has_timestamp_total_weight()) {
         statistics->TimestampTotalWeight = protoStatistics.timestamp_total_weight();
     } else {
@@ -1211,7 +1205,7 @@ void FromProto(
 
     NYT::NTableClient::FromProto(&statistics->ColumnMinValues, protoStatistics.column_min_values());
     NYT::NTableClient::FromProto(&statistics->ColumnMaxValues, protoStatistics.column_max_values());
-    NYT::FromProto(&statistics->ColumnNonNullValueCounts, protoStatistics.column_non_null_value_counts());
+    FromProto(&statistics->ColumnNonNullValueCounts, protoStatistics.column_non_null_value_counts());
 
     if (protoStatistics.has_chunk_row_count()) {
         statistics->ChunkRowCount = protoStatistics.chunk_row_count();
@@ -1261,7 +1255,7 @@ void FromProto(
     NApi::TMultiTablePartitions* multiTablePartitions,
     const NProto::TRspPartitionTables& protoRspPartitionTables)
 {
-    NYT::FromProto(
+    FromProto(
         &multiTablePartitions->Partitions,
         protoRspPartitionTables.partitions());
 }
@@ -1804,7 +1798,7 @@ TTableSchemaPtr DeserializeRowsetSchema(
     const NProto::TRowsetDescriptor& descriptor)
 {
     if (descriptor.has_schema()) {
-        return NYT::FromProto<TTableSchemaPtr>(descriptor.schema());
+        return FromProto<TTableSchemaPtr>(descriptor.schema());
     }
 
     // COMPAT(babenko)
@@ -1814,7 +1808,7 @@ TTableSchemaPtr DeserializeRowsetSchema(
         const auto& entry = descriptor.name_table_entries(i);
         if (entry.has_name()) {
             columns[i].SetName(entry.name());
-            columns[i].SetStableName(TStableName(entry.name()));
+            columns[i].SetStableName(TColumnStableName(entry.name()));
         }
         if (entry.has_logical_type()) {
             auto simpleLogicalType = CheckedEnumCast<NTableClient::ESimpleLogicalValueType>(entry.logical_type());

+ 6 - 6
yt/yt/client/table_client/check_schema_compatibility.cpp

@@ -57,8 +57,8 @@ std::pair<ESchemaCompatibility, TError> CheckTableSchemaCompatibilityImpl(
                     ESchemaCompatibility::Incompatible,
                     TError("Column %Qv has stable name %Qv in input and %Qv in output schema",
                         inputColumn->Name(),
-                        inputColumn->StableName().Get(),
-                        outputColumn.StableName().Get())
+                        inputColumn->StableName(),
+                        outputColumn.StableName())
                 };
             }
 
@@ -121,8 +121,8 @@ std::pair<ESchemaCompatibility, TError> CheckTableSchemaCompatibilityImpl(
         if (!inputColumn && !deletedColumn) {
             return {
                 ESchemaCompatibility::Incompatible,
-                TError("Deleted column \"%v\" is missing in the input schema",
-                    deletedOutputColumn.StableName().Get())
+                TError("Deleted column %Qv is missing in the input schema",
+                    deletedOutputColumn.StableName())
             };
         }
     }
@@ -133,8 +133,8 @@ std::pair<ESchemaCompatibility, TError> CheckTableSchemaCompatibilityImpl(
         if (!deletedOutputColumn) {
             return {
                 ESchemaCompatibility::Incompatible,
-                TError("Deleted column \"%v\" must be deleted in the output schema",
-                    deletedInputColumn.StableName().Get())
+                TError("Deleted column %Qv must be deleted in the output schema",
+                    deletedInputColumn.StableName())
             };
         }
     }

+ 2 - 3
yt/yt/client/table_client/columnar_statistics.cpp

@@ -296,13 +296,12 @@ void TColumnarStatistics::Update(TRange<TVersionedRow> rows)
     }
 }
 
-TColumnarStatistics TColumnarStatistics::SelectByColumnNames(const TNameTablePtr& nameTable, const std::vector<TStableName>& columnStableNames) const
+TColumnarStatistics TColumnarStatistics::SelectByColumnNames(const TNameTablePtr& nameTable, const std::vector<TColumnStableName>& columnStableNames) const
 {
     auto result = MakeEmpty(columnStableNames.size(), HasValueStatistics());
 
     for (const auto& [columnIndex, columnName] : Enumerate(columnStableNames)) {
-        if (auto id = nameTable->FindId(columnName.Get()); id && *id < GetColumnCount()) {
-
+        if (auto id = nameTable->FindId(columnName.Underlying()); id && *id < GetColumnCount()) {
             result.ColumnDataWeights[columnIndex] = ColumnDataWeights[*id];
 
             if (HasValueStatistics()) {

+ 3 - 1
yt/yt/client/table_client/columnar_statistics.h

@@ -87,7 +87,9 @@ struct TColumnarStatistics
     void Update(TRange<TUnversionedRow> rows);
     void Update(TRange<TVersionedRow> rows);
 
-    TColumnarStatistics SelectByColumnNames(const TNameTablePtr& nameTable, const std::vector<TStableName>& columnStableNames) const;
+    TColumnarStatistics SelectByColumnNames(
+        const TNameTablePtr& nameTable,
+        const std::vector<TColumnStableName>& columnStableNames) const;
 };
 
 ////////////////////////////////////////////////////////////////////////////////

+ 1 - 1
yt/yt/client/table_client/name_table.cpp

@@ -26,7 +26,7 @@ TNameTablePtr TNameTable::FromSchemaStable(const TTableSchema& schema)
     auto nameTable = New<TNameTable>();
     nameTable->NameToId_.reserve(schema.Columns().size());
     for (const auto& column : schema.Columns()) {
-        nameTable->DoRegisterNameOrThrow(column.StableName().Get());
+        nameTable->DoRegisterNameOrThrow(column.StableName().Underlying());
     }
     return nameTable;
 }

+ 2 - 3
yt/yt/client/table_client/public.h

@@ -9,11 +9,10 @@
 #include <yt/yt/core/misc/range.h>
 
 #include <library/cpp/yt/misc/enum.h>
+#include <library/cpp/yt/misc/strong_typedef.h>
 
 #include <util/generic/size_literals.h>
 
-#include <initializer_list>
-
 namespace NYT::NTableClient {
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -299,7 +298,7 @@ class TKeyComparer;
 struct TColumnRenameDescriptor;
 using TColumnRenameDescriptors = std::vector<TColumnRenameDescriptor>;
 
-class TStableName;
+YT_DEFINE_STRONG_TYPEDEF(TColumnStableName, TString);
 
 class TColumnSchema;
 

+ 64 - 98
yt/yt/client/table_client/schema.cpp

@@ -114,42 +114,6 @@ TLockMask MaxMask(TLockMask lhs, TLockMask rhs)
 
 ////////////////////////////////////////////////////////////////////////////////
 
-TStableName::TStableName(TString stableName)
-    : Name_(std::move(stableName))
-{ }
-
-const TString& TStableName::Get() const
-{
-    return Name_;
-}
-
-void FormatValue(TStringBuilderBase* builder, const TStableName& stableName, TStringBuf /*spec*/)
-{
-    builder->AppendFormat("%v", stableName.Get());
-}
-
-bool operator == (const TStableName& lhs, const TStableName& rhs)
-{
-    return lhs.Get() == rhs.Get();
-}
-
-bool operator < (const TStableName& lhs, const TStableName& rhs)
-{
-    return lhs.Get() < rhs.Get();
-}
-
-void ToProto(TString* protoStableName, const TStableName& stableName)
-{
-    *protoStableName = stableName.Get();
-}
-
-void FromProto(TStableName* stableName, const TString& protoStableName)
-{
-    *stableName = TStableName(protoStableName);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
 TColumnSchema::TColumnSchema()
     : TColumnSchema(
         TString(),
@@ -188,7 +152,7 @@ TColumnSchema::TColumnSchema(
     SetLogicalType(std::move(type));
 }
 
-TColumnSchema& TColumnSchema::SetStableName(TStableName value)
+TColumnSchema& TColumnSchema::SetStableName(TColumnStableName value)
 {
     StableName_ = std::move(value);
     return *this;
@@ -269,7 +233,7 @@ i64 TColumnSchema::GetMemoryUsage() const
 {
     return
         sizeof(TColumnSchema) +
-        StableName_.Get().size() +
+        StableName_.Underlying().size() +
         Name_.size() +
         (LogicalType_ ? LogicalType_->GetMemoryUsage() : 0) +
         (Lock_ ? Lock_->size() : 0) +
@@ -295,13 +259,13 @@ ESimpleLogicalValueType TColumnSchema::CastToV1Type() const
 
 bool TColumnSchema::IsRenamed() const
 {
-    return Name() != StableName().Get();
+    return Name() != StableName().Underlying();
 }
 
 TString TColumnSchema::GetDiagnosticNameString() const
 {
     if (IsRenamed()) {
-        return Format("%Qv (stable name %Qv)", Name(), StableName().Get());
+        return Format("%Qv (stable name %Qv)", Name(), StableName().Underlying());
     } else {
         return Format("%Qv", Name());
     }
@@ -313,12 +277,12 @@ TDeletedColumn::TDeletedColumn()
 {
 }
 
-TDeletedColumn::TDeletedColumn(TStableName stableName)
+TDeletedColumn::TDeletedColumn(TColumnStableName stableName)
     : StableName_(stableName)
 {
 }
 
-TDeletedColumn& TDeletedColumn::SetStableName(TStableName value)
+TDeletedColumn& TDeletedColumn::SetStableName(TColumnStableName value)
 {
     StableName_ = std::move(value);
     return *this;
@@ -385,7 +349,7 @@ void ToProto(NProto::TColumnSchema* protoSchema, const TColumnSchema& schema)
 {
     protoSchema->set_name(schema.Name());
     if (schema.IsRenamed()) {
-        protoSchema->set_stable_name(schema.StableName().Get());
+        protoSchema->set_stable_name(schema.StableName().Underlying());
     }
 
     protoSchema->set_type(static_cast<int>(GetPhysicalType(schema.CastToV1Type())));
@@ -435,15 +399,15 @@ void ToProto(NProto::TColumnSchema* protoSchema, const TColumnSchema& schema)
 
 void ToProto(NProto::TDeletedColumn* protoSchema, const TDeletedColumn& schema)
 {
-    protoSchema->set_stable_name(schema.StableName().Get());
+    protoSchema->set_stable_name(schema.StableName().Underlying());
 }
 
 void FromProto(TColumnSchema* schema, const NProto::TColumnSchema& protoSchema)
 {
     schema->SetName(protoSchema.name());
     schema->SetStableName(protoSchema.has_stable_name()
-        ? TStableName(protoSchema.stable_name())
-        : TStableName(protoSchema.name()));
+        ? TColumnStableName(protoSchema.stable_name())
+        : TColumnStableName(protoSchema.name()));
 
     if (protoSchema.has_logical_type()) {
         TLogicalTypePtr logicalType;
@@ -469,7 +433,7 @@ void FromProto(TColumnSchema* schema, const NProto::TColumnSchema& protoSchema)
 
 void FromProto(TDeletedColumn* schema, const NProto::TDeletedColumn& protoSchema)
 {
-    schema->SetStableName(TStableName{protoSchema.stable_name()});
+    schema->SetStableName(TColumnStableName{protoSchema.stable_name()});
 }
 
 void PrintTo(const TColumnSchema& columnSchema, std::ostream* os)
@@ -483,31 +447,31 @@ TTableSchema::TNameMapping::TNameMapping(const TTableSchema& schema)
     : Schema_(schema)
 { }
 
-bool TTableSchema::TNameMapping::IsDeleted(const TStableName& stableName) const
+bool TTableSchema::TNameMapping::IsDeleted(const TColumnStableName& stableName) const
 {
     return Schema_.FindDeletedColumn(stableName) != nullptr;
 }
 
-TString TTableSchema::TNameMapping::StableNameToName(const TStableName& stableName) const
+TString TTableSchema::TNameMapping::StableNameToName(const TColumnStableName& stableName) const
 {
     auto* column = Schema_.FindColumnByStableName(stableName);
     if (!column) {
         if (Schema_.GetStrict()) {
             THROW_ERROR_EXCEPTION("No column with stable name %Qv in strict schema", stableName);
         }
-        return stableName.Get();
+        return stableName.Underlying();
     }
     return column->Name();
 }
 
-TStableName TTableSchema::TNameMapping::NameToStableName(TStringBuf name) const
+TColumnStableName TTableSchema::TNameMapping::NameToStableName(TStringBuf name) const
 {
     auto* column = Schema_.FindColumn(name);
     if (!column) {
         if (Schema_.GetStrict()) {
             THROW_ERROR_EXCEPTION("No column with name %Qv in strict schema", name);
         }
-        return TStableName(TString(name));
+        return TColumnStableName(TString(name));
     }
     return column->StableName();
 }
@@ -558,26 +522,26 @@ TTableSchema::TTableSchema(
         // NB(levysotsky): We ignore duplicates in both maps, they will be
         // accounted for in consequent validation.
         NameToColumnIndex_.emplace(column.Name(), index);
-        StableNameToColumnIndex_.emplace(column.StableName().Get(), index);
+        StableNameToColumnIndex_.emplace(column.StableName().Underlying(), index);
     }
     for (int index = 0; index < std::ssize(DeletedColumns()); ++index) {
         const auto& deletedColumn = DeletedColumns()[index];
-        StableNameToDeletedColumnIndex_.emplace(deletedColumn.StableName().Get(), index);
+        StableNameToDeletedColumnIndex_.emplace(deletedColumn.StableName().Underlying(), index);
     }
 }
 
-const TColumnSchema* TTableSchema::FindColumnByStableName(const TStableName& stableName) const
+const TColumnSchema* TTableSchema::FindColumnByStableName(const TColumnStableName& stableName) const
 {
-    auto it = StableNameToColumnIndex_.find(stableName.Get());
+    auto it = StableNameToColumnIndex_.find(stableName.Underlying());
     if (it == StableNameToColumnIndex_.end()) {
         return nullptr;
     }
     return &Columns()[it->second];
 }
 
-const TDeletedColumn* TTableSchema::FindDeletedColumn(const TStableName& stableName) const
+const TDeletedColumn* TTableSchema::FindDeletedColumn(const TColumnStableName& stableName) const
 {
-    auto it = StableNameToDeletedColumnIndex_.find(stableName.Get());
+    auto it = StableNameToDeletedColumnIndex_.find(stableName.Underlying());
     if (it == StableNameToDeletedColumnIndex_.end()) {
         return nullptr;
     }
@@ -753,9 +717,9 @@ TKeyColumns TTableSchema::GetKeyColumnNames() const
     return keyColumns;
 }
 
-std::vector<TStableName> TTableSchema::GetKeyColumnStableNames() const
+std::vector<TColumnStableName> TTableSchema::GetKeyColumnStableNames() const
 {
-    std::vector<TStableName> keyColumns;
+    std::vector<TColumnStableName> keyColumns;
     for (const auto& column : Columns()) {
         if (column.SortOrder()) {
             keyColumns.push_back(column.StableName());
@@ -784,9 +748,9 @@ std::vector<TString> TTableSchema::GetColumnNames() const
     return result;
 }
 
-std::vector<TStableName> TTableSchema::GetColumnStableNames() const
+std::vector<TColumnStableName> TTableSchema::GetColumnStableNames() const
 {
-    std::vector<TStableName> result;
+    std::vector<TColumnStableName> result;
     result.reserve(Columns().size());
     for (const auto& column : Columns()) {
         result.push_back(column.StableName());
@@ -799,21 +763,21 @@ const THunkColumnIds& TTableSchema::GetHunkColumnIds() const
     return HunkColumnsIds_;
 }
 
-std::vector<TStableName> MapNamesToStableNames(
+std::vector<TColumnStableName> MapNamesToStableNames(
     const TTableSchema& schema,
     std::vector<TString> names,
     const std::optional<TStringBuf>& missingColumnReplacement)
 {
-    std::vector<TStableName> stableNames;
+    std::vector<TColumnStableName> stableNames;
     stableNames.reserve(names.size());
     for (const auto& name : names) {
         const auto* column = schema.FindColumn(name);
         if (column) {
             stableNames.push_back(column->StableName());
         } else if (!schema.GetStrict()) {
-            stableNames.push_back(TStableName(name));
+            stableNames.push_back(TColumnStableName(name));
         } else if (missingColumnReplacement) {
-            stableNames.push_back(TStableName(TString(*missingColumnReplacement)));
+            stableNames.push_back(TColumnStableName(TString(*missingColumnReplacement)));
         } else {
             THROW_ERROR_EXCEPTION("Column %Qv is missing in strict schema",
                 name);
@@ -933,8 +897,8 @@ TTableSchemaPtr TTableSchema::ToWrite() const
         columns.push_back(TColumnSchema(TabletIndexColumnName, ESimpleLogicalValueType::Int64)
             .SetSortOrder(ESortOrder::Ascending));
         for (const auto& column : Columns()) {
-            if (column.StableName().Get() != TimestampColumnName &&
-                column.StableName().Get() != CumulativeDataWeightColumnName)
+            if (column.StableName().Underlying() != TimestampColumnName &&
+                column.StableName().Underlying() != CumulativeDataWeightColumnName)
             {
                 columns.push_back(column);
             }
@@ -1089,8 +1053,12 @@ TTableSchemaPtr TTableSchema::ToSorted(const TSortColumns& sortColumns) const
         it->SetSortOrder(std::nullopt);
     }
 
-    return New<TTableSchema>(std::move(columns), Strict_, uniqueKeys, GetSchemaModification(),
-            DeletedColumns_);
+    return New<TTableSchema>(
+        std::move(columns),
+        Strict_,
+        uniqueKeys,
+        GetSchemaModification(),
+        DeletedColumns_);
 }
 
 TTableSchemaPtr TTableSchema::ToReplicationLog() const
@@ -1469,7 +1437,7 @@ void ValidateSystemColumnSchema(
     if (columnSchema.IsRenamed()) {
         THROW_ERROR_EXCEPTION("System column schema must have equal name and stable name")
             << TErrorAttribute("name", name)
-            << TErrorAttribute("stable_name", columnSchema.StableName().Get());
+            << TErrorAttribute("stable_name", columnSchema.StableName().Underlying());
     }
 
     const auto& allowedSystemColumns = isTableSorted
@@ -1502,6 +1470,20 @@ void ValidateSystemColumnSchema(
         name);
 }
 
+void ValidateColumnName(const TString& name)
+{
+    if (name.empty()) {
+        THROW_ERROR_EXCEPTION("Column name cannot be empty");
+    }
+
+    if (name.size() > MaxColumnNameLength) {
+        THROW_ERROR_EXCEPTION("Column name %Qv is longer than maximum allowed: %v > %v",
+            name,
+            name.size(),
+            MaxColumnNameLength);
+    }
+}
+
 void ValidateColumnSchema(
     const TColumnSchema& columnSchema,
     bool isTableSorted,
@@ -1518,31 +1500,15 @@ void ValidateColumnSchema(
         "_yt_last_seen_replica_set",
     };
 
-    const auto& stableName = columnSchema.StableName();
-    if (stableName.Get().empty()) {
-        THROW_ERROR_EXCEPTION("Column stable name cannot be empty");
-    }
-
-    const auto& name = columnSchema.Name();
-    if (name.empty()) {
-        THROW_ERROR_EXCEPTION("Column name cannot be empty");
-    }
-
     try {
-        if (stableName.Get().StartsWith(SystemColumnNamePrefix) || name.StartsWith(SystemColumnNamePrefix)) {
-            ValidateSystemColumnSchema(columnSchema, isTableSorted, allowUnversionedUpdateColumns);
-        }
+        const auto& stableName = columnSchema.StableName();
+        ValidateColumnName(stableName.Underlying());
 
-        if (stableName.Get().size() > MaxColumnNameLength) {
-            THROW_ERROR_EXCEPTION("Column stable name is longer than maximum allowed: %v > %v",
-                stableName.Get().size(),
-                MaxColumnNameLength);
-        }
+        const auto& name = columnSchema.Name();
+        ValidateColumnName(name);
 
-        if (name.size() > MaxColumnNameLength) {
-            THROW_ERROR_EXCEPTION("Column name is longer than maximum allowed: %v > %v",
-                name.size(),
-                MaxColumnNameLength);
+        if (stableName.Underlying().StartsWith(SystemColumnNamePrefix) || name.StartsWith(SystemColumnNamePrefix)) {
+            ValidateSystemColumnSchema(columnSchema, isTableSorted, allowUnversionedUpdateColumns);
         }
 
         {
@@ -1673,7 +1639,7 @@ void ValidateColumnUniqueness(const TTableSchema& schema)
     THashSet<TStringBuf> columnNames;
     THashSet<TStringBuf> columnStableNames;
     for (const auto& column : schema.Columns()) {
-        if (!columnStableNames.insert(column.StableName().Get()).second) {
+        if (!columnStableNames.insert(column.StableName().Underlying()).second) {
             THROW_ERROR_EXCEPTION("Duplicate column stable name %Qv in table schema",
                 column.StableName());
         }
@@ -1683,7 +1649,7 @@ void ValidateColumnUniqueness(const TTableSchema& schema)
         }
     }
     for (const auto& deletedColumn : schema.DeletedColumns()) {
-        if (!columnStableNames.insert(deletedColumn.StableName().Get()).second) {
+        if (!columnStableNames.insert(deletedColumn.StableName().Underlying()).second) {
             THROW_ERROR_EXCEPTION("Duplicate column stable name %Qv in table schema",
                 deletedColumn.StableName());
         }
@@ -2001,9 +1967,9 @@ TCellTaggedTableSchemaPtr::TCellTaggedTableSchemaPtr(TTableSchemaPtr tableSchema
 
 } // namespace NYT::NTableClient
 
-size_t THash<NYT::NTableClient::TStableName>::operator()(const NYT::NTableClient::TStableName& stableName) const
+size_t THash<NYT::NTableClient::TColumnStableName>::operator()(const NYT::NTableClient::TColumnStableName& stableName) const
 {
-    return THash<TString>()(stableName.Get());
+    return THash<TString>()(stableName.Underlying());
 }
 
 size_t THash<NYT::NTableClient::TColumnSchema>::operator()(const NYT::NTableClient::TColumnSchema& columnSchema) const
@@ -2022,7 +1988,7 @@ size_t THash<NYT::NTableClient::TColumnSchema>::operator()(const NYT::NTableClie
 
 size_t THash<NYT::NTableClient::TDeletedColumn>::operator()(const NYT::NTableClient::TDeletedColumn& columnSchema) const
 {
-    return THash<NYT::NTableClient::TStableName>()(columnSchema.StableName());
+    return THash<NYT::NTableClient::TColumnStableName>()(columnSchema.StableName());
 }
 
 size_t THash<NYT::NTableClient::TTableSchema>::operator()(const NYT::NTableClient::TTableSchema& tableSchema) const

+ 19 - 37
yt/yt/client/table_client/schema.h

@@ -109,33 +109,11 @@ TLockMask MaxMask(TLockMask lhs, TLockMask rhs);
 
 ////////////////////////////////////////////////////////////////////////////////
 
-//
-// Strong typedef to avoid mixing stable names and names.
-class TStableName
-{
-public:
-    explicit TStableName(TString stableName = "");
-    const TString& Get() const;
-
-private:
-    TString Name_;
-};
-
-void FormatValue(TStringBuilderBase* builder, const TStableName& stableName, TStringBuf spec);
-
-bool operator == (const TStableName& lhs, const TStableName& rhs);
-bool operator < (const TStableName& lhs, const TStableName& rhs);
-
-void ToProto(TString* protoStableName, const TStableName& stableName);
-void FromProto(TStableName* stableName, const TString& protoStableName);
-
-////////////////////////////////////////////////////////////////////////////////
-
 class TColumnSchema
 {
 public:
     // Keep in sync with hasher below.
-    DEFINE_BYREF_RO_PROPERTY(TStableName, StableName);
+    DEFINE_BYREF_RO_PROPERTY(TColumnStableName, StableName);
     DEFINE_BYREF_RO_PROPERTY(TString, Name);
     DEFINE_BYREF_RO_PROPERTY(TLogicalTypePtr, LogicalType);
     DEFINE_BYREF_RO_PROPERTY(std::optional<ESortOrder>, SortOrder);
@@ -168,7 +146,7 @@ public:
     TColumnSchema& operator=(const TColumnSchema&) = default;
     TColumnSchema& operator=(TColumnSchema&&) = default;
 
-    TColumnSchema& SetStableName(TStableName stableName);
+    TColumnSchema& SetStableName(TColumnStableName stableName);
     TColumnSchema& SetName(TString name);
     TColumnSchema& SetLogicalType(TLogicalTypePtr valueType);
     TColumnSchema& SetSimpleLogicalType(ESimpleLogicalValueType type);
@@ -207,10 +185,10 @@ class TDeletedColumn
 {
 public:
     TDeletedColumn();
-    explicit TDeletedColumn(TStableName stableName);
+    explicit TDeletedColumn(TColumnStableName stableName);
 
-    DEFINE_BYREF_RO_PROPERTY(TStableName, StableName);
-    TDeletedColumn& SetStableName(TStableName stableName);
+    DEFINE_BYREF_RO_PROPERTY(TColumnStableName, StableName);
+    TDeletedColumn& SetStableName(TColumnStableName stableName);
 };
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -237,9 +215,9 @@ public:
     public:
         explicit TNameMapping(const TTableSchema& schema);
 
-        bool IsDeleted(const TStableName& stableName) const;
-        TString StableNameToName(const TStableName& stableName) const;
-        TStableName NameToStableName(TStringBuf name) const;
+        bool IsDeleted(const TColumnStableName& stableName) const;
+        TString StableNameToName(const TColumnStableName& stableName) const;
+        TColumnStableName NameToStableName(TStringBuf name) const;
 
     private:
         const TTableSchema& Schema_;
@@ -266,8 +244,8 @@ public:
         ETableSchemaModification schemaModification = ETableSchemaModification::None,
         std::vector<TDeletedColumn> deletedColumns = {});
 
-    const TColumnSchema* FindColumnByStableName(const TStableName& stableName) const;
-    const TDeletedColumn* FindDeletedColumn(const TStableName& stableName) const;
+    const TColumnSchema* FindColumnByStableName(const TColumnStableName& stableName) const;
+    const TDeletedColumn* FindDeletedColumn(const TColumnStableName& stableName) const;
 
     int GetColumnIndex(const TColumnSchema& column) const;
 
@@ -300,14 +278,14 @@ public:
     bool HasRenamedColumns() const;
     bool IsEmpty() const;
 
-    std::vector<TStableName> GetKeyColumnStableNames() const;
+    std::vector<TColumnStableName> GetKeyColumnStableNames() const;
     TKeyColumns GetKeyColumnNames() const;
     TKeyColumns GetKeyColumns() const;
 
     int GetColumnCount() const;
     int GetKeyColumnCount() const;
     int GetValueColumnCount() const;
-    std::vector<TStableName> GetColumnStableNames() const;
+    std::vector<TColumnStableName> GetColumnStableNames() const;
     const THunkColumnIds& GetHunkColumnIds() const;
 
     TSortColumns GetSortColumns(const std::optional<TNameMapping>& nameMapping = std::nullopt) const;
@@ -414,6 +392,8 @@ private:
 
 DEFINE_REFCOUNTED_TYPE(TTableSchema)
 
+////////////////////////////////////////////////////////////////////////////////
+
 void FormatValue(TStringBuilderBase* builder, const TTableSchema& schema, TStringBuf spec);
 void FormatValue(TStringBuilderBase* builder, const TTableSchemaPtr& schema, TStringBuf spec);
 
@@ -464,7 +444,7 @@ bool IsEqualIgnoringRequiredness(const TTableSchema& lhs, const TTableSchema& rh
 
 static constexpr TStringBuf NonexistentColumnName = "$__YT_NONEXISTENT_COLUMN_NAME__";
 
-std::vector<TStableName> MapNamesToStableNames(
+std::vector<TColumnStableName> MapNamesToStableNames(
     const TTableSchema& schema,
     std::vector<TString> names,
     const std::optional<TStringBuf>& missingColumnReplacement = std::nullopt);
@@ -473,6 +453,8 @@ std::vector<TStableName> MapNamesToStableNames(
 
 void ValidateKeyColumns(const TKeyColumns& keyColumns);
 
+void ValidateColumnName(const TString& name);
+
 void ValidateColumnSchema(
     const TColumnSchema& columnSchema,
     bool isTableSorted = false,
@@ -584,9 +566,9 @@ struct TCellTaggedTableSchemaEquals
 ////////////////////////////////////////////////////////////////////////////////
 
 template <>
-struct THash<NYT::NTableClient::TStableName>
+struct THash<NYT::NTableClient::TColumnStableName>
 {
-    size_t operator()(const NYT::NTableClient::TStableName& stableName) const;
+    size_t operator()(const NYT::NTableClient::TColumnStableName& stableName) const;
 };
 
 template <>

+ 10 - 13
yt/yt/client/table_client/schema_serialization_helpers.cpp

@@ -95,7 +95,7 @@ void TSerializableColumnSchema::DeserializeFromCursor(NYson::TYsonPullParserCurs
             SetMaxInlineHunkSize(ExtractTo<std::optional<i64>>(cursor));
         } else if (key == TStringBuf("stable_name")) {
             cursor->Next();
-            SerializedStableName_ = ExtractTo<TString>(cursor);
+            SerializedStableName_ = ExtractTo<TColumnStableName>(cursor);
         } else if (key == TStringBuf("deleted")) {
             cursor->Next();
             Deleted_ = ExtractTo<bool>(cursor);
@@ -112,7 +112,7 @@ void TSerializableColumnSchema::SetColumnSchema(const TColumnSchema& columnSchem
 {
     static_cast<TColumnSchema&>(*this) = columnSchema;
     if (IsRenamed()) {
-        SerializedStableName_ = StableName().Get();
+        SerializedStableName_ = StableName();
     }
     LogicalTypeV1_ = columnSchema.CastToV1Type();
     RequiredV1_ = columnSchema.Required();
@@ -129,10 +129,10 @@ void TSerializableColumnSchema::SetDeletedColumnSchema(
 void TSerializableColumnSchema::RunPostprocessor()
 {
     if (Deleted() && *Deleted()) {
-        if (!SerializedStableName_ || SerializedStableName_->empty()) {
-            THROW_ERROR_EXCEPTION("stable name should be set for a deleted column");
+        if (!SerializedStableName_) {
+            THROW_ERROR_EXCEPTION("Stable name should be set for a deleted column");
         }
-        SetStableName(TStableName(*SerializedStableName_));
+        SetStableName(*SerializedStableName_);
         return;
     }
 
@@ -141,13 +141,11 @@ void TSerializableColumnSchema::RunPostprocessor()
         THROW_ERROR_EXCEPTION("Column name cannot be empty");
     }
 
-    if (SerializedStableName_.has_value()) {
-        if (SerializedStableName_->empty()) {
-            THROW_ERROR_EXCEPTION("Column stable name cannot be empty");
-        }
-        SetStableName(TStableName(*SerializedStableName_));
+    if (SerializedStableName_) {
+        ValidateColumnName(SerializedStableName_->Underlying());
+        SetStableName(*SerializedStableName_);
     } else {
-        SetStableName(TStableName(Name()));
+        SetStableName(TColumnStableName(Name()));
     }
 
     try {
@@ -219,7 +217,7 @@ void Serialize(const TDeletedColumn& schema, NYson::IYsonConsumer* consumer)
 {
     consumer->OnBeginMap();
     consumer->OnKeyedItem("stable_name");
-    consumer->OnStringScalar(schema.StableName().Get());
+    consumer->OnStringScalar(schema.StableName().Underlying());
     consumer->OnKeyedItem("deleted");
     consumer->OnBooleanScalar(true);
     consumer->OnEndMap();
@@ -337,7 +335,6 @@ void Deserialize(TTableSchemaPtr& schema, NYson::TYsonPullParserCursor* cursor)
     schema = New<TTableSchema>(std::move(actualSchema));
 }
 
-
 ////////////////////////////////////////////////////////////////////////////////
 
 } // namespace NYT::NTableClient

+ 1 - 1
yt/yt/client/table_client/schema_serialization_helpers.h

@@ -38,7 +38,7 @@ public:
     void SetDeletedColumnSchema(const TDeletedColumn& deletedColumnSchema);
 
 private:
-    std::optional<TString> SerializedStableName_;
+    std::optional<TColumnStableName> SerializedStableName_;
 
     std::optional<ESimpleLogicalValueType> LogicalTypeV1_;
     std::optional<bool> RequiredV1_;

Some files were not shown because too many files changed in this diff