Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shnikd committed Dec 12, 2024
1 parent 4e106ad commit 2ce9291
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ydb/public/lib/ydb_cli/commands/ydb_sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <ydb/public/lib/ydb_cli/common/query_stats.h>
#include <ydb/public/lib/ydb_cli/common/waiting_bar.h>
#include <ydb/public/sdk/cpp/client/ydb_proto/accessor.h>
#include <util/generic/guid.h>
#include <util/generic/queue.h>
#include <google/protobuf/text_format.h>

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

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

if (CollectFullDiagnostics) {
settings.CollectFullDiagnostics(true);
}

if (!Parameters.empty() || InputParamStream) {
// Execute query with parameters
THolder<TParamsBuilder> paramBuilder;
Expand Down Expand Up @@ -183,6 +190,7 @@ int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
TMaybe<TString> stats;
TMaybe<TString> plan;
TMaybe<TString> ast;
TString diagnostics;
{
TResultSetPrinter printer(OutputFormat, &IsInterrupted);

Expand All @@ -205,6 +213,8 @@ int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
plan = queryStats.GetPlan();
}
}

diagnostics = streamPart.GetDiagnostics();
}
} // TResultSetPrinter destructor should be called before printing stats

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

if (CollectFullDiagnostics) {
TFileOutput file(TStringBuilder() << "diagnostics_" << TGUID::Create().AsGuidString() << ".txt");
file << diagnostics;
}

if (IsInterrupted()) {
Cerr << "<INTERRUPTED>" << Endl;
return EXIT_FAILURE;
Expand Down
1 change: 1 addition & 0 deletions ydb/public/lib/ydb_cli/commands/ydb_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TCommandSql : public TYdbCommand, public TCommandWithOutput, public TComma
bool ExplainMode = false;
bool ExplainAnalyzeMode = false;
bool ExplainAst = false;
bool CollectDiagnostics = false;
};

}
Expand Down

0 comments on commit 2ce9291

Please sign in to comment.