Skip to content

Commit 3108bec

Browse files
added retry
1 parent 1547afc commit 3108bec

File tree

2 files changed

+58
-51
lines changed

2 files changed

+58
-51
lines changed

tests/integration/basic_example_it/basic_example.cpp

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,56 @@ static TStatus ExplicitTclTransaction(TSession session, const std::string& path,
404404
return tx.Commit().GetValueSync();
405405
}
406406

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+
407457
///////////////////////////////////////////////////////////////////////////////
408458

409459
std::string SelectSimple(TTableClient client, const std::string& path) {
@@ -452,53 +502,11 @@ void ExplicitTcl(TTableClient client, const std::string& path) {
452502
}
453503

454504
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;
504512
}

tests/integration/basic_example_it/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ TEST(Integration, BasicExample) {
7070
ASSERT_EQ(resultScanQuerySelect, expectedResultScanQuerySelect);
7171
}
7272
catch (const TYdbErrorException& e) {
73-
std::cerr << "Execution failed due to fatal error:" << std::endl;
7473
driver.Stop(true);
75-
FAIL();
74+
FAIL() << "Execution failed due to fatal error:\nStatus: " << ToString(e.Status.GetStatus()) << std::endl << e.Status.GetIssues().ToString();
7675
}
7776

7877
driver.Stop(true);

0 commit comments

Comments
 (0)