1
1
#include " basic_example.h"
2
2
3
3
#include < src/util/folder/pathsplit.h>
4
- #include < include/ ydb-cpp-sdk/json_value/ydb_json_value.h>
4
+ #include < ydb-cpp-sdk/json_value/ydb_json_value.h>
5
5
6
6
#include < format>
7
7
@@ -14,11 +14,6 @@ void ThrowOnError(const TStatus& status) {
14
14
}
15
15
}
16
16
17
- void PrintStatus (const TStatus& status) {
18
- std::cerr << " Status: " << ToString (status.GetStatus ()) << std::endl;
19
- status.GetIssues ().PrintTo (std::cerr);
20
- }
21
-
22
17
static std::string JoinPath (const std::string& basePath, const std::string& path) {
23
18
if (basePath.empty ()) {
24
19
return path;
@@ -74,25 +69,6 @@ void CreateTables(TTableClient client, const std::string& path) {
74
69
}));
75
70
}
76
71
77
- // ! Describe existing table.
78
- void DescribeTable (TTableClient client, const std::string& path, const std::string& name) {
79
- std::optional<TTableDescription> desc;
80
- std::string result;
81
- ThrowOnError (client.RetryOperationSync ([path, name, &desc](TSession session) {
82
- auto result = session.DescribeTable (JoinPath (path, name)).GetValueSync ();
83
-
84
- if (result.IsSuccess ()) {
85
- desc = result.GetTableDescription ();
86
- }
87
- return result;
88
- }));
89
-
90
- std::cout << std::format (" > Describe table: {}\n " , name);
91
- for (auto & column : desc->GetColumns ()) {
92
- std::cout << std::format (" Column, name: {}, type: {}\n " , column.Name , FormatType (column.Type ));
93
- }
94
- }
95
-
96
72
// /////////////////////////////////////////////////////////////////////////////
97
73
98
74
// ! Fills sample tables with data in single parameterized data query.
@@ -430,13 +406,6 @@ std::string SelectSimple(TTableClient client, const std::string& path) {
430
406
ThrowOnError (client.RetryOperationSync ([path, &resultSet](TSession session) {
431
407
return SelectSimpleTransaction (session, path, resultSet);
432
408
}));
433
- TResultSetParser parser (*resultSet);
434
- if (parser.TryNextRow ()) {
435
- std::cout << std::format (" > SelectSimple:\n Series, Id: {}, Title: {}, Release date: {}\n "
436
- , ToString (parser.ColumnParser (" series_id" ).GetOptionalUint64 ())
437
- , ToString (parser.ColumnParser (" title" ).GetOptionalUtf8 ())
438
- , ToString (parser.ColumnParser (" release_date" ).GetOptionalString ()));
439
- }
440
409
return FormatResultSetJson (resultSet.value (), EBinaryStringEncoding::Unicode);
441
410
}
442
411
@@ -452,13 +421,6 @@ std::string SelectWithParams(TTableClient client, const std::string& path) {
452
421
ThrowOnError (client.RetryOperationSync ([path, &resultSet](TSession session) {
453
422
return SelectWithParamsTransaction (session, path, 2 , 3 , resultSet);
454
423
}));
455
-
456
- TResultSetParser parser (*resultSet);
457
- if (parser.TryNextRow ()) {
458
- std::cout << std::format (" > SelectWithParams:\n Season, Title: {}, Series title: {}\n "
459
- , ToString (parser.ColumnParser (" season_title" ).GetOptionalUtf8 ())
460
- , ToString (parser.ColumnParser (" series_title" ).GetOptionalUtf8 ()));
461
- }
462
424
return FormatResultSetJson (resultSet.value (), EBinaryStringEncoding::Unicode);
463
425
}
464
426
@@ -467,15 +429,6 @@ std::string PreparedSelect(TTableClient client, const std::string& path, ui32 se
467
429
ThrowOnError (client.RetryOperationSync ([path, seriesId, seasonId, episodeId, &resultSet](TSession session) {
468
430
return PreparedSelectTransaction (session, path, seriesId, seasonId, episodeId, resultSet);
469
431
}));
470
-
471
- TResultSetParser parser (*resultSet);
472
- if (parser.TryNextRow ()) {
473
- auto airDate = TInstant::Days (*parser.ColumnParser (" air_date" ).GetOptionalUint64 ());
474
- std::cout << std::format (" > PreparedSelect:\n Episode {}, Title: {}, Air date: {}\n "
475
- , ToString (parser.ColumnParser (" episode_id" ).GetOptionalUint64 ())
476
- , ToString (parser.ColumnParser (" title" ).GetOptionalUtf8 ())
477
- , airDate.FormatLocalTime (" %a %b %d, %Y" ));
478
- }
479
432
return FormatResultSetJson (resultSet.value (), EBinaryStringEncoding::Unicode);
480
433
}
481
434
@@ -484,17 +437,6 @@ std::string MultiStep(TTableClient client, const std::string& path) {
484
437
ThrowOnError (client.RetryOperationSync ([path, &resultSet](TSession session) {
485
438
return MultiStepTransaction (session, path, 2 , 5 , resultSet);
486
439
}));
487
-
488
- TResultSetParser parser (*resultSet);
489
- std::cout << " > MultiStep:\n " ;
490
- while (parser.TryNextRow ()) {
491
- auto airDate = TInstant::Days (*parser.ColumnParser (" air_date" ).GetOptionalUint64 ());
492
- std::cout << std::format (" Episode {}, Season: {}, Title: {}, Air date: {}\n "
493
- , ToString (parser.ColumnParser (" episode_id" ).GetOptionalUint64 ())
494
- , ToString (parser.ColumnParser (" season_id" ).GetOptionalUint64 ())
495
- , ToString (parser.ColumnParser (" title" ).GetOptionalUtf8 ())
496
- , airDate.FormatLocalTime (" %a %b %d, %Y" ));
497
- }
498
440
return FormatResultSetJson (resultSet.value (), EBinaryStringEncoding::Unicode);
499
441
}
500
442
@@ -504,7 +446,8 @@ void ExplicitTcl(TTableClient client, const std::string& path) {
504
446
}));
505
447
}
506
448
507
- std::string ScanQuerySelect (TTableClient client, const std::string& path) {
449
+ std::vector<std::string> ScanQuerySelect (TTableClient client, const std::string& path) {
450
+ std::vector<std::string> result;
508
451
auto query = std::format (R"(
509
452
--!syntax_v1
510
453
PRAGMA TablePathPrefix("{}");
@@ -529,11 +472,10 @@ std::string ScanQuerySelect(TTableClient client, const std::string& path) {
529
472
530
473
if (!resultScanQuery.IsSuccess ()) {
531
474
std::cerr << " ScanQuery execution failure: " << resultScanQuery.GetIssues ().ToString () << std::endl;
532
- return " " ;
475
+ return {} ;
533
476
}
534
477
535
478
bool eos = false ;
536
- std::cout << " > ScanQuerySelect:\n " ;
537
479
538
480
while (!eos) {
539
481
auto streamPart = resultScanQuery.ReadNext ().ExtractValueSync ();
@@ -549,17 +491,8 @@ std::string ScanQuerySelect(TTableClient client, const std::string& path) {
549
491
if (streamPart.HasResultSet ()) {
550
492
auto rs = streamPart.ExtractResultSet ();
551
493
auto columns = rs.GetColumnsMeta ();
552
-
553
- TResultSetParser parser (rs);
554
- while (parser.TryNextRow ()) {
555
- std::cout << std::format (" Season, SeriesId: {}, SeasonId: {}, Title: {}, Air date: {}\n "
556
- , ToString (parser.ColumnParser (" series_id" ).GetOptionalUint64 ())
557
- , ToString (parser.ColumnParser (" season_id" ).GetOptionalUint64 ())
558
- , ToString (parser.ColumnParser (" title" ).GetOptionalUtf8 ())
559
- , ToString (parser.ColumnParser (" first_aired" ).GetOptionalString ()));
560
- }
561
- return FormatResultSetJson (rs, EBinaryStringEncoding::Unicode);
494
+ result.push_back (FormatResultSetJson (rs, EBinaryStringEncoding::Unicode));
562
495
}
563
496
}
564
- return " " ;
497
+ return result ;
565
498
}
0 commit comments