@@ -30,6 +30,17 @@ using namespace NTestUtils;
3030
3131namespace {
3232
33+ void FillRootTable (TTestEnv& env, ui16 tableNum = 0 ) {
34+ TTableClient client (env.GetDriver ());
35+ auto session = client.CreateSession ().GetValueSync ().GetSession ();
36+ NKqp::AssertSuccessResult (session.ExecuteDataQuery (Sprintf (R"(
37+ REPLACE INTO `Root/Table%u` (Key, Value) VALUES
38+ (0u, "X"),
39+ (1u, "Y"),
40+ (2u, "Z");
41+ )" , tableNum), TTxControl::BeginTx ().CommitTx ()).GetValueSync ());
42+ }
43+
3344void CreateRootTable (TTestEnv& env, ui64 partitionCount = 1 , bool fillTable = false , ui16 tableNum = 0 ) {
3445 env.GetClient ().CreateTable (" /Root" , Sprintf (R"(
3546 Name: "Table%u"
@@ -39,16 +50,23 @@ void CreateRootTable(TTestEnv& env, ui64 partitionCount = 1, bool fillTable = fa
3950 UniformPartitionsCount: %lu
4051 )" , tableNum, partitionCount));
4152
42- if (fillTable) {
43- TTableClient client (env.GetDriver ());
44- auto session = client.CreateSession ().GetValueSync ().GetSession ();
45- NKqp::AssertSuccessResult (session.ExecuteDataQuery (R"(
46- REPLACE INTO `Root/Table0` (Key, Value) VALUES
47- (0u, "X"),
48- (1u, "Y"),
49- (2u, "Z");
50- )" , TTxControl::BeginTx ().CommitTx ()).GetValueSync ());
51- }
53+ if (fillTable)
54+ FillRootTable (env, tableNum);
55+ }
56+
57+ void CreateRootColumnTable (TTestEnv& env, ui64 partitionCount = 1 , bool fillTable = false , ui16 tableNum = 0 ) {
58+ NQuery::TQueryClient client (env.GetDriver ());
59+ auto result = client.ExecuteQuery (Sprintf (R"(
60+ CREATE TABLE `/Root/Table%u` (
61+ Key Int32 NOT NULL,
62+ Value Utf8,
63+ PRIMARY KEY(Key)
64+ ) WITH (STORE=COLUMN, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = %lu);
65+ )" , tableNum, partitionCount), NQuery::TTxControl::NoTx ()).GetValueSync ();
66+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
67+
68+ if (fillTable)
69+ FillRootTable (env, tableNum);
5270}
5371
5472void BreakLock (TSession& session, const TString& tableName) {
@@ -2646,68 +2664,27 @@ R"(CREATE TABLE `test_show_create` (
26462664 check.Uint64 (1u ); // LastTtlRowsProcessed
26472665 check.Uint64 (1u ); // LastTtlRowsErased
26482666 }
2649-
2650- Y_UNIT_TEST (PartitionStatsAfterRemoveColumnTable) {
2651- TTestEnv env;
2652- NQuery::TQueryClient client (env.GetDriver ());
2653-
2654- {
2655- auto result = client.ExecuteQuery (R"(
2656- CREATE TABLE `/Root/test_table` (
2657- key int not null,
2658- value utf8,
2659- PRIMARY KEY(key)
2660- ) WITH (STORE=COLUMN);
2661- )" , NQuery::TTxControl::NoTx ()).GetValueSync ();
2662-
2663- UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
2664- }
2665-
2666- {
2667- auto result = client.ExecuteQuery (R"(
2668- SELECT Path FROM `/Root/.sys/partition_stats`
2669- GROUP BY Path;
2670- )" , NQuery::TTxControl::NoTx ()).GetValueSync ();
2671- UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
2672- auto parser = result.GetResultSetParser (0 );
2673- bool existsPath = false ;
2674- while (parser.TryNextRow ()) {
2675- auto path = parser.ColumnParser (" Path" ).GetOptionalUtf8 ();
2676- UNIT_ASSERT (path);
2677- if (*path == " /Root/test_table" ) {
2678- existsPath = true ;
2679- break ;
2680- }
2681- }
2682- UNIT_ASSERT_C (existsPath, " Path /Root/test_table not found" );
2683- }
2684-
2685- {
2686- auto result = client.ExecuteQuery (R"(
2687- DROP TABLE `/Root/test_table`
2688- )" , NQuery::TTxControl::NoTx ()).GetValueSync ();
2689-
2690- UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
2691- }
2692-
2693- {
2694- auto result = client.ExecuteQuery (R"(
2695- SELECT Path FROM `/Root/.sys/partition_stats`
2696- GROUP BY Path;
2697- )" , NQuery::TTxControl::NoTx ()).GetValueSync ();
2698- UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
2699- auto parser = result.GetResultSetParser (0 );
2700- bool existsPath = false ;
2701- while (parser.TryNextRow ()) {
2702- auto path = parser.ColumnParser (" Path" ).GetOptionalUtf8 ();
2703- UNIT_ASSERT (path);
2704- if (*path == " /Root/test_table" ) {
2705- existsPath = true ;
2706- break ;
2707- }
2708- }
2709- UNIT_ASSERT_C (!existsPath, " Path /Root/test_table found" );
2710- }
2667+
2668+ Y_UNIT_TEST_TWIN (PartitionStatsAfterDropTable, UseColumnTable) {
2669+ TTestEnv env ({.DataShardStatsReportIntervalSeconds = 0 });
2670+ if (UseColumnTable)
2671+ CreateRootColumnTable (env);
2672+ else
2673+ CreateRootTable (env);
2674+
2675+ TTableClient client (env.GetDriver ());
2676+
2677+ WaitForStats (client, " /Root/.sys/partition_stats" , " Path = '/Root/Table0'" );
2678+
2679+ auto session = client.CreateSession ().GetValueSync ().GetSession ();
2680+ auto result = session.ExecuteSchemeQuery (R"(
2681+ DROP TABLE `Root/Table0`;
2682+ )" ).GetValueSync ();
2683+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
2684+
2685+ // Verify Table0 is removed from partition_stats
2686+ auto table0Count = GetRowCount (client, " /Root/.sys/partition_stats" , " Path = '/Root/Table0'" );
2687+ UNIT_ASSERT_VALUES_EQUAL (table0Count, 0 );
27112688 }
27122689
27132690 Y_UNIT_TEST (PartitionStatsLocksFields) {
@@ -2738,6 +2715,34 @@ R"(CREATE TABLE `test_show_create` (
27382715 check.Uint64 (1 ); // LocksBroken
27392716 }
27402717
2718+ Y_UNIT_TEST_TWIN (PartitionStatsAfterRenameTable, UseColumnTable) {
2719+ TTestEnv env ({.DataShardStatsReportIntervalSeconds = 0 });
2720+ if (UseColumnTable)
2721+ CreateRootColumnTable (env);
2722+ else
2723+ CreateRootTable (env);
2724+
2725+ TTableClient client (env.GetDriver ());
2726+ auto session = client.CreateSession ().GetValueSync ().GetSession ();
2727+
2728+ WaitForStats (client, " /Root/.sys/partition_stats" , " Path = '/Root/Table0'" );
2729+
2730+ auto result = session.ExecuteSchemeQuery (R"(
2731+ ALTER TABLE `Root/Table0` RENAME TO `Root/Table1`;
2732+ )" ).GetValueSync ();
2733+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
2734+
2735+ WaitForStats (client, " /Root/.sys/partition_stats" , " Path = '/Root/Table1'" );
2736+
2737+ // Verify Table0 is no longer in partition_stats
2738+ auto table0Count = GetRowCount (client, " /Root/.sys/partition_stats" , " Path = '/Root/Table0'" );
2739+ UNIT_ASSERT_VALUES_EQUAL (table0Count, 0 );
2740+
2741+ // Verify Table1 exists in partition_stats
2742+ auto table1Count = GetRowCount (client, " /Root/.sys/partition_stats" , " Path = '/Root/Table1'" );
2743+ UNIT_ASSERT_VALUES_EQUAL (table1Count, 1 );
2744+ }
2745+
27412746 Y_UNIT_TEST (PartitionStatsFields) {
27422747 auto nowUs = TInstant::Now ().MicroSeconds ();
27432748
0 commit comments