blob: b3e27cec10f3bad93fa091c00ce2d77774d71f75 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include <yql/essentials/public/purecalc/examples/protobuf_pull_list/main.pb.h>
#include <yql/essentials/public/purecalc/purecalc.h>
#include <yql/essentials/public/purecalc/io_specs/protobuf/spec.h>
#include <yql/essentials/public/purecalc/helpers/stream/stream_from_vector.h>
using namespace NYql::NPureCalc;
using namespace NExampleProtos;
const char* Query = R"(
SELECT
Url,
COUNT(*) AS Hits
FROM
Input
GROUP BY
Url
ORDER BY
Url
)";
THolder<IStream<TInput*>> MakeInput();
int main() {
try {
auto factory = MakeProgramFactory();
auto program = factory->MakePullListProgram(
TProtobufInputSpec<TInput>(),
TProtobufOutputSpec<TOutput>(),
Query,
ETranslationMode::SQL
);
auto result = program->Apply(MakeInput());
while (auto* message = result->Fetch()) {
Cout << "url = " << message->GetUrl() << Endl;
Cout << "hits = " << message->GetHits() << Endl;
}
} catch (TCompileError& e) {
Cout << e.GetIssues();
}
}
THolder<IStream<TInput*>> MakeInput() {
TVector<TInput> input;
{
auto& message = input.emplace_back();
message.SetUrl("https://yandex.ru/a");
}
{
auto& message = input.emplace_back();
message.SetUrl("https://yandex.ru/a");
}
{
auto& message = input.emplace_back();
message.SetUrl("https://yandex.ru/b");
}
{
auto& message = input.emplace_back();
message.SetUrl("https://yandex.ru/c");
}
{
auto& message = input.emplace_back();
message.SetUrl("https://yandex.ru/b");
}
{
auto& message = input.emplace_back();
message.SetUrl("https://yandex.ru/b");
}
return StreamFromVector(std::move(input));
}
|