Skip to content

Commit

Permalink
improve writing test for control portions count and compaction disable (
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmorozov333 authored Jan 9, 2025
1 parent 592bc99 commit bf7c753
Showing 1 changed file with 61 additions and 20 deletions.
81 changes: 61 additions & 20 deletions ydb/core/kqp/ut/olap/write_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ Y_UNIT_TEST_SUITE(KqpOlapWrite) {
settings.AppConfig.MutableColumnShardConfig()->SetWritingBufferDurationMs(15000);
TKikimrRunner kikimr(settings);
Tests::NCommon::TLoggerInit(kikimr).Initialize();
auto csController = NKikimr::NYDBTest::TControllers::RegisterCSControllerGuard<NKikimr::NYDBTest::NColumnShard::TReadOnlyController>();
TTypedLocalHelper helper("Utf8", kikimr);
helper.CreateTestOlapTable();
auto writeSession = helper.StartWriting("/Root/olapStore/olapTable");
Expand All @@ -209,30 +210,51 @@ Y_UNIT_TEST_SUITE(KqpOlapWrite) {
writeSession.FillTable("field", NArrow::NConstruction::TStringPoolFiller(1, 1, "ccc", 1), 0.75, 800000);
Sleep(TDuration::Seconds(1));
writeSession.Finalize();

auto selectQuery = TString(R"(
{
auto selectQuery = TString(R"(
SELECT
field, count(*) as count,
FROM `/Root/olapStore/olapTable`
GROUP BY field
ORDER BY field
)");

auto tableClient = kikimr.GetTableClient();
auto rows = ExecuteScanQuery(tableClient, selectQuery);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[0].at("count")), 400000);
UNIT_ASSERT_VALUES_EQUAL(GetUtf8(rows[0].at("field")), "aaa");
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[1].at("count")), 200000);
UNIT_ASSERT_VALUES_EQUAL(GetUtf8(rows[1].at("field")), "bbb");
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[2].at("count")), 800000);
UNIT_ASSERT_VALUES_EQUAL(GetUtf8(rows[2].at("field")), "ccc");
auto tableClient = kikimr.GetTableClient();
auto rows = ExecuteScanQuery(tableClient, selectQuery);
UNIT_ASSERT_VALUES_EQUAL(rows.size(), 3);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[0].at("count")), 400000);
UNIT_ASSERT_VALUES_EQUAL(GetUtf8(rows[0].at("field")), "aaa");
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[1].at("count")), 200000);
UNIT_ASSERT_VALUES_EQUAL(GetUtf8(rows[1].at("field")), "bbb");
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[2].at("count")), 800000);
UNIT_ASSERT_VALUES_EQUAL(GetUtf8(rows[2].at("field")), "ccc");
}
{
auto selectQuery = TString(R"(
SELECT COUNT(*) as count, MAX(PortionId) as portion_id, TabletId
FROM `/Root/olapStore/olapTable/.sys/primary_index_portion_stats`
GROUP BY TabletId
)");

auto tableClient = kikimr.GetTableClient();
auto rows = ExecuteScanQuery(tableClient, selectQuery);
UNIT_ASSERT_VALUES_EQUAL(rows.size(), 3);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[0].at("count")), 1);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[1].at("count")), 1);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[2].at("count")), 1);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[0].at("portion_id")), 1);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[1].at("portion_id")), 1);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[2].at("portion_id")), 1);
}
AFL_VERIFY(csController->GetCompactionStartedCounter().Val() == 0);
}

Y_UNIT_TEST(MultiWriteInTimeDiffSchemas) {
auto settings = TKikimrSettings().SetWithSampleTables(false);
settings.AppConfig.MutableColumnShardConfig()->SetWritingBufferDurationMs(15000);
TKikimrRunner kikimr(settings);
Tests::NCommon::TLoggerInit(kikimr).Initialize();
auto csController = NKikimr::NYDBTest::TControllers::RegisterCSControllerGuard<NKikimr::NYDBTest::NColumnShard::TReadOnlyController>();
TTypedLocalHelper helper("Utf8", "Utf8", kikimr);
helper.CreateTestOlapTable();
auto writeGuard = helper.StartWriting("/Root/olapStore/olapTable");
Expand All @@ -243,23 +265,42 @@ Y_UNIT_TEST_SUITE(KqpOlapWrite) {
writeGuard.FillTable("field", NArrow::NConstruction::TStringPoolFiller(1, 1, "ccc", 1), 0.75, 800000);
Sleep(TDuration::Seconds(1));
writeGuard.Finalize();

auto selectQuery = TString(R"(
{
auto selectQuery = TString(R"(
SELECT
field, count(*) as count,
FROM `/Root/olapStore/olapTable`
GROUP BY field
ORDER BY field
)");

auto tableClient = kikimr.GetTableClient();
auto rows = ExecuteScanQuery(tableClient, selectQuery);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[0].at("count")), 200000);
UNIT_ASSERT_VALUES_EQUAL(GetUtf8(rows[0].at("field")), "");
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[1].at("count")), 400000);
UNIT_ASSERT_VALUES_EQUAL(GetUtf8(rows[1].at("field")), "aaa");
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[2].at("count")), 800000);
UNIT_ASSERT_VALUES_EQUAL(GetUtf8(rows[2].at("field")), "ccc");
auto tableClient = kikimr.GetTableClient();
auto rows = ExecuteScanQuery(tableClient, selectQuery);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[0].at("count")), 200000);
UNIT_ASSERT_VALUES_EQUAL(GetUtf8(rows[0].at("field")), "");
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[1].at("count")), 400000);
UNIT_ASSERT_VALUES_EQUAL(GetUtf8(rows[1].at("field")), "aaa");
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[2].at("count")), 800000);
UNIT_ASSERT_VALUES_EQUAL(GetUtf8(rows[2].at("field")), "ccc");
}
{
auto selectQuery = TString(R"(
SELECT COUNT(*) as count, MAX(PortionId) as portion_id, TabletId
FROM `/Root/olapStore/olapTable/.sys/primary_index_portion_stats`
GROUP BY TabletId
)");

auto tableClient = kikimr.GetTableClient();
auto rows = ExecuteScanQuery(tableClient, selectQuery);
UNIT_ASSERT_VALUES_EQUAL(rows.size(), 3);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[0].at("count")), 1);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[1].at("count")), 1);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[2].at("count")), 1);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[0].at("portion_id")), 1);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[1].at("portion_id")), 1);
UNIT_ASSERT_VALUES_EQUAL(GetUint64(rows[2].at("portion_id")), 1);
}
AFL_VERIFY(csController->GetCompactionStartedCounter().Val() == 0);
}

Y_UNIT_TEST(WriteDeleteCleanGC) {
Expand Down

0 comments on commit bf7c753

Please sign in to comment.