@@ -404,6 +404,56 @@ static TStatus ExplicitTclTransaction(TSession session, const std::string& path,
404
404
return tx.Commit ().GetValueSync ();
405
405
}
406
406
407
+ static TStatus ScanQuerySelect (TTableClient client, const std::string& path, std::vector <TResultSet>& vectorResultSet) {
408
+ std::vector<std::string> result;
409
+ auto query = std::format (R"(
410
+ --!syntax_v1
411
+ PRAGMA TablePathPrefix("{}");
412
+
413
+ DECLARE $series AS List<UInt64>;
414
+
415
+ SELECT series_id, season_id, title, CAST(CAST(first_aired AS Date) AS String) AS first_aired
416
+ FROM seasons
417
+ WHERE series_id IN $series
418
+ ORDER BY season_id;
419
+ )" , path);
420
+
421
+ auto parameters = TParamsBuilder ()
422
+ .AddParam (" $series" )
423
+ .BeginList ()
424
+ .AddListItem ().Uint64 (1 )
425
+ .AddListItem ().Uint64 (10 )
426
+ .EndList ().Build ()
427
+ .Build ();
428
+
429
+ // Executes scan query
430
+ auto resultScanQuery = client.StreamExecuteScanQuery (query, parameters).GetValueSync ();
431
+
432
+ if (!resultScanQuery.IsSuccess ()) {
433
+ return resultScanQuery;
434
+ }
435
+
436
+ bool eos = false ;
437
+
438
+ while (!eos) {
439
+ auto streamPart = resultScanQuery.ReadNext ().ExtractValueSync ();
440
+
441
+ if (!streamPart.IsSuccess ()) {
442
+ eos = true ;
443
+ if (!streamPart.EOS ()) {
444
+ std::cerr << " ScanQuery execution failure: " << streamPart.GetIssues ().ToString () << std::endl;
445
+ }
446
+ continue ;
447
+ }
448
+
449
+ if (streamPart.HasResultSet ()) {
450
+ auto rs = streamPart.ExtractResultSet ();
451
+ vectorResultSet.push_back (rs);
452
+ }
453
+ }
454
+ return resultScanQuery;
455
+ }
456
+
407
457
// /////////////////////////////////////////////////////////////////////////////
408
458
409
459
std::string SelectSimple (TTableClient client, const std::string& path) {
@@ -452,53 +502,11 @@ void ExplicitTcl(TTableClient client, const std::string& path) {
452
502
}
453
503
454
504
std::vector<std::string> ScanQuerySelect (TTableClient client, const std::string& path) {
455
- std::vector<std::string> result;
456
- auto query = std::format (R"(
457
- --!syntax_v1
458
- PRAGMA TablePathPrefix("{}");
459
-
460
- DECLARE $series AS List<UInt64>;
461
-
462
- SELECT series_id, season_id, title, CAST(CAST(first_aired AS Date) AS String) AS first_aired
463
- FROM seasons
464
- WHERE series_id IN $series
465
- ORDER BY season_id;
466
- )" , path);
467
-
468
- auto parameters = TParamsBuilder ()
469
- .AddParam (" $series" )
470
- .BeginList ()
471
- .AddListItem ().Uint64 (1 )
472
- .AddListItem ().Uint64 (10 )
473
- .EndList ().Build ()
474
- .Build ();
475
-
476
- // Executes scan query
477
- auto resultScanQuery = client.StreamExecuteScanQuery (query, parameters).GetValueSync ();
478
-
479
- if (!resultScanQuery.IsSuccess ()) {
480
- std::cerr << " ScanQuery execution failure: " << resultScanQuery.GetIssues ().ToString () << std::endl;
481
- return {};
482
- }
483
-
484
- bool eos = false ;
485
-
486
- while (!eos) {
487
- auto streamPart = resultScanQuery.ReadNext ().ExtractValueSync ();
488
-
489
- if (!streamPart.IsSuccess ()) {
490
- eos = true ;
491
- if (!streamPart.EOS ()) {
492
- std::cerr << " ScanQuery execution failure: " << streamPart.GetIssues ().ToString () << std::endl;
493
- }
494
- continue ;
495
- }
496
-
497
- if (streamPart.HasResultSet ()) {
498
- auto rs = streamPart.ExtractResultSet ();
499
- auto columns = rs.GetColumnsMeta ();
500
- result.push_back (FormatResultSetJson (rs, EBinaryStringEncoding::Unicode));
501
- }
502
- }
503
- return result;
505
+ std::vector <TResultSet> vectorResultSet;
506
+ ThrowOnError (client.RetryOperationSync ([path, &vectorResultSet](TTableClient& client) {
507
+ return ScanQuerySelect (client, path, vectorResultSet);
508
+ }));
509
+ std::vector <std::string> resultJson (vectorResultSet.size ());
510
+ std::transform (vectorResultSet.begin (), vectorResultSet.end (), resultJson.begin (), [](TResultSet& x){return FormatResultSetJson (x, EBinaryStringEncoding::Unicode);});
511
+ return resultJson;
504
512
}
0 commit comments