|
@@ -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
|