Skip to content

Commit 2ce9291

Browse files
committed
Fixes
1 parent 4e106ad commit 2ce9291

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ydb/public/lib/ydb_cli/commands/ydb_sql.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <ydb/public/lib/ydb_cli/common/query_stats.h>
1010
#include <ydb/public/lib/ydb_cli/common/waiting_bar.h>
1111
#include <ydb/public/sdk/cpp/client/ydb_proto/accessor.h>
12+
#include <util/generic/guid.h>
1213
#include <util/generic/queue.h>
1314
#include <google/protobuf/text_format.h>
1415

@@ -43,6 +44,8 @@ void TCommandSql::Config(TConfig& config) {
4344
config.Opts->AddLongOption("syntax", "Query syntax [yql, pg]")
4445
.RequiredArgument("[String]").DefaultValue("yql").StoreResult(&Syntax)
4546
.Hidden();
47+
config.Opts->AddLongOption("collect-diagnostics", "Collects diagnostics and saves it to file")
48+
.StoreTrue(&CollectFullDiagnostics);
4649

4750
AddOutputFormats(config, {
4851
EDataFormat::Pretty,
@@ -146,6 +149,10 @@ int TCommandSql::RunCommand(TConfig& config) {
146149
throw TMisuseException() << "Unknow syntax option \"" << Syntax << "\"";
147150
}
148151

152+
if (CollectFullDiagnostics) {
153+
settings.CollectFullDiagnostics(true);
154+
}
155+
149156
if (!Parameters.empty() || InputParamStream) {
150157
// Execute query with parameters
151158
THolder<TParamsBuilder> paramBuilder;
@@ -183,6 +190,7 @@ int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
183190
TMaybe<TString> stats;
184191
TMaybe<TString> plan;
185192
TMaybe<TString> ast;
193+
TString diagnostics;
186194
{
187195
TResultSetPrinter printer(OutputFormat, &IsInterrupted);
188196

@@ -205,6 +213,8 @@ int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
205213
plan = queryStats.GetPlan();
206214
}
207215
}
216+
217+
diagnostics = streamPart.GetDiagnostics();
208218
}
209219
} // TResultSetPrinter destructor should be called before printing stats
210220

@@ -235,6 +245,11 @@ int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
235245
queryPlanPrinter.Print(*plan);
236246
}
237247

248+
if (CollectFullDiagnostics) {
249+
TFileOutput file(TStringBuilder() << "diagnostics_" << TGUID::Create().AsGuidString() << ".txt");
250+
file << diagnostics;
251+
}
252+
238253
if (IsInterrupted()) {
239254
Cerr << "<INTERRUPTED>" << Endl;
240255
return EXIT_FAILURE;

ydb/public/lib/ydb_cli/commands/ydb_sql.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class TCommandSql : public TYdbCommand, public TCommandWithOutput, public TComma
3434
bool ExplainMode = false;
3535
bool ExplainAnalyzeMode = false;
3636
bool ExplainAst = false;
37+
bool CollectDiagnostics = false;
3738
};
3839

3940
}

0 commit comments

Comments
 (0)