@@ -149,7 +149,7 @@ void BreakLock(TSession& session, const TString& tableName) {
149
149
if (yson == " []" ) {
150
150
continue ;
151
151
}
152
-
152
+
153
153
NKqp::CompareYson (R"( [
154
154
[[55u];["Fifty five"]];
155
155
])" , yson);
@@ -167,7 +167,7 @@ void BreakLock(TSession& session, const TString& tableName) {
167
167
{ // tx1: try to commit
168
168
auto result = tx1->Commit ().ExtractValueSync ();
169
169
UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), EStatus::SUCCESS, result.GetIssues ().ToString ());
170
- }
170
+ }
171
171
}
172
172
173
173
void SetupAuthEnvironment (TTestEnv& env) {
@@ -256,16 +256,38 @@ void WaitForStats(TTableClient& client, const TString& tableName, const TString&
256
256
break ;
257
257
Sleep (TDuration::Seconds (5 ));
258
258
}
259
- UNIT_ASSERT_GE (rowCount, 0 );
259
+ UNIT_ASSERT_GE (rowCount, 0 );
260
+ }
261
+
262
+ NQuery::TExecuteQueryResult ExecuteQuery (NQuery::TSession& session, const std::string& query) {
263
+ auto result = session.ExecuteQuery (query, NQuery::TTxControl::NoTx ()).ExtractValueSync ();
264
+ UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), EStatus::SUCCESS, result.GetIssues ().ToString ());
265
+ return result;
266
+ }
267
+
268
+ NKikimrSchemeOp::TPathDescription DescribePath (TTestActorRuntime& runtime, TString&& path) {
269
+ if (!IsStartWithSlash (path)) {
270
+ path = CanonizePath (JoinPath ({" /Root" , path}));
271
+ }
272
+ auto sender = runtime.AllocateEdgeActor ();
273
+ TAutoPtr<IEventHandle> handle;
274
+
275
+ auto request = MakeHolder<TEvTxUserProxy::TEvNavigate>();
276
+ request->Record .MutableDescribePath ()->SetPath (path);
277
+ request->Record .MutableDescribePath ()->MutableOptions ()->SetShowPrivateTable (true );
278
+ request->Record .MutableDescribePath ()->MutableOptions ()->SetReturnBoundaries (true );
279
+ runtime.Send (new IEventHandle (MakeTxProxyID (), sender, request.Release ()));
280
+ return runtime.GrabEdgeEventRethrow <NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult>(handle)->GetRecord ().GetPathDescription ();
260
281
}
261
282
262
- class TShowCreateTableChecker {
283
+ class TShowCreateChecker {
263
284
public:
264
285
265
- explicit TShowCreateTableChecker (TTestEnv& env)
286
+ explicit TShowCreateChecker (TTestEnv& env)
266
287
: Env(env)
288
+ , Runtime(*Env.GetServer().GetRuntime())
267
289
, QueryClient(NQuery::TQueryClient(Env.GetDriver()))
268
- , TableClient(TTableClient(Env.GetDriver() ))
290
+ , Session(QueryClient.GetSession().GetValueSync().GetSession( ))
269
291
{
270
292
CreateTier (" tier1" );
271
293
CreateTier (" tier2" );
@@ -279,7 +301,7 @@ class TShowCreateTableChecker {
279
301
sessionId = session.GetId ();
280
302
}
281
303
282
- CreateTable (session, query);
304
+ ExecuteQuery (session, query);
283
305
auto showCreateTableQuery = ShowCreateTable (session, tableName);
284
306
285
307
if (formatQuery) {
@@ -290,132 +312,106 @@ class TShowCreateTableChecker {
290
312
291
313
DropTable (session, tableName);
292
314
293
- CreateTable (session, showCreateTableQuery);
315
+ ExecuteQuery (session, showCreateTableQuery);
294
316
auto describeResultNew = DescribeTable (tableName, sessionId);
295
317
296
318
DropTable (session, tableName);
297
319
298
- CompareDescriptions (std::move ( describeResultOrig), std::move ( describeResultNew) , showCreateTableQuery);
320
+ CompareDescriptions (describeResultOrig, describeResultNew, showCreateTableQuery);
299
321
}
300
322
301
323
private:
302
324
303
- void CreateTable (NYdb::NQuery::TSession& session, const std::string& query) {
304
- auto result = session.ExecuteQuery (query, NQuery::TTxControl::NoTx ()).ExtractValueSync ();
305
- UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), EStatus::SUCCESS, result.GetIssues ().ToString ());
306
- }
307
-
308
- void CreateTier (const TString& tierName) {
309
- auto session = TableClient.CreateSession ().GetValueSync ().GetSession ();
310
- auto result = session.ExecuteSchemeQuery (R"(
325
+ void CreateTier (const std::string& tierName) {
326
+ ExecuteQuery (Session, std::format (R"(
311
327
UPSERT OBJECT `accessKey` (TYPE SECRET) WITH (value = `secretAccessKey`);
312
328
UPSERT OBJECT `secretKey` (TYPE SECRET) WITH (value = `fakeSecret`);
313
- CREATE EXTERNAL DATA SOURCE `)" + tierName + R"( ` WITH (
314
- SOURCE_TYPE="ObjectStorage",
315
- LOCATION="http://fake.fake/olap-)" + tierName + R"( ",
316
- AUTH_METHOD="AWS",
317
- AWS_ACCESS_KEY_ID_SECRET_NAME="accessKey",
318
- AWS_SECRET_ACCESS_KEY_SECRET_NAME="secretKey",
319
- AWS_REGION="ru-central1"
320
- );
321
- )" ).GetValueSync ();
322
- UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), EStatus::SUCCESS, result.GetIssues ().ToString ());
329
+ CREATE EXTERNAL DATA SOURCE `{}` WITH (
330
+ SOURCE_TYPE = "ObjectStorage",
331
+ LOCATION = "http://fake.fake/olap-{}",
332
+ AUTH_METHOD = "AWS",
333
+ AWS_ACCESS_KEY_ID_SECRET_NAME = "accessKey",
334
+ AWS_SECRET_ACCESS_KEY_SECRET_NAME = "secretKey",
335
+ AWS_REGION = "ru-central1"
336
+ );
337
+ )" , tierName, tierName));
323
338
}
324
339
325
- Ydb::Table::CreateTableRequest DescribeTable (const std::string& tableName,
326
- std::optional<TString> sessionId = std::nullopt) {
327
-
328
- auto describeTable = [this ](const TString& path) {
329
- auto & runtime = *(this ->Env .GetServer ().GetRuntime ());
330
- auto sender = runtime.AllocateEdgeActor ();
331
- TAutoPtr<IEventHandle> handle;
340
+ Ydb::Table::CreateTableRequest DescribeTable (const std::string& tableName, std::optional<TString> sessionId = std::nullopt) {
332
341
333
- auto request = MakeHolder<TEvTxUserProxy::TEvNavigate>();
334
- request->Record .MutableDescribePath ()->SetPath (path);
335
- request->Record .MutableDescribePath ()->MutableOptions ()->SetShowPrivateTable (true );
336
- request->Record .MutableDescribePath ()->MutableOptions ()->SetReturnBoundaries (true );
337
- runtime.Send (new IEventHandle (MakeTxProxyID (), sender, request.Release ()));
338
- auto reply = runtime.GrabEdgeEventRethrow <NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult>(handle);
339
-
340
- if (reply->GetRecord ().GetPathDescription ().HasColumnTableDescription ()) {
341
- const auto & tableDescription = reply->GetRecord ().GetPathDescription ().GetColumnTableDescription ();
342
+ auto describeTable = [this ](TString&& path) {
343
+ auto pathDescription = DescribePath (Runtime, std::move (path));
342
344
345
+ if (pathDescription.HasColumnTableDescription ()) {
346
+ const auto & tableDescription = pathDescription.GetColumnTableDescription ();
343
347
return *GetCreateTableRequest (tableDescription);
344
348
}
345
349
346
- if (!reply-> GetRecord (). GetPathDescription () .HasTable ()) {
347
- UNIT_ASSERT_C ( false , " Invalid path type" );
350
+ if (!pathDescription .HasTable ()) {
351
+ UNIT_FAIL ( " Invalid path type: " << pathDescription. GetSelf (). GetPathType () );
348
352
}
349
353
350
- const auto & tableDescription = reply->GetRecord ().GetPathDescription ().GetTable ();
351
-
354
+ const auto & tableDescription = pathDescription.GetTable ();
352
355
return *GetCreateTableRequest (tableDescription);
353
356
};
354
357
355
- TString tablePath = TString (tableName);
358
+ auto tablePath = TString (tableName);
356
359
if (!IsStartWithSlash (tablePath)) {
357
360
tablePath = CanonizePath (JoinPath ({" /Root" , tablePath}));
358
361
}
359
362
if (sessionId.has_value ()) {
360
363
auto pos = sessionId.value ().find (" &id=" );
361
364
tablePath = NKqp::GetTempTablePath (" Root" , sessionId.value ().substr (pos + 4 ), tablePath);
362
365
}
363
- auto tableDesc = describeTable (tablePath);
366
+ auto tableDesc = describeTable (std::move ( tablePath) );
364
367
365
368
return tableDesc;
366
369
}
367
370
368
- std::string ShowCreateTable (NYdb::NQuery::TSession& session, const std::string& tableName) {
369
- auto result = session.ExecuteQuery (TStringBuilder () << R"(
370
- SHOW CREATE TABLE `)" << tableName << R"( `;
371
- )" , NQuery::TTxControl::NoTx ()).ExtractValueSync ();
372
- UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), EStatus::SUCCESS, result.GetIssues ().ToString ());
371
+ std::string ShowCreate (NQuery::TSession& session, std::string_view type, const std::string& path) {
372
+ const auto result = ExecuteQuery (session, std::format (" SHOW CREATE {} `{}`;" , type, path));
373
373
374
374
UNIT_ASSERT_VALUES_EQUAL (result.GetResultSets ().size (), 1 );
375
375
auto resultSet = result.GetResultSet (0 );
376
376
auto columnsMeta = resultSet.GetColumnsMeta ();
377
- UNIT_ASSERT (columnsMeta.size () == 3 );
377
+ UNIT_ASSERT_VALUES_EQUAL (columnsMeta.size (), 3 );
378
378
379
- NYdb:: TResultSetParser parser (resultSet);
379
+ TResultSetParser parser (resultSet);
380
380
UNIT_ASSERT (parser.TryNextRow ());
381
381
382
- TString tablePath = TString (tableName);
383
-
384
382
TString statement = " " ;
385
383
386
- for (size_t i = 0 ; i < columnsMeta.size (); i++) {
387
- const auto & column = columnsMeta[i];
384
+ for (const auto & column : columnsMeta) {
385
+ TValueParser parserValue (parser.GetValue (column.Name ));
386
+ parserValue.OpenOptional ();
387
+ const auto & value = parserValue.GetUtf8 ();
388
+
388
389
if (column.Name == " Path" ) {
389
- TValueParser parserValue (parser.GetValue (i));
390
- parserValue.OpenOptional ();
391
- UNIT_ASSERT_VALUES_EQUAL (parserValue.GetUtf8 (), std::string (tablePath));
392
- continue ;
390
+ UNIT_ASSERT_VALUES_EQUAL (value, path);
393
391
} else if (column.Name == " PathType" ) {
394
- TValueParser parserValue (parser.GetValue (i));
395
- parserValue.OpenOptional ();
396
- UNIT_ASSERT_VALUES_EQUAL (parserValue.GetUtf8 (), " Table" );
397
- continue ;
392
+ auto actualType = to_upper (TString (value));
393
+ UNIT_ASSERT_VALUES_EQUAL (actualType, type);
398
394
} else if (column.Name == " Statement" ) {
399
- TValueParser parserValue (parser.GetValue (i));
400
- parserValue.OpenOptional ();
401
- statement = parserValue.GetUtf8 ();
395
+ statement = value;
402
396
} else {
403
- UNIT_ASSERT_C ( false , " Invalid column name" );
397
+ UNIT_FAIL ( " Invalid column name: " << column. Name );
404
398
}
405
399
}
406
400
UNIT_ASSERT (statement);
407
401
408
402
return statement;
409
403
}
410
404
411
- void DropTable (NYdb::NQuery::TSession& session, const std::string& tableName) {
412
- auto result = session.ExecuteQuery (TStringBuilder () << R"(
413
- DROP TABLE `)" << tableName << R"( `;
414
- )" , NQuery::TTxControl::NoTx ()).ExtractValueSync ();
415
- UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), EStatus::SUCCESS, result.GetIssues ().ToString ());
405
+ std::string ShowCreateTable (NQuery::TSession& session, const std::string& tableName) {
406
+ return ShowCreate (session, " TABLE" , tableName);
407
+ }
408
+
409
+ void DropTable (NQuery::TSession& session, const std::string& tableName) {
410
+ ExecuteQuery (session, std::format (" DROP TABLE `{}`;" , tableName));
416
411
}
417
412
418
- void CompareDescriptions (Ydb::Table::CreateTableRequest describeResultOrig, Ydb::Table::CreateTableRequest describeResultNew, const std::string& showCreateTableQuery) {
413
+ template <typename TProtobufDescription>
414
+ void CompareDescriptions (const TProtobufDescription& describeResultOrig, const TProtobufDescription& describeResultNew, const std::string& showCreateTableQuery) {
419
415
TString first;
420
416
::google::protobuf::TextFormat::PrintToString (describeResultOrig, &first);
421
417
TString second;
@@ -470,8 +466,9 @@ class TShowCreateTableChecker {
470
466
471
467
private:
472
468
TTestEnv& Env;
469
+ TTestActorRuntime& Runtime;
473
470
NQuery::TQueryClient QueryClient;
474
- TTableClient TableClient ;
471
+ NQuery::TSession Session ;
475
472
};
476
473
477
474
class TYsonFieldChecker {
@@ -705,7 +702,7 @@ Y_UNIT_TEST_SUITE(SystemView) {
705
702
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::KQP_YQL, NActors::NLog::PRI_TRACE);
706
703
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::SYSTEM_VIEWS, NActors::NLog::PRI_DEBUG);
707
704
708
- TShowCreateTableChecker checker (env);
705
+ TShowCreateChecker checker (env);
709
706
710
707
checker.CheckShowCreateTable (
711
708
R"( CREATE TABLE test_show_create (
@@ -899,7 +896,7 @@ R"(CREATE TABLE `test_show_create` (
899
896
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::KQP_YQL, NActors::NLog::PRI_TRACE);
900
897
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::SYSTEM_VIEWS, NActors::NLog::PRI_DEBUG);
901
898
902
- TShowCreateTableChecker checker (env);
899
+ TShowCreateChecker checker (env);
903
900
904
901
checker.CheckShowCreateTable (R"(
905
902
CREATE TABLE test_show_create (
@@ -992,7 +989,7 @@ WITH (PARTITION_AT_KEYS = ((FALSE), (FALSE, 1, 2), (TRUE, 1, 1, 1, 1, 'str'), (T
992
989
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::KQP_YQL, NActors::NLog::PRI_TRACE);
993
990
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::SYSTEM_VIEWS, NActors::NLog::PRI_DEBUG);
994
991
995
- TShowCreateTableChecker checker (env);
992
+ TShowCreateChecker checker (env);
996
993
997
994
checker.CheckShowCreateTable (R"(
998
995
CREATE TABLE test_show_create (
@@ -1029,7 +1026,7 @@ WITH (
1029
1026
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::KQP_YQL, NActors::NLog::PRI_TRACE);
1030
1027
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::SYSTEM_VIEWS, NActors::NLog::PRI_DEBUG);
1031
1028
1032
- TShowCreateTableChecker checker (env);
1029
+ TShowCreateChecker checker (env);
1033
1030
1034
1031
checker.CheckShowCreateTable (R"(
1035
1032
CREATE TABLE test_show_create (
@@ -1093,7 +1090,7 @@ WITH (
1093
1090
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::KQP_YQL, NActors::NLog::PRI_TRACE);
1094
1091
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::SYSTEM_VIEWS, NActors::NLog::PRI_DEBUG);
1095
1092
1096
- TShowCreateTableChecker checker (env);
1093
+ TShowCreateChecker checker (env);
1097
1094
1098
1095
checker.CheckShowCreateTable (R"(
1099
1096
CREATE TABLE test_show_create (
@@ -1117,7 +1114,7 @@ WITH (
1117
1114
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::KQP_YQL, NActors::NLog::PRI_TRACE);
1118
1115
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::SYSTEM_VIEWS, NActors::NLog::PRI_DEBUG);
1119
1116
1120
- TShowCreateTableChecker checker (env);
1117
+ TShowCreateChecker checker (env);
1121
1118
1122
1119
checker.CheckShowCreateTable (R"(
1123
1120
CREATE TABLE test_show_create (
@@ -1158,7 +1155,7 @@ WITH (READ_REPLICAS_SETTINGS = 'ANY_AZ:3');
1158
1155
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::KQP_YQL, NActors::NLog::PRI_TRACE);
1159
1156
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::SYSTEM_VIEWS, NActors::NLog::PRI_DEBUG);
1160
1157
1161
- TShowCreateTableChecker checker (env);
1158
+ TShowCreateChecker checker (env);
1162
1159
1163
1160
checker.CheckShowCreateTable (R"(
1164
1161
CREATE TABLE test_show_create (
@@ -1199,7 +1196,7 @@ WITH (KEY_BLOOM_FILTER = DISABLED);
1199
1196
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::KQP_YQL, NActors::NLog::PRI_TRACE);
1200
1197
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::SYSTEM_VIEWS, NActors::NLog::PRI_DEBUG);
1201
1198
1202
- TShowCreateTableChecker checker (env);
1199
+ TShowCreateChecker checker (env);
1203
1200
1204
1201
checker.CheckShowCreateTable (R"(
1205
1202
CREATE TABLE test_show_create (
@@ -1315,7 +1312,7 @@ WITH (
1315
1312
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::KQP_YQL, NActors::NLog::PRI_TRACE);
1316
1313
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::SYSTEM_VIEWS, NActors::NLog::PRI_DEBUG);
1317
1314
1318
- TShowCreateTableChecker checker (env);
1315
+ TShowCreateChecker checker (env);
1319
1316
1320
1317
checker.CheckShowCreateTable (R"(
1321
1318
CREATE TEMPORARY TABLE test_show_create (
@@ -1341,7 +1338,7 @@ R"(CREATE TEMPORARY TABLE `test_show_create` (
1341
1338
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::KQP_YQL, NActors::NLog::PRI_TRACE);
1342
1339
env.GetServer ().GetRuntime ()->SetLogPriority (NKikimrServices::SYSTEM_VIEWS, NActors::NLog::PRI_DEBUG);
1343
1340
1344
- TShowCreateTableChecker checker (env);
1341
+ TShowCreateChecker checker (env);
1345
1342
1346
1343
checker.CheckShowCreateTable (
1347
1344
R"( CREATE TABLE `/Root/test_show_create` (
@@ -1868,7 +1865,7 @@ WITH (
1868
1865
1869
1866
TTableClient client (env.GetDriver ());
1870
1867
auto session = client.CreateSession ().GetValueSync ().GetSession ();
1871
-
1868
+
1872
1869
BreakLock (session, " /Root/Table0" );
1873
1870
1874
1871
WaitForStats (client, " /Root/.sys/partition_stats" , " LocksBroken != 0" );
@@ -1888,7 +1885,7 @@ WITH (
1888
1885
check.Uint64 (1 ); // LocksAcquired
1889
1886
check.Uint64 (0 ); // LocksWholeShard
1890
1887
check.Uint64 (1 ); // LocksBroken
1891
- }
1888
+ }
1892
1889
1893
1890
Y_UNIT_TEST (PartitionStatsFields) {
1894
1891
NDataShard::gDbStatsReportInterval = TDuration::Seconds (0 );
@@ -2717,7 +2714,7 @@ WITH (
2717
2714
2718
2715
TTableClient client (env.GetDriver ());
2719
2716
auto session = client.CreateSession ().GetValueSync ().GetSession ();
2720
-
2717
+
2721
2718
const TString tableName = " /Root/Tenant1/Table1" ;
2722
2719
const TString viewName = " /Root/Tenant1/.sys/top_partitions_by_tli_one_minute" ;
2723
2720
0 commit comments