Skip to content

Commit 7ec0dac

Browse files
committed
Generate ProtocolToThrift files through make and commit
1 parent 4766404 commit 7ec0dac

28 files changed

+3023
-736
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
presto_thrift.json
2+
presto_protocol-to-thrift-json.json
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
all: ProtocolToThrift.h ProtocolToThrift.cpp
14+
15+
ProtocolToThrift.h: ProtocolToThrift-hpp.mustache presto_protocol-to-thrift-json.json
16+
echo "// DO NOT EDIT : This file is generated by presto_protocol-to-thrift-json.py" > ProtocolToThrift.h
17+
chevron -d presto_protocol-to-thrift-json.json ProtocolToThrift-hpp.mustache >> ProtocolToThrift.h
18+
clang-format -style=file -i ProtocolToThrift.h
19+
20+
ProtocolToThrift.cpp: ProtocolToThrift-cpp.mustache presto_protocol-to-thrift-json.json
21+
echo "// DO NOT EDIT : This file is generated by presto_protocol-to-thrift-json.py" > ProtocolToThrift.cpp
22+
chevron -d presto_protocol-to-thrift-json.json ProtocolToThrift-cpp.mustache >> ProtocolToThrift.cpp
23+
clang-format -style=file -i ProtocolToThrift.cpp
24+
25+
presto_protocol-to-thrift-json.json: presto_protocol-to-thrift-json.py presto_protocol-to-thrift-json.yml presto_thrift.json ../../presto_protocol/core/presto_protocol_core.json
26+
./presto_protocol-to-thrift-json.py presto_thrift.json ../../presto_protocol/core/presto_protocol_core.json | jq . > presto_protocol-to-thrift-json.json
27+
28+
presto_thrift.json: presto_thrift.thrift ./thrift2json.py
29+
./thrift2json.py presto_thrift.thrift | jq . > presto_thrift.json
30+
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
{{! Select all the comment items and expand them here }}
16+
{{#.}}
17+
{{#comment}}
18+
{{comment}}
19+
{{/comment}}
20+
{{/.}}
21+
22+
#include "github/presto-trunk/presto-native-execution/presto_cpp/main/thrift/ProtocolToThrift.h"
23+
24+
namespace facebook::presto::thrift {
25+
26+
// These could be covered by a more general template but this way only
27+
// conversions to supported Thrift data types can be generated.
28+
void toThrift(const std::string& proto, std::string& thrift) {
29+
thrift = proto;
30+
}
31+
void toThrift(const bool& proto, bool& thrift) {
32+
thrift = proto;
33+
}
34+
void toThrift(const int16_t& proto, int16_t& thrift) {
35+
thrift = proto;
36+
}
37+
void toThrift(const int32_t& proto, int32_t& thrift) {
38+
thrift = proto;
39+
}
40+
void toThrift(const int64_t& proto, int64_t& thrift) {
41+
thrift = proto;
42+
}
43+
void toThrift(const double& proto, double& thrift) {
44+
thrift = proto;
45+
}
46+
void toThrift(const facebook::presto::protocol::Duration& duration, double& thrift) {
47+
thrift = duration.getValue(facebook::presto::protocol::TimeUnit::MILLISECONDS);
48+
}
49+
void toThrift(const facebook::presto::protocol::DataSize& dataSize, double& thrift) {
50+
thrift = dataSize.getValue(facebook::presto::protocol::DataUnit::BYTE);
51+
}
52+
53+
template <typename P, typename T>
54+
void toThrift(const std::shared_ptr<P>& proto, std::shared_ptr<T>& thrift) {
55+
if (proto) {
56+
thrift = std::make_shared<T>();
57+
toThrift(*proto, *thrift);
58+
}
59+
}
60+
61+
template <typename P, typename T>
62+
void toThrift(const std::shared_ptr<P>& proto, T& thrift) {
63+
if (proto) {
64+
toThrift(*proto, thrift);
65+
}
66+
}
67+
68+
template <typename V, typename S>
69+
void toThrift(const std::vector<V>& v, std::set<S>& s) {
70+
S toItem;
71+
for (const auto& fromItem : v) {
72+
toThrift(fromItem, toItem);
73+
s.insert(std::move(toItem));
74+
}
75+
}
76+
77+
template <typename P, typename T>
78+
void toThrift(const std::vector<P>& p, std::vector<T>& t) {
79+
t.reserve(p.size());
80+
T toItem;
81+
for (const auto& fromItem : p) {
82+
toThrift(fromItem, toItem);
83+
t.emplace_back(std::move(toItem));
84+
}
85+
}
86+
87+
template <typename K1, typename V1, typename K2, typename V2>
88+
void toThrift(const std::map<K1, V1>& protoMap, std::map<K2, V2>& thriftMap) {
89+
K2 toKey;
90+
V2 toValue;
91+
for (const auto& [fromKey, fromValue] : protoMap) {
92+
toThrift(fromKey, toKey);
93+
toThrift(fromValue, toValue);
94+
thriftMap.emplace(std::move(toKey), std::move(toValue));
95+
}
96+
}
97+
98+
template <typename P, typename T>
99+
void toThrift(const std::shared_ptr<P>& proto, apache::thrift::optional_field_ref<T> thrift) {
100+
if (proto) {
101+
thrift.ensure();
102+
toThrift(*proto, apache::thrift::can_throw(*thrift));
103+
}
104+
}
105+
106+
void fromThrift(const std::string& thrift, std::string& proto) {
107+
proto = thrift;
108+
}
109+
void fromThrift(const bool& thrift, bool& proto) {
110+
proto = thrift;
111+
}
112+
void fromThrift(const int32_t& thrift, int32_t& proto) {
113+
proto = thrift;
114+
}
115+
void fromThrift(const int64_t& thrift, int64_t& proto) {
116+
proto = thrift;
117+
}
118+
void fromThrift(const double& thrift, double& proto) {
119+
proto = thrift;
120+
}
121+
122+
void fromThrift(const double& thrift, facebook::presto::protocol::Duration& duration) {
123+
duration = facebook::presto::protocol::Duration(thrift, facebook::presto::protocol::TimeUnit::MILLISECONDS);
124+
}
125+
126+
void fromThrift(const double& thrift, facebook::presto::protocol::DataSize& dataSize) {
127+
dataSize = facebook::presto::protocol::DataSize(thrift, facebook::presto::protocol::DataUnit::BYTE);
128+
}
129+
130+
template <typename P, typename T>
131+
void fromThrift(const apache::thrift::optional_field_ref<T>& thrift, std::shared_ptr<P>& proto) {
132+
if (thrift.has_value()) {
133+
proto = std::make_shared<P>();
134+
fromThrift(*thrift, *proto);
135+
}
136+
}
137+
138+
template <typename P, typename T>
139+
void fromThrift(const T& thrift, std::shared_ptr<P>& proto) {
140+
proto = std::make_shared<P>();
141+
fromThrift(thrift, *proto);
142+
}
143+
144+
template <typename P, typename T>
145+
void fromThrift(const std::shared_ptr<P>& thrift, std::shared_ptr<T>& proto) {
146+
if (thrift) {
147+
proto = std::make_shared<T>();
148+
fromThrift(*thrift, *proto);
149+
}
150+
}
151+
152+
template <typename V, typename S>
153+
void fromThrift(const std::set<S>& thrift, std::vector<V>& proto) {
154+
proto.reserve(thrift.size());
155+
V toItem;
156+
for (const auto& fromItem : thrift) {
157+
fromThrift(fromItem, toItem);
158+
proto.emplace_back(std::move(toItem));
159+
}
160+
}
161+
162+
template <typename P, typename T>
163+
void fromThrift(const std::vector<P>& thrift, std::vector<T>& proto) {
164+
proto.reserve(thrift.size());
165+
T toItem;
166+
for (const auto& fromItem : thrift) {
167+
fromThrift(fromItem, toItem);
168+
proto.emplace_back(std::move(toItem));
169+
}
170+
}
171+
172+
template <typename K1, typename V1, typename K2, typename V2>
173+
void fromThrift(const std::map<K1, V1>& thriftMap, std::map<K2, V2>& protoMap) {
174+
K2 toKey;
175+
V2 toValue;
176+
for (const auto& [fromKey, fromValue] : thriftMap) {
177+
fromThrift(fromKey, toKey);
178+
fromThrift(fromValue, toValue);
179+
protoMap.emplace(std::move(toKey), std::move(toValue));
180+
}
181+
}
182+
183+
{{! Select all the items and expand either the "hinc" member or the "struct", "enum" members }}
184+
{{#.}}
185+
{{#cinc}}
186+
{{&cinc}}
187+
{{/cinc}}
188+
{{^cinc}}
189+
{{#struct}}
190+
void toThrift(const facebook::presto::protocol::{{class_name}}& proto, {{&class_name}}& thrift) {
191+
{{#fields}}
192+
toThrift(proto.{{proto_name}}, {{^optional}}*{{/optional}}thrift.{{field_name}}_ref());
193+
{{/fields}}
194+
}
195+
void fromThrift(const {{&class_name}}& thrift, facebook::presto::protocol::{{class_name}}& proto) {
196+
{{#fields}}
197+
fromThrift({{^optional}}*{{/optional}}thrift.{{field_name}}_ref(), proto.{{proto_name}});
198+
{{/fields}}
199+
}
200+
201+
{{/struct}}
202+
{{#wrapper}}
203+
void toThrift(const facebook::presto::protocol::{{class_name}}& proto, {{class_name}}& thrift) {
204+
{{#fields}}
205+
toThrift(proto, {{^optional}}*{{/optional}}thrift.{{field_name}}_ref());
206+
{{/fields}}
207+
}
208+
void fromThrift(const {{class_name}}& thrift, facebook::presto::protocol::{{class_name}}& proto) {
209+
{{#fields}}
210+
fromThrift({{^optional}}*{{/optional}}thrift.{{field_name}}_ref(), proto);
211+
{{/fields}}
212+
}
213+
{{/wrapper}}
214+
{{#enum}}
215+
void toThrift(const facebook::presto::protocol::{{class_name}}& proto, {{class_name}}& thrift) {
216+
thrift = ({{class_name}})(static_cast<int>(proto));
217+
}
218+
void fromThrift(const {{class_name}}& thrift, facebook::presto::protocol::{{class_name}}& proto) {
219+
proto = (facebook::presto::protocol::{{class_name}})(static_cast<int>(thrift));
220+
}
221+
222+
{{/enum}}
223+
{{/cinc}}
224+
{{/.}}
225+
226+
}
227+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
#pragma once
15+
16+
{{! Select all the comment items and expand them here }}
17+
{{#.}}
18+
{{#comment}}
19+
{{comment}}
20+
{{/comment}}
21+
{{/.}}
22+
23+
#include "github/presto-trunk/presto-native-execution/presto_cpp/presto_protocol/core/presto_protocol_core.h"
24+
#include "github/presto-trunk/presto-native-execution/presto_cpp/main/thrift/gen-cpp2/presto_thrift_types.h"
25+
26+
namespace facebook::presto::thrift {
27+
28+
void toThrift(const facebook::presto::protocol::Duration& duration, double& thrift);
29+
void toThrift(const facebook::presto::protocol::DataSize& dataSize, double& thrift);
30+
void fromThrift(const double& thrift, facebook::presto::protocol::Duration& duration);
31+
void fromThrift(const double& thrift, facebook::presto::protocol::DataSize& dataSize);
32+
33+
{{! Select all the items and expand either the "hinc" member or the "struct", "enum" members }}
34+
{{#.}}
35+
{{#hinc}}
36+
{{&hinc}}
37+
{{/hinc}}
38+
{{^hinc}}
39+
{{#struct}}
40+
void toThrift(const facebook::presto::protocol::{{class_name}}& proto, {{class_name}}& thrift);
41+
void fromThrift(const {{&class_name}}& thrift, facebook::presto::protocol::{{class_name}}& proto);
42+
43+
{{/struct}}
44+
{{#wrapper}}
45+
void toThrift(const facebook::presto::protocol::{{class_name}}& proto, {{class_name}}& thrift);
46+
void fromThrift(const {{class_name}}& thrift, facebook::presto::protocol::{{class_name}}& proto);
47+
48+
{{/wrapper}}
49+
{{#enum}}
50+
void toThrift(const facebook::presto::protocol::{{class_name}}& proto, {{class_name}}& thrift);
51+
void fromThrift(const {{class_name}}& thrift, facebook::presto::protocol::{{class_name}}& proto);
52+
53+
{{/enum}}
54+
{{/hinc}}
55+
{{/.}}
56+
57+
} // namespace facebook::presto

0 commit comments

Comments
 (0)