aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-02-29 14:33:26 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-02-29 14:41:09 +0300
commit7181b196918e411d43eeb3b6c6b6fdcc5f46cba5 (patch)
tree2b1ac34ee314dfaf8a3a81f0e55291c096134910
parent1e191167512509999e550b571d716f1a83521ca1 (diff)
downloadydb-7181b196918e411d43eeb3b6c6b6fdcc5f46cba5.tar.gz
Intermediate changes
-rw-r--r--yt/yt/client/table_client/schema.cpp168
-rw-r--r--yt/yt/client/table_client/schema.h22
2 files changed, 143 insertions, 47 deletions
diff --git a/yt/yt/client/table_client/schema.cpp b/yt/yt/client/table_client/schema.cpp
index 3e04a5c2ba..3401696fea 100644
--- a/yt/yt/client/table_client/schema.cpp
+++ b/yt/yt/client/table_client/schema.cpp
@@ -480,8 +480,8 @@ TColumnStableName TTableSchema::TNameMapping::NameToStableName(TStringBuf name)
const std::vector<TColumnSchema>& TTableSchema::Columns() const
{
- if (Columns_) [[likely]] {
- return *Columns_;
+ if (ColumnInfo_) [[likely]] {
+ return ColumnInfo_->Columns;
} else {
static const std::vector<TColumnSchema> empty;
return empty;
@@ -490,7 +490,12 @@ const std::vector<TColumnSchema>& TTableSchema::Columns() const
const std::vector<TDeletedColumn>& TTableSchema::DeletedColumns() const
{
- return DeletedColumns_;
+ if (ColumnInfo_) [[likely]] {
+ return ColumnInfo_->DeletedColumns;
+ } else {
+ static std::vector<TDeletedColumn> empty;
+ return empty;
+ }
}
TTableSchema::TTableSchema(
@@ -502,11 +507,11 @@ TTableSchema::TTableSchema(
: Strict_(strict)
, UniqueKeys_(uniqueKeys)
, SchemaModification_(schemaModification)
- , Columns_(std::make_shared<const std::vector<TColumnSchema>>(std::move(columns)))
- , DeletedColumns_(std::move(deletedColumns))
+ , ColumnInfo_(std::make_shared<const TColumnInfo>(std::move(columns), std::move(deletedColumns)))
{
+ const auto& info = *ColumnInfo_;
for (int index = 0; index < std::ssize(Columns()); ++index) {
- const auto& column = Columns()[index];
+ const auto& column = info.Columns[index];
if (column.SortOrder()) {
++KeyColumnCount_;
}
@@ -525,7 +530,7 @@ TTableSchema::TTableSchema(
StableNameToColumnIndex_.emplace(column.StableName().Underlying(), index);
}
for (int index = 0; index < std::ssize(DeletedColumns()); ++index) {
- const auto& deletedColumn = DeletedColumns()[index];
+ const auto& deletedColumn = info.DeletedColumns[index];
StableNameToDeletedColumnIndex_.emplace(deletedColumn.StableName().Underlying(), index);
}
}
@@ -601,7 +606,6 @@ TTableSchemaPtr TTableSchema::Filter(const TColumnFilter& columnFilter, bool dis
{
int newKeyColumnCount = 0;
std::vector<TColumnSchema> columns;
-
if (columnFilter.IsUniversal()) {
if (!discardSortOrder) {
return New<TTableSchema>(*this);
@@ -613,18 +617,19 @@ TTableSchemaPtr TTableSchema::Filter(const TColumnFilter& columnFilter, bool dis
}
} else {
bool inKeyColumns = !discardSortOrder;
+ const auto& schemaColumns = Columns();
for (int id : columnFilter.GetIndexes()) {
- if (id < 0 || id >= std::ssize(Columns())) {
+ if (id < 0 || id >= std::ssize(schemaColumns)) {
THROW_ERROR_EXCEPTION("Invalid column during schema filtering: expected in range [0, %v), got %v",
- Columns().size(),
+ schemaColumns.size(),
id);
}
- if (id != std::ssize(columns) || !Columns()[id].SortOrder()) {
+ if (id != std::ssize(columns) || !schemaColumns[id].SortOrder()) {
inKeyColumns = false;
}
- columns.push_back(Columns()[id]);
+ columns.push_back(schemaColumns[id]);
if (!inKeyColumns) {
columns.back().SetSortOrder(std::nullopt);
@@ -641,7 +646,7 @@ TTableSchemaPtr TTableSchema::Filter(const TColumnFilter& columnFilter, bool dis
Strict_,
UniqueKeys_ && (newKeyColumnCount == GetKeyColumnCount()),
ETableSchemaModification::None,
- DeletedColumns_);
+ DeletedColumns());
}
TTableSchemaPtr TTableSchema::Filter(const THashSet<TString>& columnNames, bool discardSortOrder) const
@@ -740,9 +745,13 @@ int TTableSchema::GetColumnCount() const
std::vector<TString> TTableSchema::GetColumnNames() const
{
+ if (!ColumnInfo_) {
+ return std::vector<TString>();
+ }
std::vector<TString> result;
- result.reserve(Columns().size());
- for (const auto& column : Columns()) {
+ const auto& info = *ColumnInfo_;
+ result.reserve(info.Columns.size());
+ for (const auto& column : info.Columns) {
result.push_back(column.Name());
}
return result;
@@ -750,9 +759,13 @@ std::vector<TString> TTableSchema::GetColumnNames() const
std::vector<TColumnStableName> TTableSchema::GetColumnStableNames() const
{
+ if (!ColumnInfo_) {
+ return std::vector<TColumnStableName>();
+ }
std::vector<TColumnStableName> result;
- result.reserve(Columns().size());
- for (const auto& column : Columns()) {
+ const auto& info = *ColumnInfo_;
+ result.reserve(info.Columns.size());
+ for (const auto& column : info.Columns) {
result.push_back(column.StableName());
}
return result;
@@ -846,7 +859,9 @@ TTableSchemaPtr TTableSchema::FromKeyColumns(const TKeyColumns& keyColumns)
TColumnSchema(columnName, ESimpleLogicalValueType::Any)
.SetSortOrder(ESortOrder::Ascending));
}
- schema.Columns_ = std::make_shared<const std::vector<TColumnSchema>>(std::move(columns));
+ schema.ColumnInfo_ = std::make_shared<const TColumnInfo>(
+ std::move(columns),
+ std::vector<TDeletedColumn>{});
schema.KeyColumnCount_ = keyColumns.size();
ValidateTableSchema(schema);
return New<TTableSchema>(std::move(schema));
@@ -861,7 +876,9 @@ TTableSchemaPtr TTableSchema::FromSortColumns(const TSortColumns& sortColumns)
TColumnSchema(sortColumn.Name, ESimpleLogicalValueType::Any)
.SetSortOrder(sortColumn.SortOrder));
}
- schema.Columns_ = std::make_shared<const std::vector<TColumnSchema>>(std::move(columns));
+ schema.ColumnInfo_ = std::make_shared<const TColumnInfo>(
+ std::move(columns),
+ std::vector<TDeletedColumn>{});
schema.KeyColumnCount_ = sortColumns.size();
ValidateTableSchema(schema);
return New<TTableSchema>(std::move(schema));
@@ -869,6 +886,15 @@ TTableSchemaPtr TTableSchema::FromSortColumns(const TSortColumns& sortColumns)
TTableSchemaPtr TTableSchema::ToQuery() const
{
+ if (!ColumnInfo_) {
+ return New<TTableSchema>(
+ std::vector<TColumnSchema>(),
+ true, /*strict*/
+ false, /*uniqueKeys*/
+ ETableSchemaModification::None,
+ std::vector<TDeletedColumn>());
+ }
+ const auto& info = *ColumnInfo_;
if (IsSorted()) {
return New<TTableSchema>(*this);
} else {
@@ -878,9 +904,9 @@ TTableSchemaPtr TTableSchema::ToQuery() const
TColumnSchema(RowIndexColumnName, ESimpleLogicalValueType::Int64)
.SetSortOrder(ESortOrder::Ascending)
};
- columns.insert(columns.end(), Columns().begin(), Columns().end());
+ columns.insert(columns.end(), info.Columns.begin(), info.Columns.end());
return New<TTableSchema>(std::move(columns), true, false,
- ETableSchemaModification::None, DeletedColumns_);
+ ETableSchemaModification::None, DeletedColumns());
}
}
@@ -905,7 +931,7 @@ TTableSchemaPtr TTableSchema::ToWrite() const
}
}
return New<TTableSchema>(std::move(columns), Strict_, UniqueKeys_,
- ETableSchemaModification::None, DeletedColumns_);
+ ETableSchemaModification::None, DeletedColumns());
}
TTableSchemaPtr TTableSchema::WithTabletIndex() const
@@ -917,7 +943,7 @@ TTableSchemaPtr TTableSchema::WithTabletIndex() const
// XXX: Is it ok? $tablet_index is usually a key column.
columns.push_back(TColumnSchema(TabletIndexColumnName, ESimpleLogicalValueType::Int64));
return New<TTableSchema>(std::move(columns), Strict_, UniqueKeys_,
- ETableSchemaModification::None, DeletedColumns_);
+ ETableSchemaModification::None, DeletedColumns());
}
}
@@ -930,7 +956,7 @@ TTableSchemaPtr TTableSchema::ToVersionedWrite() const
columns.insert(columns.begin(), TColumnSchema(TabletIndexColumnName, ESimpleLogicalValueType::Int64)
.SetSortOrder(ESortOrder::Ascending));
return New<TTableSchema>(std::move(columns), Strict_, UniqueKeys_,
- ETableSchemaModification::None, DeletedColumns_);
+ ETableSchemaModification::None, DeletedColumns());
}
}
@@ -942,7 +968,12 @@ TTableSchemaPtr TTableSchema::ToLookup() const
columns.push_back(column);
}
}
- return New<TTableSchema>(std::move(columns), Strict_, UniqueKeys_, ETableSchemaModification::None, DeletedColumns_);
+ return New<TTableSchema>(
+ std::move(columns),
+ Strict_,
+ UniqueKeys_,
+ ETableSchemaModification::None,
+ DeletedColumns());
}
TTableSchemaPtr TTableSchema::ToDelete() const
@@ -952,42 +983,87 @@ TTableSchemaPtr TTableSchema::ToDelete() const
TTableSchemaPtr TTableSchema::ToKeys() const
{
- std::vector<TColumnSchema> columns(Columns().begin(), Columns().begin() + KeyColumnCount_);
+ if (!ColumnInfo_) {
+ return New<TTableSchema>(
+ std::vector<TColumnSchema>(),
+ Strict_,
+ UniqueKeys_,
+ ETableSchemaModification::None,
+ std::vector<TDeletedColumn>());
+ }
+ const auto& info = *ColumnInfo_;
+ std::vector<TColumnSchema> columns(info.Columns.begin(), info.Columns.begin() + KeyColumnCount_);
return New<TTableSchema>(std::move(columns), Strict_, UniqueKeys_,
- ETableSchemaModification::None, DeletedColumns_);
+ ETableSchemaModification::None, info.DeletedColumns);
}
TTableSchemaPtr TTableSchema::ToUniqueKeys() const
{
- return New<TTableSchema>(Columns(), Strict_, /*uniqueKeys*/ true,
- ETableSchemaModification::None, DeletedColumns_);
+ if (!ColumnInfo_) {
+ return New<TTableSchema>(
+ std::vector<TColumnSchema>(),
+ Strict_,
+ true, /*uniqueKeys*/
+ ETableSchemaModification::None,
+ std::vector<TDeletedColumn>());
+ }
+ const auto& info = *ColumnInfo_;
+ return New<TTableSchema>(info.Columns, Strict_, /*uniqueKeys*/ true,
+ ETableSchemaModification::None, info.DeletedColumns);
}
TTableSchemaPtr TTableSchema::ToStrippedColumnAttributes() const
{
+ if (!ColumnInfo_) {
+ return New<TTableSchema>(
+ std::vector<TColumnSchema>(),
+ Strict_,
+ false, /*uniqueKeys*/
+ ETableSchemaModification::None,
+ std::vector<TDeletedColumn>());
+ }
+ const auto& info = *ColumnInfo_;
std::vector<TColumnSchema> strippedColumns;
- for (const auto& column : Columns()) {
+ for (const auto& column : info.Columns) {
auto& strippedColumn = strippedColumns.emplace_back(column.Name(), column.LogicalType());
strippedColumn.SetStableName(column.StableName());
}
return New<TTableSchema>(std::move(strippedColumns), Strict_, /*uniqueKeys*/ false,
- ETableSchemaModification::None, DeletedColumns_);
+ ETableSchemaModification::None, info.DeletedColumns);
}
TTableSchemaPtr TTableSchema::ToSortedStrippedColumnAttributes() const
{
+ if (!ColumnInfo_) {
+ return New<TTableSchema>(
+ std::vector<TColumnSchema>(),
+ Strict_,
+ UniqueKeys_, /*uniqueKeys*/
+ ETableSchemaModification::None,
+ std::vector<TDeletedColumn>());
+ }
+ const auto& info = *ColumnInfo_;
std::vector<TColumnSchema> strippedColumns;
- for (const auto& column : Columns()) {
+ for (const auto& column : info.Columns) {
auto& strippedColumn = strippedColumns.emplace_back(column.Name(), column.LogicalType(), column.SortOrder());
strippedColumn.SetStableName(column.StableName());
}
return New<TTableSchema>(std::move(strippedColumns), Strict_, UniqueKeys_,
- ETableSchemaModification::None, DeletedColumns_);
+ ETableSchemaModification::None, info.DeletedColumns);
}
TTableSchemaPtr TTableSchema::ToCanonical() const
{
- auto columns = Columns();
+ if (!ColumnInfo_) {
+ return New<TTableSchema>(
+ std::vector<TColumnSchema>(),
+ Strict_,
+ UniqueKeys_, /*uniqueKeys*/
+ ETableSchemaModification::None,
+ std::vector<TDeletedColumn>());
+ }
+ const auto& info = *ColumnInfo_;
+ auto columns = info.Columns;
std::sort(
columns.begin() + KeyColumnCount_,
columns.end(),
@@ -995,7 +1071,7 @@ TTableSchemaPtr TTableSchema::ToCanonical() const
return lhs.Name() < rhs.Name();
});
return New<TTableSchema>(columns, Strict_, UniqueKeys_,
- ETableSchemaModification::None, DeletedColumns_);
+ ETableSchemaModification::None, info.DeletedColumns);
}
TTableSchemaPtr TTableSchema::ToSorted(const TKeyColumns& keyColumns) const
@@ -1058,16 +1134,17 @@ TTableSchemaPtr TTableSchema::ToSorted(const TSortColumns& sortColumns) const
Strict_,
uniqueKeys,
GetSchemaModification(),
- DeletedColumns_);
+ DeletedColumns());
}
TTableSchemaPtr TTableSchema::ToReplicationLog() const
{
+ const auto& schemaColumns = Columns();
std::vector<TColumnSchema> columns;
columns.push_back(TColumnSchema(TimestampColumnName, ESimpleLogicalValueType::Uint64));
if (IsSorted()) {
columns.push_back(TColumnSchema(TReplicationLogTable::ChangeTypeColumnName, ESimpleLogicalValueType::Int64));
- for (const auto& column : Columns()) {
+ for (const auto& column : schemaColumns) {
if (column.SortOrder()) {
columns.push_back(
TColumnSchema(
@@ -1083,7 +1160,7 @@ TTableSchemaPtr TTableSchema::ToReplicationLog() const
}
}
} else {
- for (const auto& column : Columns()) {
+ for (const auto& column : schemaColumns) {
columns.push_back(
TColumnSchema(
TReplicationLogTable::ValueColumnNamePrefix + column.Name(),
@@ -1097,12 +1174,13 @@ TTableSchemaPtr TTableSchema::ToReplicationLog() const
/* strict */ true,
/* uniqueKeys */ false,
ETableSchemaModification::None,
- DeletedColumns_);
+ DeletedColumns());
}
TTableSchemaPtr TTableSchema::ToUnversionedUpdate(bool sorted) const
{
YT_VERIFY(IsSorted());
+ const auto& info = *ColumnInfo_;
std::vector<TColumnSchema> columns;
columns.reserve(GetKeyColumnCount() + 1 + GetValueColumnCount() * 2);
@@ -1123,7 +1201,7 @@ TTableSchemaPtr TTableSchema::ToUnversionedUpdate(bool sorted) const
// Values.
for (int columnIndex = GetKeyColumnCount(); columnIndex < GetColumnCount(); ++columnIndex) {
- const auto& column = Columns()[columnIndex];
+ const auto& column = info.Columns[columnIndex];
YT_VERIFY(!column.SortOrder());
columns.emplace_back(
TUnversionedUpdateSchema::ValueColumnNamePrefix + column.Name(),
@@ -1138,7 +1216,7 @@ TTableSchemaPtr TTableSchema::ToUnversionedUpdate(bool sorted) const
/*strict*/ true,
/*uniqueKeys*/ sorted,
ETableSchemaModification::None,
- DeletedColumns_);
+ info.DeletedColumns);
}
TTableSchemaPtr TTableSchema::ToModifiedSchema(ETableSchemaModification schemaModification) const
@@ -1169,10 +1247,14 @@ TTableSchemaPtr TTableSchema::ToModifiedSchema(ETableSchemaModification schemaMo
TComparator TTableSchema::ToComparator() const
{
+ if (!ColumnInfo_) {
+ return TComparator(std::vector<ESortOrder>());
+ }
+ const auto& info = *ColumnInfo_;
std::vector<ESortOrder> sortOrders(KeyColumnCount_);
for (int index = 0; index < KeyColumnCount_; ++index) {
- YT_VERIFY(Columns()[index].SortOrder());
- sortOrders[index] = *Columns()[index].SortOrder();
+ YT_VERIFY(info.Columns[index].SortOrder());
+ sortOrders[index] = *info.Columns[index].SortOrder();
}
return TComparator(std::move(sortOrders));
}
diff --git a/yt/yt/client/table_client/schema.h b/yt/yt/client/table_client/schema.h
index 8211d6d423..bc53ad71c5 100644
--- a/yt/yt/client/table_client/schema.h
+++ b/yt/yt/client/table_client/schema.h
@@ -235,6 +235,11 @@ public:
//! Constructs an empty non-strict schema.
TTableSchema() = default;
+ TTableSchema(TTableSchema&&) = default;
+ TTableSchema& operator=(TTableSchema&&) = default;
+ TTableSchema(const TTableSchema&) = default;
+ TTableSchema& operator=(const TTableSchema&) = default;
+
//! Constructs a schema with given columns and strictness flag.
//! No validation is performed.
explicit TTableSchema(
@@ -375,16 +380,25 @@ public:
i64 GetMemoryUsage() const;
private:
- std::shared_ptr<const std::vector<TColumnSchema>> Columns_;
- std::vector<TDeletedColumn> DeletedColumns_;
+ struct TColumnInfo
+ {
+ 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;
+ };
+
+ std::shared_ptr<const TColumnInfo> ColumnInfo_;
int KeyColumnCount_ = 0;
bool HasComputedColumns_ = false;
bool HasAggregateColumns_ = false;
THunkColumnIds HunkColumnsIds_;
- // NB: Strings are owned by Columns_, addresses are immutable
- // inside TTableSchema.
THashMap<TStringBuf, int> StableNameToColumnIndex_;
THashMap<TStringBuf, int> NameToColumnIndex_;
THashMap<TStringBuf, int> StableNameToDeletedColumnIndex_;