Skip to content

Commit

Permalink
Truncate query results output in benchmarks (#12263)
Browse files Browse the repository at this point in the history
  • Loading branch information
iddqdex authored Dec 3, 2024
1 parent 2d13859 commit e0f8546
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions ydb/apps/ydb/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Truncate query results output in benchmarks

## 2.17.0 ##

Expand Down
7 changes: 4 additions & 3 deletions ydb/public/lib/ydb_cli/commands/ydb_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ bool TWorkloadCommandBenchmark::RunBench(TClient& client, NYdbWorkload::IWorkloa
++successIteration;
if (successIteration == 1) {
outFStream << queryN << ": " << Endl;
PrintResult(res, outFStream);
PrintResult(res, outFStream, qInfo.ExpectedResult);
}
const auto resHash = res.CalcHash();
if ((!prevResult || *prevResult != resHash) && !res.IsExpected(qInfo.ExpectedResult)) {
Expand All @@ -376,7 +376,7 @@ bool TWorkloadCommandBenchmark::RunBench(TClient& client, NYdbWorkload::IWorkloa
query << Endl << Endl <<
"UNEXPECTED DIFF: " << Endl
<< "RESULT: " << Endl;
PrintResult(res, outFStream);
PrintResult(res, outFStream, qInfo.ExpectedResult);
outFStream << Endl
<< "EXPECTATION: " << Endl << qInfo.ExpectedResult << Endl;
prevResult = resHash;
Expand Down Expand Up @@ -459,9 +459,10 @@ bool TWorkloadCommandBenchmark::RunBench(TClient& client, NYdbWorkload::IWorkloa
return !someFailQueries;
}

void TWorkloadCommandBenchmark::PrintResult(const BenchmarkUtils::TQueryBenchmarkResult& res, IOutputStream& out) const {
void TWorkloadCommandBenchmark::PrintResult(const BenchmarkUtils::TQueryBenchmarkResult& res, IOutputStream& out, const std::string& expected) const {
TResultSetPrinter printer(TResultSetPrinter::TSettings()
.SetOutput(&out)
.SetMaxRowsCount(std::max(StringSplitter(expected.c_str()).Split('\n').Count(), (size_t)100))
.SetFormat(EDataFormat::Pretty).SetMaxWidth(120)
);
for (const auto& [i, rr]: res.GetRawResults()) {
Expand Down
2 changes: 1 addition & 1 deletion ydb/public/lib/ydb_cli/commands/ydb_benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TWorkloadCommandBenchmark final: public TWorkloadCommandBase {
template <typename TClient>
bool RunBench(TClient& client, NYdbWorkload::IWorkloadQueryGenerator& workloadGen);
void SavePlans(const BenchmarkUtils::TQueryBenchmarkResult& res, ui32 queryNum, const TStringBuf name) const;
void PrintResult(const BenchmarkUtils::TQueryBenchmarkResult& res, IOutputStream& out) const;
void PrintResult(const BenchmarkUtils::TQueryBenchmarkResult& res, IOutputStream& out, const std::string& expected) const;
BenchmarkUtils::TQueryBenchmarkDeadline GetDeadline() const;

private:
Expand Down
19 changes: 15 additions & 4 deletions ydb/public/lib/ydb_cli/common/format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,12 @@ void TResultSetPrinter::PrintPretty(const TResultSet& resultSet) {
tableConfig.WithoutHeader();
}
TPrettyTable table(columnNames, tableConfig);

while (parser.TryNextRow()) {
for (size_t printed = 0; parser.TryNextRow(); ++printed) {
auto& row = table.AddRow();
if (Settings.GetMaxRowsCount() && printed >= Settings.GetMaxRowsCount()) {
row.FreeText(TStringBuilder() << "And " << (resultSet.RowsCount() - printed) << " more lines, total " << resultSet.RowsCount());
break;
}
for (ui32 i = 0; i < columns.size(); ++i) {
row.Column(i, FormatValueJson(parser.GetValue(i), EBinaryStringEncoding::Unicode));
}
Expand All @@ -782,13 +785,17 @@ void TResultSetPrinter::PrintJsonArray(const TResultSet& resultSet, EBinaryStrin

TResultSetParser parser(resultSet);
bool firstRow = true;
while (parser.TryNextRow()) {
for (size_t printed = 0; parser.TryNextRow(); ++printed) {
if (!firstRow || !FirstPart) {
EndLineBeforeNextResult();
}
if (firstRow) {
firstRow = false;
}
if (Settings.GetMaxRowsCount() && printed >= Settings.GetMaxRowsCount()) {
*Settings.GetOutput() << "And " << (resultSet.RowsCount() - printed) << " more lines, total " << resultSet.RowsCount();
break;
}
NJsonWriter::TBuf writer(NJsonWriter::HEM_UNSAFE, Settings.GetOutput());
FormatResultRowJson(parser, columns, writer, encoding);
}
Expand All @@ -806,7 +813,11 @@ void TResultSetPrinter::PrintCsv(const TResultSet& resultSet, const char* delim)
}
*Settings.GetOutput() << Endl;
}
while (parser.TryNextRow()) {
for (size_t printed = 0; parser.TryNextRow(); ++printed) {
if (Settings.GetMaxRowsCount() && printed >= Settings.GetMaxRowsCount()) {
*Settings.GetOutput() << "And " << (resultSet.RowsCount() - printed) << " more lines, total " << resultSet.RowsCount() << Endl;
break;
}
for (ui32 i = 0; i < columns.size(); ++i) {
*Settings.GetOutput() << FormatValueJson(parser.GetValue(i), EBinaryStringEncoding::Unicode);
if (i < columns.size() - 1) {
Expand Down
1 change: 1 addition & 0 deletions ydb/public/lib/ydb_cli/common/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class TResultSetPrinter {
YDB_ACCESSOR(EDataFormat, Format, EDataFormat::Pretty);
YDB_ACCESSOR(std::function<bool()>, IsInterrupted, []() { return false; });
YDB_ACCESSOR(size_t, MaxWidth, 0);
YDB_ACCESSOR(size_t, MaxRowsCount, 0);
YDB_FLAG_ACCESSOR(CsvWithHeader, false);
YDB_READONLY(IOutputStream*, Output, &Cout);
public:
Expand Down

0 comments on commit e0f8546

Please sign in to comment.