aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2025-02-28 20:58:41 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2025-02-28 22:03:06 +0300
commit0047ca5b59e3fe09612d57d79d24b19c05e2a4fe (patch)
tree6687f39f563c281d593e71e17be00ea733e28f94
parent0f9401a62a8e61076cca0a79e2431514fe847894 (diff)
downloadydb-0047ca5b59e3fe09612d57d79d24b19c05e2a4fe.tar.gz
Intermediate changes
commit_hash:635f3c44553ff6c26f4387533d6260171d23708f
-rw-r--r--yql/essentials/tools/ya.make1
-rw-r--r--yql/essentials/tools/yql_complete/ya.make12
-rw-r--r--yql/essentials/tools/yql_complete/yql_complete.cpp53
3 files changed, 66 insertions, 0 deletions
diff --git a/yql/essentials/tools/ya.make b/yql/essentials/tools/ya.make
index becd8907f6..248945e3fb 100644
--- a/yql/essentials/tools/ya.make
+++ b/yql/essentials/tools/ya.make
@@ -11,6 +11,7 @@ RECURSE(
udf_dep_stub
udf_probe
udf_resolver
+ yql_complete
yql_facade_run
yql_linter
)
diff --git a/yql/essentials/tools/yql_complete/ya.make b/yql/essentials/tools/yql_complete/ya.make
new file mode 100644
index 0000000000..627abb2eeb
--- /dev/null
+++ b/yql/essentials/tools/yql_complete/ya.make
@@ -0,0 +1,12 @@
+PROGRAM()
+
+PEERDIR(
+ library/cpp/getopt
+ yql/essentials/sql/v1/complete
+)
+
+SRCS(
+ yql_complete.cpp
+)
+
+END()
diff --git a/yql/essentials/tools/yql_complete/yql_complete.cpp b/yql/essentials/tools/yql_complete/yql_complete.cpp
new file mode 100644
index 0000000000..289573190b
--- /dev/null
+++ b/yql/essentials/tools/yql_complete/yql_complete.cpp
@@ -0,0 +1,53 @@
+#include <yql/essentials/sql/v1/complete/sql_complete.h>
+
+#include <library/cpp/getopt/last_getopt.h>
+#include <util/stream/file.h>
+
+int Run(int argc, char* argv[]) {
+ NLastGetopt::TOpts opts = NLastGetopt::TOpts::Default();
+
+ TString inFileName;
+ TMaybe<ui64> pos;
+ opts.AddLongOption('i', "input", "input file").RequiredArgument("input").StoreResult(&inFileName);
+ opts.AddLongOption('p', "pos", "position").StoreResult(&pos);
+ opts.SetFreeArgsNum(0);
+ opts.AddHelpOption();
+
+ NLastGetopt::TOptsParseResult res(&opts, argc, argv);
+
+ THolder<TUnbufferedFileInput> inFile;
+ if (!inFileName.empty()) {
+ inFile.Reset(new TUnbufferedFileInput(inFileName));
+ }
+ IInputStream& in = inFile ? *inFile.Get() : Cin;
+
+ auto queryString = in.ReadAll();
+ auto engine = NSQLComplete::MakeSqlCompletionEngine();
+ NSQLComplete::TCompletionInput input;
+ input.Text = queryString;
+ if (pos) {
+ input.CursorPosition = *pos;
+ } else {
+ input.CursorPosition = queryString.size();
+ }
+
+ auto output = engine->Complete(input);
+ for (const auto& c : output.Candidates) {
+ Cout << "[" << c.Kind << "] " << c.Content << "\n";
+ }
+
+ return 0;
+}
+
+int main(int argc, char* argv[]) {
+ try {
+ return Run(argc, argv);
+ } catch (const yexception& e) {
+ Cerr << "Caught exception:" << e.what() << Endl;
+ return 1;
+ } catch (...) {
+ Cerr << CurrentExceptionMessage() << Endl;
+ return 1;
+ }
+ return 0;
+}