Skip to content

Commit 868a62a

Browse files
authored
[SchemeShard] Add required path creation (#11445)
1 parent 667a30d commit 868a62a

File tree

10 files changed

+705
-260
lines changed

10 files changed

+705
-260
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include <util/stream/file.h>
2+
#include <util/stream/output.h>
3+
#include <util/string/builder.h>
4+
#include <util/system/src_location.h>
5+
#include <ydb/core/protos/flat_scheme_op.pb.h>
6+
#include <google/protobuf/descriptor.pb.h>
7+
8+
#include <jinja2cpp/template_env.h>
9+
#include <jinja2cpp/template.h>
10+
#include <jinja2cpp/value.h>
11+
#include <jinja2cpp/reflected_value.h>
12+
#include <cstdint>
13+
#include <string>
14+
#include <vector>
15+
#include <iostream>
16+
17+
std::string replace(
18+
const std::string& str,
19+
const std::string& from,
20+
const std::string& to)
21+
{
22+
std::string result;
23+
24+
size_t pos = str.find(from);
25+
result.append(str, 0, pos);
26+
result.append(to);
27+
result.append(str, pos + from.size(), std::string::npos);
28+
29+
return result;
30+
}
31+
32+
int main(int argc, char** argv) {
33+
if (argc < 3) {
34+
Cerr << "Usage: " << argv[0] << " INPUT OUTPUT ..." << Endl;
35+
return 1;
36+
}
37+
38+
std::vector<std::string> opTypes;
39+
const auto* d = NKikimrSchemeOp::EOperationType_descriptor();
40+
for (int i = 0; i < d->value_count(); ++i) {
41+
const auto* v = d->value(i);
42+
if (v) {
43+
auto name = v->full_name();
44+
name = replace(name, ".", "::");
45+
opTypes.emplace_back(name);
46+
}
47+
}
48+
49+
jinja2::TemplateEnv env;
50+
env.AddGlobal("generator", jinja2::Reflect(std::string(__SOURCE_FILE__)));
51+
env.AddGlobal("opTypes", jinja2::Reflect(opTypes));
52+
53+
for (int i = 1; i < argc; i += 2) {
54+
if (!(i + 1 < argc)) {
55+
Cerr << "ERROR: missing output for " << argv[i] << Endl;
56+
return 1;
57+
}
58+
59+
jinja2::Template t(&env);
60+
auto loaded = t.Load(TFileInput(argv[i]).ReadAll(), argv[i]);
61+
if (!loaded) {
62+
Cerr << "ERROR: " << loaded.error().ToString() << Endl;
63+
return 1;
64+
}
65+
66+
auto rendered = t.RenderAsString({});
67+
if (!rendered) {
68+
Cerr << "ERROR: " << rendered.error().ToString() << Endl;
69+
return 1;
70+
}
71+
72+
TFileOutput(argv[i + 1]).Write(rendered.value());
73+
Cout << "Generated " << argv[i + 1] << " from " << argv[i] << Endl;
74+
}
75+
76+
return 0;
77+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
PROGRAM()
2+
3+
SRCS(main.cpp)
4+
5+
PEERDIR(
6+
contrib/libs/jinja2cpp
7+
ydb/core/protos
8+
)
9+
10+
END()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Auto-generated by {{ generator }}, do not modify.
2+
#pragma once
3+
4+
#include <ydb/core/tx/schemeshard/generated/traits.h>
5+
6+
namespace NKikimr::NSchemeShard::NGenerated {
7+
8+
template <class TFn>
9+
constexpr auto DispatchOp(const TTxTransaction& tx, TFn fn) {
10+
switch (tx.GetOperationType()) {
11+
{% for opType in opTypes %}
12+
case {{ opType }}:
13+
return fn(TSchemeTxTraits<{{ opType }}>{});
14+
{% endfor %}
15+
default:
16+
return fn(TSchemeTxTraitsFallback{});
17+
}
18+
}
19+
20+
} // namespace NKikimr::NSchemeShard::NGenerated

0 commit comments

Comments
 (0)