@@ -251,6 +251,24 @@ static void SerializeTo(const TRenameIndex& rename, Ydb::Table::RenameIndexItem&
251
251
proto.set_replace_destination (rename.ReplaceDestination_ );
252
252
}
253
253
254
+ template <typename TProto>
255
+ TExplicitPartitions TExplicitPartitions::FromProto (const TProto& proto) {
256
+ TExplicitPartitions out;
257
+ for (const auto & splitPoint : proto.split_points ()) {
258
+ TValue value (TType (splitPoint.type ()), splitPoint.value ());
259
+ out.AppendSplitPoints (value);
260
+ }
261
+ return out;
262
+ }
263
+
264
+ void TExplicitPartitions::SerializeTo (Ydb::Table::ExplicitPartitions& proto) const {
265
+ for (const auto & splitPoint : SplitPoints_) {
266
+ auto * boundary = proto.add_split_points ();
267
+ boundary->mutable_type ()->CopyFrom (TProtoAccessor::GetProto (splitPoint.GetType ()));
268
+ boundary->mutable_value ()->CopyFrom (TProtoAccessor::GetProto (splitPoint));
269
+ }
270
+ }
271
+
254
272
class TTableDescription ::TImpl {
255
273
using EUnit = TValueSinceUnixEpochModeSettings::EUnit;
256
274
@@ -419,13 +437,7 @@ class TTableDescription::TImpl {
419
437
break ;
420
438
421
439
case Ydb::Table::CreateTableRequest::kPartitionAtKeys : {
422
- TExplicitPartitions partitionAtKeys;
423
- for (const auto & splitPoint : request.partition_at_keys ().split_points ()) {
424
- TValue value (TType (splitPoint.type ()), splitPoint.value ());
425
- partitionAtKeys.AppendSplitPoints (value);
426
- }
427
-
428
- SetPartitionAtKeys (partitionAtKeys);
440
+ SetPartitionAtKeys (TExplicitPartitions::FromProto (request.partition_at_keys ()));
429
441
break ;
430
442
}
431
443
@@ -922,12 +934,7 @@ void TTableDescription::SerializeTo(Ydb::Table::CreateTableRequest& request) con
922
934
}
923
935
924
936
if (const auto & partitionAtKeys = Impl_->GetPartitionAtKeys ()) {
925
- auto * borders = request.mutable_partition_at_keys ();
926
- for (const auto & splitPoint : partitionAtKeys->SplitPoints_ ) {
927
- auto * border = borders->add_split_points ();
928
- border->mutable_type ()->CopyFrom (TProtoAccessor::GetProto (splitPoint.GetType ()));
929
- border->mutable_value ()->CopyFrom (TProtoAccessor::GetProto (splitPoint));
930
- }
937
+ partitionAtKeys->SerializeTo (*request.mutable_partition_at_keys ());
931
938
} else if (Impl_->GetProto ().shard_key_bounds_size ()) {
932
939
request.mutable_partition_at_keys ()->mutable_split_points ()->CopyFrom (Impl_->GetProto ().shard_key_bounds ());
933
940
}
@@ -2204,16 +2211,25 @@ bool TRenameItem::ReplaceDestination() const {
2204
2211
2205
2212
// //////////////////////////////////////////////////////////////////////////////
2206
2213
2207
- TIndexDescription::TIndexDescription (const std::string& name, EIndexType type,
2208
- const std::vector<std::string>& indexColumns, const std::vector<std::string>& dataColumns)
2209
- : IndexName_(name)
2214
+ TIndexDescription::TIndexDescription (
2215
+ const std::string& name,
2216
+ EIndexType type,
2217
+ const std::vector<std::string>& indexColumns,
2218
+ const std::vector<std::string>& dataColumns,
2219
+ const TGlobalIndexSettings& settings
2220
+ ) : IndexName_(name)
2210
2221
, IndexType_(type)
2211
2222
, IndexColumns_(indexColumns)
2212
2223
, DataColumns_(dataColumns)
2224
+ , GlobalIndexSettings_(settings)
2213
2225
{}
2214
2226
2215
- TIndexDescription::TIndexDescription (const std::string& name, const std::vector<std::string>& indexColumns, const std::vector<std::string>& dataColumns)
2216
- : TIndexDescription(name, EIndexType::GlobalSync, indexColumns, dataColumns)
2227
+ TIndexDescription::TIndexDescription (
2228
+ const std::string& name,
2229
+ const std::vector<std::string>& indexColumns,
2230
+ const std::vector<std::string>& dataColumns,
2231
+ const TGlobalIndexSettings& settings
2232
+ ) : TIndexDescription(name, EIndexType::GlobalSync, indexColumns, dataColumns, settings)
2217
2233
{}
2218
2234
2219
2235
TIndexDescription::TIndexDescription (const Ydb::Table::TableIndex& tableIndex)
@@ -2244,31 +2260,68 @@ uint64_t TIndexDescription::GetSizeBytes() const {
2244
2260
return SizeBytes;
2245
2261
}
2246
2262
2263
+ template <typename TProto>
2264
+ TGlobalIndexSettings TGlobalIndexSettings::FromProto (const TProto& proto) {
2265
+ auto partitionsFromProto = [](const auto & proto) -> TUniformOrExplicitPartitions {
2266
+ switch (proto.partitions_case ()) {
2267
+ case TProto::kUniformPartitions :
2268
+ return proto.uniform_partitions ();
2269
+ case TProto::kPartitionAtKeys :
2270
+ return TExplicitPartitions::FromProto (proto.partition_at_keys ());
2271
+ default :
2272
+ return {};
2273
+ }
2274
+ };
2275
+
2276
+ return {
2277
+ .PartitioningSettings = TPartitioningSettings (proto.partitioning_settings ()),
2278
+ .Partitions = partitionsFromProto (proto)
2279
+ };
2280
+ }
2281
+
2282
+ void TGlobalIndexSettings::SerializeTo (Ydb::Table::GlobalIndexSettings& settings) const {
2283
+ *settings.mutable_partitioning_settings () = PartitioningSettings.GetProto ();
2284
+
2285
+ auto variantVisitor = [&settings](auto && partitions) {
2286
+ using T = std::decay_t <decltype (partitions)>;
2287
+ if constexpr (std::is_same_v<T, uint64_t >) {
2288
+ settings.set_uniform_partitions (partitions);
2289
+ } else if constexpr (std::is_same_v<T, TExplicitPartitions>) {
2290
+ partitions.SerializeTo (*settings.mutable_partition_at_keys ());
2291
+ }
2292
+ };
2293
+ std::visit (std::move (variantVisitor), Partitions);
2294
+ }
2295
+
2247
2296
template <typename TProto>
2248
2297
TIndexDescription TIndexDescription::FromProto (const TProto& proto) {
2249
2298
EIndexType type;
2250
2299
std::vector<std::string> indexColumns;
2251
2300
std::vector<std::string> dataColumns;
2301
+ TGlobalIndexSettings globalIndexSettings;
2252
2302
2253
2303
indexColumns.assign (proto.index_columns ().begin (), proto.index_columns ().end ());
2254
2304
dataColumns.assign (proto.data_columns ().begin (), proto.data_columns ().end ());
2255
2305
2256
2306
switch (proto.type_case ()) {
2257
2307
case TProto::kGlobalIndex :
2258
2308
type = EIndexType::GlobalSync;
2309
+ globalIndexSettings = TGlobalIndexSettings::FromProto (proto.global_index ().settings ());
2259
2310
break ;
2260
2311
case TProto::kGlobalAsyncIndex :
2261
2312
type = EIndexType::GlobalAsync;
2313
+ globalIndexSettings = TGlobalIndexSettings::FromProto (proto.global_async_index ().settings ());
2262
2314
break ;
2263
2315
case TProto::kGlobalUniqueIndex :
2264
2316
type = EIndexType::GlobalUnique;
2317
+ globalIndexSettings = TGlobalIndexSettings::FromProto (proto.global_unique_index ().settings ());
2265
2318
break ;
2266
2319
default : // fallback to global sync
2267
2320
type = EIndexType::GlobalSync;
2268
2321
break ;
2269
2322
}
2270
2323
2271
- auto result = TIndexDescription (proto.name (), type, indexColumns, dataColumns);
2324
+ auto result = TIndexDescription (proto.name (), type, indexColumns, dataColumns, globalIndexSettings );
2272
2325
if constexpr (std::is_same_v<TProto, Ydb::Table::TableIndexDescription>) {
2273
2326
result.SizeBytes = proto.size_bytes ();
2274
2327
}
@@ -2286,13 +2339,13 @@ void TIndexDescription::SerializeTo(Ydb::Table::TableIndex& proto) const {
2286
2339
2287
2340
switch (IndexType_) {
2288
2341
case EIndexType::GlobalSync:
2289
- *proto.mutable_global_index () = Ydb::Table::GlobalIndex ( );
2342
+ GlobalIndexSettings_. SerializeTo ( *proto.mutable_global_index ()-> mutable_settings () );
2290
2343
break ;
2291
2344
case EIndexType::GlobalAsync:
2292
- *proto.mutable_global_async_index () = Ydb::Table::GlobalAsyncIndex ( );
2345
+ GlobalIndexSettings_. SerializeTo ( *proto.mutable_global_async_index ()-> mutable_settings () );
2293
2346
break ;
2294
2347
case EIndexType::GlobalUnique:
2295
- *proto.mutable_global_unique_index () = Ydb::Table::GlobalUniqueIndex ( );
2348
+ GlobalIndexSettings_. SerializeTo ( *proto.mutable_global_unique_index ()-> mutable_settings () );
2296
2349
break ;
2297
2350
case EIndexType::Unknown:
2298
2351
break ;
0 commit comments