10
10
#include < ydb/core/tx/tx_proxy/proxy.h>
11
11
#include < ydb/core/tx/tx_proxy/read_table.h>
12
12
13
+ #include < ydb/core/tx/data_events/events.h>
14
+ #include < ydb/core/tx/data_events/payload_helper.h>
15
+
13
16
#include < ydb/public/sdk/cpp/client/ydb_result/result.h>
14
17
15
18
#include < algorithm>
@@ -25,46 +28,52 @@ namespace {
25
28
26
29
using TCellVec = std::vector<TCell>;
27
30
28
- void CreateTable (Tests::TServer::TPtr server,
31
+ TVector<TShardedTableOptions::TColumn> GetColumns () {
32
+ TVector<TShardedTableOptions::TColumn> columns = {
33
+ {" key1" , " Uint32" , true , false },
34
+ {" key2" , " Uint32" , true , false },
35
+ {" key3" , " Uint32" , true , false },
36
+ {" value" , " Uint32" , false , false }};
37
+
38
+ return columns;
39
+ }
40
+
41
+ TVector<TShardedTableOptions::TColumn> GetMoviesColumns () {
42
+ TVector<TShardedTableOptions::TColumn> columns = {
43
+ {" id" , " Uint32" , true , false },
44
+ {" title" , " String" , false , false },
45
+ {" rating" , " Uint32" , false , false }};
46
+
47
+ return columns;
48
+ }
49
+
50
+ std::tuple<TVector<ui64>, ui64> CreateTable (Tests::TServer::TPtr server,
29
51
TActorId sender,
30
52
const TString &root,
31
53
const TString &name,
32
54
bool withFollower = false ,
33
55
ui64 shardCount = 1 )
34
56
{
35
- TVector<TShardedTableOptions::TColumn> columns = {
36
- {" key1" , " Uint32" , true , false },
37
- {" key2" , " Uint32" , true , false },
38
- {" key3" , " Uint32" , true , false },
39
- {" value" , " Uint32" , false , false }
40
- };
41
-
42
57
auto opts = TShardedTableOptions ()
43
58
.Shards (shardCount)
44
- .Columns (columns );
59
+ .Columns (GetColumns () );
45
60
46
61
if (withFollower)
47
62
opts.Followers (1 );
48
63
49
- CreateShardedTable (server, sender, root, name, opts);
64
+ return CreateShardedTable (server, sender, root, name, opts);
50
65
}
51
66
52
- void CreateMoviesTable (Tests::TServer::TPtr server,
67
+ std::tuple<TVector<ui64>, ui64> CreateMoviesTable (Tests::TServer::TPtr server,
53
68
TActorId sender,
54
69
const TString &root,
55
70
const TString &name)
56
71
{
57
- TVector<TShardedTableOptions::TColumn> columns = {
58
- {" id" , " Uint32" , true , false },
59
- {" title" , " String" , false , false },
60
- {" rating" , " Uint32" , false , false }
61
- };
62
-
63
72
auto opts = TShardedTableOptions ()
64
73
.Shards (1 )
65
- .Columns (columns );
74
+ .Columns (GetMoviesColumns () );
66
75
67
- CreateShardedTable (server, sender, root, name, opts);
76
+ return CreateShardedTable (server, sender, root, name, opts);
68
77
}
69
78
70
79
struct TRowWriter : public NArrow ::IRowWriter {
@@ -308,11 +317,14 @@ void AddRangeQuery(
308
317
struct TTableInfo {
309
318
TString Name;
310
319
320
+ ui64 TableId;
311
321
ui64 TabletId;
312
322
ui64 OwnerId;
313
323
NKikimrTxDataShard::TEvGetInfoResponse::TUserTable UserTable;
314
324
315
325
TActorId ClientId;
326
+
327
+ TVector<TShardedTableOptions::TColumn> Columns;
316
328
};
317
329
318
330
struct TTestHelper {
@@ -345,7 +357,7 @@ struct TTestHelper {
345
357
{
346
358
auto & table1 = Tables[" table-1" ];
347
359
table1.Name = " table-1" ;
348
- CreateTable (Server, Sender, " /Root" , " table-1" , WithFollower, ShardCount);
360
+ auto [shards, tableId] = CreateTable (Server, Sender, " /Root" , " table-1" , WithFollower, ShardCount);
349
361
ExecSQL (Server, Sender, R"(
350
362
UPSERT INTO `/Root/table-1`
351
363
(key1, key2, key3, value)
@@ -360,20 +372,22 @@ struct TTestHelper {
360
372
(11, 11, 11, 1111);
361
373
)" );
362
374
363
- auto shards = GetTableShards (Server, Sender, " /Root/table-1 " ) ;
375
+ table1. TableId = tableId ;
364
376
table1.TabletId = shards.at (0 );
365
377
366
378
auto [tables, ownerId] = GetTables (Server, table1.TabletId );
367
379
table1.OwnerId = ownerId;
368
380
table1.UserTable = tables[" table-1" ];
369
381
370
382
table1.ClientId = runtime.ConnectToPipe (table1.TabletId , Sender, 0 , GetTestPipeConfig ());
383
+
384
+ table1.Columns = GetColumns ();
371
385
}
372
386
373
387
{
374
388
auto & table2 = Tables[" movies" ];
375
389
table2.Name = " movies" ;
376
- CreateMoviesTable (Server, Sender, " /Root" , " movies" );
390
+ auto [shards, tableId] = CreateMoviesTable (Server, Sender, " /Root" , " movies" );
377
391
ExecSQL (Server, Sender, R"(
378
392
UPSERT INTO `/Root/movies`
379
393
(id, title, rating)
@@ -383,29 +397,33 @@ struct TTestHelper {
383
397
(3, "Hard die", 8);
384
398
)" );
385
399
386
- auto shards = GetTableShards (Server, Sender, " /Root/movies " ) ;
400
+ table2. TableId = tableId ;
387
401
table2.TabletId = shards.at (0 );
388
402
389
403
auto [tables, ownerId] = GetTables (Server, table2.TabletId );
390
404
table2.OwnerId = ownerId;
391
405
table2.UserTable = tables[" movies" ];
392
406
393
407
table2.ClientId = runtime.ConnectToPipe (table2.TabletId , Sender, 0 , GetTestPipeConfig ());
408
+
409
+ table2.Columns = GetMoviesColumns ();
394
410
}
395
411
396
412
{
397
413
auto & table3 = Tables[" table-1-many" ];
398
414
table3.Name = " table-1-many" ;
399
- CreateTable (Server, Sender, " /Root" , " table-1-many" , WithFollower, ShardCount);
415
+ auto [shards, tableId] = CreateTable (Server, Sender, " /Root" , " table-1-many" , WithFollower, ShardCount);
400
416
401
- auto shards = GetTableShards (Server, Sender, " /Root/table-1-many " ) ;
417
+ table3. TableId = tableId ;
402
418
table3.TabletId = shards.at (0 );
403
419
404
420
auto [tables, ownerId] = GetTables (Server, table3.TabletId );
405
421
table3.OwnerId = ownerId;
406
422
table3.UserTable = tables[" table-1-many" ];
407
423
408
424
table3.ClientId = runtime.ConnectToPipe (table3.TabletId , Sender, 0 , GetTestPipeConfig ());
425
+
426
+ table3.Columns = GetColumns ();
409
427
}
410
428
}
411
429
@@ -717,6 +735,30 @@ struct TTestHelper {
717
735
UNIT_ASSERT_VALUES_EQUAL (rowsRead, Min (rowCount, limit));
718
736
}
719
737
738
+ NKikimrDataEvents::TEvWriteResult WriteRow (const TString& tableName, ui64 txId, const TVector<ui32>& values, NKikimrDataEvents::TEvWrite::ETxMode txMode = NKikimrDataEvents::TEvWrite::MODE_IMMEDIATE) {
739
+ const auto & table = Tables[tableName];
740
+
741
+ auto opts = TShardedTableOptions ().Columns (table.Columns );
742
+ size_t columnCount = table.Columns .size ();
743
+
744
+ std::vector<ui32> columnIds (columnCount);
745
+ std::iota (columnIds.begin (), columnIds.end (), 1 );
746
+
747
+ Y_ABORT_UNLESS (values.size () == columnCount);
748
+
749
+ TVector<TCell> cells;
750
+ for (ui32 col = 0 ; col < columnCount; ++col)
751
+ cells.emplace_back (TCell ((const char *)&values[col], sizeof (ui32)));
752
+
753
+ TSerializedCellMatrix matrix (cells, 1 , columnCount);
754
+
755
+ auto evWrite = std::make_unique<NKikimr::NEvents::TDataEvents::TEvWrite>(txId, txMode);
756
+ ui64 payloadIndex = NKikimr::NEvWrite::TPayloadHelper<NKikimr::NEvents::TDataEvents::TEvWrite>(*evWrite).AddDataToPayload (matrix.ReleaseBuffer ());
757
+ evWrite->AddOperation (NKikimrDataEvents::TEvWrite::TOperation::OPERATION_UPSERT, table.TableId , 1 , columnIds, payloadIndex, NKikimrDataEvents::FORMAT_CELLVEC);
758
+
759
+ return Write (*Server->GetRuntime (), Sender, table.TabletId , std::move (evWrite));
760
+ }
761
+
720
762
struct THangedReturn {
721
763
ui64 LastPlanStep = 0 ;
722
764
TVector<THolder<IEventHandle>> ReadSets;
0 commit comments