Skip to content

Commit e1c69bf

Browse files
vitalifkunga
authored andcommitted
Extract CountRows() to generic ut helpers (#19009)
1 parent a1936b3 commit e1c69bf

File tree

6 files changed

+26
-35
lines changed

6 files changed

+26
-35
lines changed

ydb/core/tx/schemeshard/ut_helpers/helpers.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,6 +2628,24 @@ namespace NSchemeShardUT_Private {
26282628
return result;
26292629
}
26302630

2631+
ui32 CountRows(TTestActorRuntime& runtime, ui64 schemeshardId, const TString& table) {
2632+
auto tableDesc = DescribePath(runtime, schemeshardId, table, true, false, true);
2633+
const auto& pathDesc = tableDesc.GetPathDescription();
2634+
const auto& key = pathDesc.GetTable().GetKeyColumnNames();
2635+
ui32 rows = 0;
2636+
for (const auto& x : pathDesc.GetTablePartitions()) {
2637+
auto result = ReadTable(runtime, x.GetDatashardId(), pathDesc.GetSelf().GetName(),
2638+
{key.begin(), key.end()}, {pathDesc.GetTable().GetKeyColumnNames()[0]});
2639+
auto value = NClient::TValue::Create(result);
2640+
rows += value["Result"]["List"].Size();
2641+
}
2642+
return rows;
2643+
}
2644+
2645+
ui32 CountRows(TTestActorRuntime& runtime, const TString& table) {
2646+
return CountRows(runtime, TTestTxConfig::SchemeShard, table);
2647+
}
2648+
26312649
void WriteVectorTableRows(TTestActorRuntime& runtime, ui64 schemeShardId, ui64 txId, const TString & tablePath, bool withValue, ui32 shard, ui32 min, ui32 max) {
26322650
TVector<TCell> cells;
26332651
ui8 str[6] = { 0 };

ydb/core/tx/schemeshard/ut_helpers/helpers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,9 @@ namespace NSchemeShardUT_Private {
653653
NKikimrMiniKQL::TResult ReadTable(TTestActorRuntime& runtime, ui64 tabletId,
654654
const TString& table, const TVector<TString>& pk, const TVector<TString>& columns, const TString& rangeFlags = "");
655655

656+
ui32 CountRows(TTestActorRuntime& runtime, ui64 schemeshardId, const TString& table);
657+
ui32 CountRows(TTestActorRuntime& runtime, const TString& table);
658+
656659
void WriteVectorTableRows(TTestActorRuntime& runtime, ui64 schemeShardId, ui64 txId, const TString & tablePath,
657660
bool withValue, ui32 shard, ui32 min, ui32 max);
658661

ydb/core/tx/schemeshard/ut_helpers/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ PEERDIR(
2121
ydb/core/tx/tx_proxy
2222
ydb/public/lib/scheme_types
2323
yql/essentials/public/issue
24+
ydb/public/lib/deprecated/kicli
2425
ydb/public/sdk/cpp/src/client/driver
2526
ydb/public/sdk/cpp/src/client/table
2627
)

ydb/core/tx/schemeshard/ut_index/ut_async_index.cpp

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -126,37 +126,15 @@ Y_UNIT_TEST_SUITE(TAsyncIndexTests) {
126126
ui32 ExpectedRecords;
127127
};
128128

129-
template <typename C>
130-
ui32 CountRows(TTestActorRuntime& runtime, const TTableTraits& table, const C& partitions) {
131-
ui32 rows = 0;
132-
133-
for (const auto& x : partitions) {
134-
auto result = ReadTable(runtime, x.GetDatashardId(), SplitPath(table.Path).back(), table.Key, table.Columns);
135-
auto value = NClient::TValue::Create(result);
136-
rows += value["Result"]["List"].Size();
137-
}
138-
139-
return rows;
140-
}
141-
142129
bool CheckWrittenToIndex(TTestActorRuntime& runtime, const TTableTraits& mainTable, const TTableTraits& indexTable) {
143-
bool writtenToMainTable = false;
144-
{
145-
auto tableDesc = DescribePath(runtime, mainTable.Path, true, true);
146-
const auto& tablePartitions = tableDesc.GetPathDescription().GetTablePartitions();
147-
UNIT_ASSERT(!tablePartitions.empty());
148-
writtenToMainTable = mainTable.ExpectedRecords == CountRows(runtime, mainTable, tablePartitions);
149-
}
130+
auto mainTableRows = CountRows(runtime, mainTable.Path);
131+
bool writtenToMainTable = (mainTable.ExpectedRecords == mainTableRows);
150132

151133
if (writtenToMainTable) {
152-
auto tableDesc = DescribePrivatePath(runtime, indexTable.Path, true, true);
153-
const auto& tablePartitions = tableDesc.GetPathDescription().GetTablePartitions();
154-
UNIT_ASSERT(!tablePartitions.empty());
155-
156134
int i = 0;
157135
while (++i < 10) {
158136
runtime.SimulateSleep(TDuration::Seconds(1));
159-
if (indexTable.ExpectedRecords == CountRows(runtime, indexTable, tablePartitions)) {
137+
if (indexTable.ExpectedRecords == CountRows(runtime, indexTable.Path)) {
160138
break;
161139
}
162140
}

ydb/core/tx/schemeshard/ut_index/ya.make

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ PEERDIR(
1616
ydb/core/scheme
1717
ydb/core/testlib/default
1818
ydb/core/tx/schemeshard/ut_helpers
19-
ydb/public/lib/deprecated/kicli
2019
)
2120

2221
SRCS(

ydb/core/tx/schemeshard/ut_index_build/ut_vector_index_build.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,7 @@ Y_UNIT_TEST_SUITE (VectorIndexBuildTest) {
177177

178178
// Check row count in the posting table
179179
{
180-
auto indexDesc = DescribePath(runtime, tenantSchemeShard, "/MyRoot/ServerLessDB/Table/index1/indexImplPostingTable", true, true, true);
181-
auto parts = indexDesc.GetPathDescription().GetTablePartitions();
182-
ui32 rows = 0;
183-
for (const auto & x: parts) {
184-
auto result = ReadTable(runtime, x.GetDatashardId(), "indexImplPostingTable",
185-
{NKikimr::NTableIndex::NTableVectorKmeansTreeIndex::ParentColumn, "key"}, {"key"});
186-
auto value = NClient::TValue::Create(result);
187-
rows += value["Result"]["List"].Size();
188-
}
180+
auto rows = CountRows(runtime, tenantSchemeShard, "/MyRoot/ServerLessDB/Table/index1/indexImplPostingTable");
189181
Cerr << "... posting table contains " << rows << " rows" << Endl;
190182
UNIT_ASSERT_VALUES_EQUAL(rows, 200);
191183
}

0 commit comments

Comments
 (0)