Skip to content

Commit 4f19586

Browse files
committed
Fixes
1 parent c80cd1b commit 4f19586

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

@@ -40,6 +41,8 @@ void TCommandSql::Config(TConfig& config) {
4041
config.Opts->AddLongOption("syntax", "Query syntax [yql, pg]")
4142
.RequiredArgument("[String]").DefaultValue("yql").StoreResult(&Syntax)
4243
.Hidden();
44+
config.Opts->AddLongOption("collect-diagnostics", "Collects diagnostics and saves it to file")
45+
.StoreTrue(&CollectFullDiagnostics);
4346

4447
AddOutputFormats(config, {
4548
EDataFormat::Pretty,
@@ -135,6 +138,10 @@ int TCommandSql::RunCommand(TConfig& config) {
135138
throw TMisuseException() << "Unknow syntax option \"" << Syntax << "\"";
136139
}
137140

141+
if (CollectFullDiagnostics) {
142+
settings.CollectFullDiagnostics(true);
143+
}
144+
138145
if (!Parameters.empty() || InputParamStream) {
139146
// Execute query with parameters
140147
THolder<TParamsBuilder> paramBuilder;
@@ -171,6 +178,7 @@ int TCommandSql::RunCommand(TConfig& config) {
171178
int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
172179
TMaybe<TString> stats;
173180
TMaybe<TString> plan;
181+
TString diagnostics;
174182
{
175183
TResultSetPrinter printer(OutputFormat, &IsInterrupted);
176184

@@ -192,6 +200,8 @@ int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
192200
plan = queryStats.GetPlan();
193201
}
194202
}
203+
204+
diagnostics = streamPart.GetDiagnostics();
195205
}
196206
} // TResultSetPrinter destructor should be called before printing stats
197207

@@ -212,6 +222,11 @@ int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
212222
queryPlanPrinter.Print(*plan);
213223
}
214224

225+
if (CollectFullDiagnostics) {
226+
TFileOutput file(TStringBuilder() << "diagnostics_" << TGUID::Create().AsGuidString() << ".txt");
227+
file << diagnostics;
228+
}
229+
215230
if (IsInterrupted()) {
216231
Cerr << "<INTERRUPTED>" << Endl;
217232
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
@@ -33,6 +33,7 @@ class TCommandSql : public TYdbCommand, public TCommandWithOutput, public TComma
3333
TString Syntax;
3434
bool ExplainMode = false;
3535
bool ExplainAnalyzeMode = false;
36+
bool CollectFullDiagnostics = false;
3637
};
3738

3839
}

0 commit comments

Comments
 (0)