@@ -103,6 +103,17 @@ void CreateTenantsAndTables(TTestEnv& env, bool extSchemeShard = true, ui64 part
103103 CreateTables (env, partitionCount);
104104}
105105
106+ void FillRootTable (TTestEnv& env, ui16 tableNum = 0 ) {
107+ TTableClient client (env.GetDriver ());
108+ auto session = client.CreateSession ().GetValueSync ().GetSession ();
109+ NKqp::AssertSuccessResult (session.ExecuteDataQuery (Sprintf (R"(
110+ REPLACE INTO `Root/Table%u` (Key, Value) VALUES
111+ (0u, "X"),
112+ (1u, "Y"),
113+ (2u, "Z");
114+ )" , tableNum), TTxControl::BeginTx ().CommitTx ()).GetValueSync ());
115+ }
116+
106117void CreateRootTable (TTestEnv& env, ui64 partitionCount = 1 , bool fillTable = false , ui16 tableNum = 0 ) {
107118 env.GetClient ().CreateTable (" /Root" , Sprintf (R"(
108119 Name: "Table%u"
@@ -112,16 +123,23 @@ void CreateRootTable(TTestEnv& env, ui64 partitionCount = 1, bool fillTable = fa
112123 UniformPartitionsCount: %lu
113124 )" , tableNum, partitionCount));
114125
115- if (fillTable) {
116- TTableClient client (env.GetDriver ());
117- auto session = client.CreateSession ().GetValueSync ().GetSession ();
118- NKqp::AssertSuccessResult (session.ExecuteDataQuery (R"(
119- REPLACE INTO `Root/Table0` (Key, Value) VALUES
120- (0u, "X"),
121- (1u, "Y"),
122- (2u, "Z");
123- )" , TTxControl::BeginTx ().CommitTx ()).GetValueSync ());
124- }
126+ if (fillTable)
127+ FillRootTable (env, tableNum);
128+ }
129+
130+ void CreateRootColumnTable (TTestEnv& env, ui64 partitionCount = 1 , bool fillTable = false , ui16 tableNum = 0 ) {
131+ NQuery::TQueryClient client (env.GetDriver ());
132+ auto result = client.ExecuteQuery (Sprintf (R"(
133+ CREATE TABLE `/Root/Table%u` (
134+ Key Int32 NOT NULL,
135+ Value Utf8,
136+ PRIMARY KEY(Key)
137+ ) WITH (STORE=COLUMN, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = %lu);
138+ )" , tableNum, partitionCount), NQuery::TTxControl::NoTx ()).GetValueSync ();
139+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
140+
141+ if (fillTable)
142+ FillRootTable (env, tableNum);
125143}
126144
127145void BreakLock (TSession& session, const TString& tableName) {
@@ -2767,68 +2785,27 @@ R"(CREATE TABLE `test_show_create` (
27672785 check.Uint64 (1u ); // LastTtlRowsProcessed
27682786 check.Uint64 (1u ); // LastTtlRowsErased
27692787 }
2770-
2771- Y_UNIT_TEST (PartitionStatsAfterRemoveColumnTable) {
2772- TTestEnv env;
2773- NQuery::TQueryClient client (env.GetDriver ());
2774-
2775- {
2776- auto result = client.ExecuteQuery (R"(
2777- CREATE TABLE `/Root/test_table` (
2778- key int not null,
2779- value utf8,
2780- PRIMARY KEY(key)
2781- ) WITH (STORE=COLUMN);
2782- )" , NQuery::TTxControl::NoTx ()).GetValueSync ();
2783-
2784- UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
2785- }
2786-
2787- {
2788- auto result = client.ExecuteQuery (R"(
2789- SELECT Path FROM `/Root/.sys/partition_stats`
2790- GROUP BY Path;
2791- )" , NQuery::TTxControl::NoTx ()).GetValueSync ();
2792- UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
2793- auto parser = result.GetResultSetParser (0 );
2794- bool existsPath = false ;
2795- while (parser.TryNextRow ()) {
2796- auto path = parser.ColumnParser (" Path" ).GetOptionalUtf8 ();
2797- UNIT_ASSERT (path);
2798- if (*path == " /Root/test_table" ) {
2799- existsPath = true ;
2800- break ;
2801- }
2802- }
2803- UNIT_ASSERT_C (existsPath, " Path /Root/test_table not found" );
2804- }
2805-
2806- {
2807- auto result = client.ExecuteQuery (R"(
2808- DROP TABLE `/Root/test_table`
2809- )" , NQuery::TTxControl::NoTx ()).GetValueSync ();
2810-
2811- UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
2812- }
2813-
2814- {
2815- auto result = client.ExecuteQuery (R"(
2816- SELECT Path FROM `/Root/.sys/partition_stats`
2817- GROUP BY Path;
2818- )" , NQuery::TTxControl::NoTx ()).GetValueSync ();
2819- UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
2820- auto parser = result.GetResultSetParser (0 );
2821- bool existsPath = false ;
2822- while (parser.TryNextRow ()) {
2823- auto path = parser.ColumnParser (" Path" ).GetOptionalUtf8 ();
2824- UNIT_ASSERT (path);
2825- if (*path == " /Root/test_table" ) {
2826- existsPath = true ;
2827- break ;
2828- }
2829- }
2830- UNIT_ASSERT_C (!existsPath, " Path /Root/test_table found" );
2831- }
2788+
2789+ Y_UNIT_TEST_TWIN (PartitionStatsAfterDropTable, UseColumnTable) {
2790+ TTestEnv env ({.DataShardStatsReportIntervalSeconds = 0 });
2791+ if (UseColumnTable)
2792+ CreateRootColumnTable (env);
2793+ else
2794+ CreateRootTable (env);
2795+
2796+ TTableClient client (env.GetDriver ());
2797+
2798+ WaitForStats (client, " /Root/.sys/partition_stats" , " Path = '/Root/Table0'" );
2799+
2800+ auto session = client.CreateSession ().GetValueSync ().GetSession ();
2801+ auto result = session.ExecuteSchemeQuery (R"(
2802+ DROP TABLE `Root/Table0`;
2803+ )" ).GetValueSync ();
2804+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
2805+
2806+ // Verify Table0 is removed from partition_stats
2807+ auto table0Count = GetRowCount (client, " /Root/.sys/partition_stats" , " Path = '/Root/Table0'" );
2808+ UNIT_ASSERT_VALUES_EQUAL (table0Count, 0 );
28322809 }
28332810
28342811 Y_UNIT_TEST (PartitionStatsLocksFields) {
@@ -2859,6 +2836,34 @@ R"(CREATE TABLE `test_show_create` (
28592836 check.Uint64 (1 ); // LocksBroken
28602837 }
28612838
2839+ Y_UNIT_TEST_TWIN (PartitionStatsAfterRenameTable, UseColumnTable) {
2840+ TTestEnv env ({.DataShardStatsReportIntervalSeconds = 0 });
2841+ if (UseColumnTable)
2842+ CreateRootColumnTable (env);
2843+ else
2844+ CreateRootTable (env);
2845+
2846+ TTableClient client (env.GetDriver ());
2847+ auto session = client.CreateSession ().GetValueSync ().GetSession ();
2848+
2849+ WaitForStats (client, " /Root/.sys/partition_stats" , " Path = '/Root/Table0'" );
2850+
2851+ auto result = session.ExecuteSchemeQuery (R"(
2852+ ALTER TABLE `Root/Table0` RENAME TO `Root/Table1`;
2853+ )" ).GetValueSync ();
2854+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
2855+
2856+ WaitForStats (client, " /Root/.sys/partition_stats" , " Path = '/Root/Table1'" );
2857+
2858+ // Verify Table0 is no longer in partition_stats
2859+ auto table0Count = GetRowCount (client, " /Root/.sys/partition_stats" , " Path = '/Root/Table0'" );
2860+ UNIT_ASSERT_VALUES_EQUAL (table0Count, 0 );
2861+
2862+ // Verify Table1 exists in partition_stats
2863+ auto table1Count = GetRowCount (client, " /Root/.sys/partition_stats" , " Path = '/Root/Table1'" );
2864+ UNIT_ASSERT_VALUES_EQUAL (table1Count, 1 );
2865+ }
2866+
28622867 Y_UNIT_TEST (PartitionStatsFields) {
28632868 auto nowUs = TInstant::Now ().MicroSeconds ();
28642869
0 commit comments