Skip to content

Commit ec42e43

Browse files
authored
Interactive cli over query service and some minor improvements (#8665)
1 parent a418278 commit ec42e43

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

ydb/public/lib/ydb_cli/commands/interactive/interactive_cli.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <ydb/public/lib/ydb_cli/commands/interactive/line_reader.h>
1010
#include <ydb/public/lib/ydb_cli/commands/ydb_service_scheme.h>
1111
#include <ydb/public/lib/ydb_cli/commands/ydb_service_table.h>
12-
#include <ydb/public/lib/ydb_cli/commands/ydb_yql.h>
12+
#include <ydb/public/lib/ydb_cli/commands/ydb_sql.h>
1313

1414
namespace NYdb {
1515
namespace NConsoleClient {
@@ -179,9 +179,19 @@ void TInteractiveCLI::Run() {
179179
continue;
180180
}
181181

182+
TString query = TString(line);
183+
TString queryLowerCase = to_lower(query);
184+
if (queryLowerCase == "quit" || queryLowerCase == "exit") {
185+
std::cout << "Bye" << std::endl;
186+
return;
187+
}
188+
182189
TString queryStatsMode(NTable::QueryStatsModeToString(interactiveCLIState.CollectStatsMode));
183-
TCommandYql yqlCommand(TString(line), queryStatsMode);
184-
yqlCommand.Run(Config);
190+
TCommandSql sqlCommand;
191+
sqlCommand.SetScript(std::move(query));
192+
sqlCommand.SetCollectStatsMode(std::move(queryStatsMode));
193+
sqlCommand.SetSyntax("yql");
194+
sqlCommand.Run(Config);
185195
} catch (TYdbErrorException &error) {
186196
Cerr << error;
187197
} catch (yexception & error) {
@@ -191,7 +201,7 @@ void TInteractiveCLI::Run() {
191201
}
192202
}
193203

194-
std::cout << "Bye" << '\n';
204+
std::cout << std::endl << "Bye" << std::endl;
195205
}
196206

197207
}

ydb/public/lib/ydb_cli/commands/interactive/line_reader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ TLineReader::TLineReader(std::string prompt, std::string historyFilePath, Sugges
9999
Rx.set_word_break_characters(WordBreakCharacters.data());
100100
Rx.bind_key(replxx::Replxx::KEY::control('N'), [&](char32_t code) { return Rx.invoke(replxx::Replxx::ACTION::HISTORY_NEXT, code); });
101101
Rx.bind_key(replxx::Replxx::KEY::control('P'), [&](char32_t code) { return Rx.invoke(replxx::Replxx::ACTION::HISTORY_PREVIOUS, code); });
102+
Rx.bind_key(replxx::Replxx::KEY::control('D'), [](char32_t) { return replxx::Replxx::ACTION_RESULT::BAIL; });
102103
auto commit_action = [&](char32_t code) {
103104
return Rx.invoke(replxx::Replxx::ACTION::COMMIT_LINE, code);
104105
};

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ TCommandSql::TCommandSql()
2121
: TYdbCommand("sql", {}, "Execute SQL query")
2222
{}
2323

24-
TCommandSql::TCommandSql(TString query, TString collectStatsMode)
25-
: TYdbCommand("sql", {}, "Execute SQL query")
26-
{
27-
Query = std::move(query);
28-
CollectStatsMode = std::move(collectStatsMode);
29-
}
30-
3124
void TCommandSql::Config(TConfig& config) {
3225
TYdbCommand::Config(config);
3326
config.Opts->AddLongOption('s', "script", "Script (query) text to execute").RequiredArgument("[String]")
@@ -178,5 +171,17 @@ int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
178171
return EXIT_SUCCESS;
179172
}
180173

174+
void TCommandSql::SetScript(TString&& script) {
175+
Query = std::move(script);
176+
}
177+
178+
void TCommandSql::SetCollectStatsMode(TString&& collectStatsMode) {
179+
CollectStatsMode = std::move(collectStatsMode);
180+
}
181+
182+
void TCommandSql::SetSyntax(TString&& syntax) {
183+
Syntax = std::move(syntax);
184+
}
185+
181186
}
182187
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ class TCommandSql : public TYdbCommand, public TCommandWithFormat,
1515
{
1616
public:
1717
TCommandSql();
18-
TCommandSql(TString script, TString collectStatsMode);
1918
virtual void Config(TConfig& config) override;
2019
virtual void Parse(TConfig& config) override;
2120
virtual int Run(TConfig& config) override;
21+
void SetSyntax(TString&& syntax);
22+
void SetCollectStatsMode(TString&& collectStatsMode);
23+
void SetScript(TString&& script);
2224

2325
private:
2426
int RunCommand(TConfig& config);

0 commit comments

Comments
 (0)