Skip to content

Commit 1d94190

Browse files
robot-pigletblinkov
authored andcommitted
Intermediate changes
commit_hash:635f3c44553ff6c26f4387533d6260171d23708f
1 parent 9d01d04 commit 1d94190

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

yql/essentials/tools/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ RECURSE(
1111
udf_dep_stub
1212
udf_probe
1313
udf_resolver
14+
yql_complete
1415
yql_facade_run
1516
yql_linter
1617
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
PROGRAM()
2+
3+
PEERDIR(
4+
library/cpp/getopt
5+
yql/essentials/sql/v1/complete
6+
)
7+
8+
SRCS(
9+
yql_complete.cpp
10+
)
11+
12+
END()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <yql/essentials/sql/v1/complete/sql_complete.h>
2+
3+
#include <library/cpp/getopt/last_getopt.h>
4+
#include <util/stream/file.h>
5+
6+
int Run(int argc, char* argv[]) {
7+
NLastGetopt::TOpts opts = NLastGetopt::TOpts::Default();
8+
9+
TString inFileName;
10+
TMaybe<ui64> pos;
11+
opts.AddLongOption('i', "input", "input file").RequiredArgument("input").StoreResult(&inFileName);
12+
opts.AddLongOption('p', "pos", "position").StoreResult(&pos);
13+
opts.SetFreeArgsNum(0);
14+
opts.AddHelpOption();
15+
16+
NLastGetopt::TOptsParseResult res(&opts, argc, argv);
17+
18+
THolder<TUnbufferedFileInput> inFile;
19+
if (!inFileName.empty()) {
20+
inFile.Reset(new TUnbufferedFileInput(inFileName));
21+
}
22+
IInputStream& in = inFile ? *inFile.Get() : Cin;
23+
24+
auto queryString = in.ReadAll();
25+
auto engine = NSQLComplete::MakeSqlCompletionEngine();
26+
NSQLComplete::TCompletionInput input;
27+
input.Text = queryString;
28+
if (pos) {
29+
input.CursorPosition = *pos;
30+
} else {
31+
input.CursorPosition = queryString.size();
32+
}
33+
34+
auto output = engine->Complete(input);
35+
for (const auto& c : output.Candidates) {
36+
Cout << "[" << c.Kind << "] " << c.Content << "\n";
37+
}
38+
39+
return 0;
40+
}
41+
42+
int main(int argc, char* argv[]) {
43+
try {
44+
return Run(argc, argv);
45+
} catch (const yexception& e) {
46+
Cerr << "Caught exception:" << e.what() << Endl;
47+
return 1;
48+
} catch (...) {
49+
Cerr << CurrentExceptionMessage() << Endl;
50+
return 1;
51+
}
52+
return 0;
53+
}

0 commit comments

Comments
 (0)