@@ -248,7 +248,7 @@ void CreateUniformTable(TTestEnv& env, const TString& databaseName, const TStrin
248248 ExecuteYqlScript (env, Sprintf (R"(
249249 CREATE TABLE `Root/%s/%s` (
250250 Key Uint64,
251- Value Uint64 ,
251+ Value String ,
252252 PRIMARY KEY (Key)
253253 )
254254 WITH ( UNIFORM_PARTITIONS = 4 );
@@ -266,7 +266,7 @@ void PrepareUniformTable(TTestEnv& env, const TString& databaseName, const TStri
266266 replace << " , " ;
267267 }
268268 ui64 value = 4000000000000000000ull * (i + 1 );
269- replace << Sprintf (" (%" PRIu64 " ul, %" PRIu64 " ul )" , value, value);
269+ replace << Sprintf (" (%" PRIu64 " ul, \" %" PRIu64 " \" )" , value, value);
270270 }
271271 replace << " ;" ;
272272 ExecuteYqlScript (env, replace);
@@ -299,7 +299,9 @@ TTableInfo CreateColumnTable(TTestEnv& env, const TString& databaseName, const T
299299 return tableInfo;
300300}
301301
302- void InsertDataIntoTable (TTestEnv& env, const TString& databaseName, const TString& tableName, size_t rowCount) {
302+ void InsertDataIntoTable (
303+ TTestEnv& env, const TString& databaseName, const TString& tableName,
304+ std::vector<TInsertedRow> insertedRows) {
303305 auto fullTableName = Sprintf (" Root/%s/%s" , databaseName.c_str (), tableName.c_str ());
304306 auto & runtime = *env.GetServer ().GetRuntime ();
305307
@@ -319,11 +321,10 @@ void InsertDataIntoTable(TTestEnv& env, const TString& databaseName, const TStri
319321 reqValueType->mutable_type ()->mutable_optional_type ()->mutable_item ()->set_type_id (Ydb::Type::STRING);
320322
321323 auto * reqRows = rows->mutable_value ();
322-
323- for (size_t i = 0 ; i < rowCount; ++i) {
324+ for (const auto & inserted : insertedRows) {
324325 auto * row = reqRows->add_items ();
325- row->add_items ()->set_uint64_value (i );
326- row->add_items ()->set_bytes_value (ToString (i) );
326+ row->add_items ()->set_uint64_value (inserted. Key );
327+ row->add_items ()->set_bytes_value (inserted. Value );
327328 }
328329
329330 auto future = NRpcService::DoLocalRpc<TEvBulkUpsertRequest>(
@@ -335,12 +336,16 @@ void InsertDataIntoTable(TTestEnv& env, const TString& databaseName, const TStri
335336 env.GetController ()->WaitActualization (TDuration::Seconds (1 ));
336337}
337338
338-
339339TTableInfo PrepareColumnTable (TTestEnv& env, const TString& databaseName, const TString& tableName,
340340 int shardCount)
341341{
342342 auto info = CreateColumnTable (env, databaseName, tableName, shardCount);
343- InsertDataIntoTable (env, databaseName, tableName, ColumnTableRowsNumber);
343+
344+ std::vector<TInsertedRow> rows;
345+ for (size_t i = 0 ; i < ColumnTableRowsNumber; ++i) {
346+ rows.push_back (TInsertedRow{.Key = i, .Value = ToString (i)});
347+ }
348+ InsertDataIntoTable (env, databaseName, tableName, rows);
344349 return info;
345350}
346351
@@ -399,7 +404,7 @@ TTableInfo PrepareColumnTableWithIndexes(TTestEnv& env, const TString& databaseN
399404 auto future = NRpcService::DoLocalRpc<TEvBulkUpsertRequest>(
400405 std::move (request), " " , " " , runtime.GetActorSystem (0 ));
401406 auto response = runtime.WaitFuture (std::move (future));
402-
407+
403408 UNIT_ASSERT (response.operation ().ready ());
404409 UNIT_ASSERT_VALUES_EQUAL (response.operation ().status (), Ydb::StatusIds::SUCCESS);
405410 }
@@ -409,6 +414,14 @@ TTableInfo PrepareColumnTableWithIndexes(TTestEnv& env, const TString& databaseN
409414 return info;
410415}
411416
417+ std::vector<TInsertedRow> RowsWithFewDistinctValues (size_t count) {
418+ std::vector<TInsertedRow> rows;
419+ for (size_t i = 0 ; i < count; ++i) {
420+ rows.push_back (TInsertedRow{.Key = i, .Value = ToString (i % 10 )});
421+ }
422+ return rows;
423+ }
424+
412425void DropTable (TTestEnv& env, const TString& databaseName, const TString& tableName) {
413426 ExecuteYqlScript (env, Sprintf (R"(
414427 DROP TABLE `Root/%s/%s`;
@@ -442,16 +455,6 @@ std::shared_ptr<TCountMinSketch> ExtractCountMin(TTestActorRuntime& runtime, con
442455 return stat.CountMin ;
443456}
444457
445- void ValidateCountMinDatashard (TTestActorRuntime& runtime, TPathId pathId) {
446- auto countMin = ExtractCountMin (runtime, pathId);
447-
448- for (ui32 i = 0 ; i < 4 ; ++i) {
449- ui64 value = 4000000000000000000ull * (i + 1 );
450- auto probe = countMin->Probe ((const char *)&value, sizeof (ui64));
451- UNIT_ASSERT_VALUES_EQUAL (probe, 1 );
452- }
453- }
454-
455458void ValidateCountMinAbsence (TTestActorRuntime& runtime, TPathId pathId) {
456459 auto statServiceId = NStat::MakeStatServiceID (runtime.GetNodeId (1 ));
457460
@@ -475,6 +478,43 @@ void ValidateCountMinAbsence(TTestActorRuntime& runtime, TPathId pathId) {
475478 UNIT_ASSERT (!rsp.Success );
476479}
477480
481+ void CheckCountMinSketch (
482+ TTestActorRuntime& runtime, const TPathId& pathId,
483+ const std::vector<TCountMinSketchProbes>& expected) {
484+ auto evGet = std::make_unique<TEvStatistics::TEvGetStatistics>();
485+ evGet->StatType = NStat::EStatType::COUNT_MIN_SKETCH;
486+
487+ for (auto item : expected) {
488+ NStat::TRequest req;
489+ req.PathId = pathId;
490+ req.ColumnTag = item.Tag ;
491+ evGet->StatRequests .push_back (req);
492+ }
493+
494+ auto sender = runtime.AllocateEdgeActor ();
495+ auto statServiceId = NStat::MakeStatServiceID (runtime.GetNodeId (0 ));
496+ runtime.Send (statServiceId, sender, evGet.release (), 0 , true );
497+
498+ auto res = runtime.GrabEdgeEventRethrow <TEvStatistics::TEvGetStatisticsResult>(sender);
499+ auto msg = res->Get ();
500+
501+ UNIT_ASSERT (msg->Success );
502+ UNIT_ASSERT ( msg->StatResponses .size () == expected.size ());
503+
504+ for (size_t i = 0 ; i < msg->StatResponses .size (); ++i) {
505+ const auto & stat = msg->StatResponses [i];
506+ UNIT_ASSERT (stat.Success );
507+
508+ auto countMin = stat.CountMinSketch .CountMin .get ();
509+ UNIT_ASSERT (countMin != nullptr );
510+
511+ for (const auto & item : expected[i].Probes ) {
512+ auto probe = countMin->Probe (item.Value .data (), item.Value .size ());
513+ UNIT_ASSERT_VALUES_EQUAL (item.Expected , probe);
514+ }
515+ }
516+ }
517+
478518TAnalyzedTable::TAnalyzedTable (const TPathId& pathId)
479519 : PathId(pathId)
480520{}
0 commit comments