@@ -239,4 +239,67 @@ ColumnFamilies {
239
239
" { 0 -> 0, 1 -> 1 }" );
240
240
}
241
241
242
+ Y_UNIT_TEST (IndexBuildInfoAddParent) {
243
+ TIndexBuildInfo info;
244
+
245
+ info.KMeans .ParentBegin = 1 ;
246
+ info.KMeans .Parent = 1 ;
247
+ info.KMeans .ChildBegin = 201 ;
248
+ info.KMeans .Child = 201 ;
249
+
250
+ TVector<TCell> from = {TCell::Make ((ui64)1 ), TCell::Make (123 )};
251
+ TVector<TCell> to = {TCell::Make ((ui64)3 ), TCell::Make (123 )};
252
+ auto range = TSerializedTableRange (from, true , to, true );
253
+ info.AddParent (range, TShardIdx (1 , 1 ));
254
+
255
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .size (), 1 );
256
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .at (3 ).From , 1 );
257
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .at (3 ).Shards .size (), 1 );
258
+
259
+ // add an intersecting shard. it even crashed here until 02.07.2025 :)
260
+ from = {TCell::Make ((ui64)3 ), TCell::Make (123 )};
261
+ to = {TCell::Make ((ui64)4 ), TCell::Make (123 )};
262
+ range = TSerializedTableRange (from, true , to, true );
263
+ info.AddParent (range, TShardIdx (1 , 2 ));
264
+
265
+ // Cluster2Shards is a rather stupid thing - for now, it just merges all intersecting
266
+ // shard ranges into a single item, thus losing the range info for individual cluster IDs
267
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .size (), 1 );
268
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .at (4 ).From , 1 );
269
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .at (4 ).Shards .size (), 2 );
270
+
271
+ // add a non-intersecting shard
272
+ from = {TCell::Make ((ui64)5 ), TCell::Make (123 )};
273
+ to = {TCell::Make ((ui64)6 ), TCell::Make (123 )};
274
+ range = TSerializedTableRange (from, true , to, true );
275
+ info.AddParent (range, TShardIdx (1 , 3 ));
276
+
277
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .size (), 2 );
278
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .at (4 ).From , 1 );
279
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .at (4 ).Shards .size (), 2 );
280
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .at (6 ).From , 5 );
281
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .at (6 ).Shards .size (), 1 );
282
+
283
+ // incomplete range is "from (99, +infinity)", thus equal to "from [100]"
284
+ from = {TCell::Make ((ui64)99 )};
285
+ to = {TCell::Make ((ui64)100 ), TCell::Make (123 )};
286
+ range = TSerializedTableRange (from, true , to, true );
287
+ info.AddParent (range, TShardIdx (1 , 4 ));
288
+
289
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .size (), 3 );
290
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .at (100 ).From , 100 );
291
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .at (100 ).Shards .size (), 1 );
292
+
293
+ // insert and check something before an existing item
294
+ from = {TCell::Make ((ui64)50 ), TCell::Make (123 )};
295
+ to = {TCell::Make ((ui64)51 ), TCell::Make (123 )};
296
+ range = TSerializedTableRange (from, true , to, true );
297
+ info.AddParent (range, TShardIdx (1 , 5 ));
298
+
299
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .size (), 4 );
300
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .at (51 ).From , 50 );
301
+ UNIT_ASSERT_VALUES_EQUAL (info.Cluster2Shards .at (51 ).Shards .size (), 1 );
302
+
303
+ }
304
+
242
305
}
0 commit comments