-
Notifications
You must be signed in to change notification settings - Fork 0
[native] Add CLP connector #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
#include "presto_cpp/presto_protocol/connector/clp/presto_protocol_clp.h" | ||
#include "presto_cpp/presto_protocol/core/ConnectorProtocol.h" | ||
|
||
namespace facebook::presto::protocol::clp { | ||
using ClpConnectorProtocol = ConnectorProtocolTemplate< | ||
ClpTableHandle, | ||
ClpTableLayoutHandle, | ||
ClpColumnHandle, | ||
NotImplemented, | ||
NotImplemented, | ||
ClpSplit, | ||
NotImplemented, | ||
ClpTransactionHandle, | ||
NotImplemented>; | ||
} // namespace facebook::presto::protocol::clp |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
// presto_protocol.prolog.cpp | ||
// | ||
|
||
{{#.}} | ||
{{#comment}} | ||
{{comment}} | ||
{{/comment}} | ||
{{/.}} | ||
|
||
|
||
#include "presto_cpp/presto_protocol/connector/clp/presto_protocol_clp.h" | ||
using namespace std::string_literals; | ||
|
||
namespace facebook::presto::protocol::clp { | ||
|
||
void to_json(json& j, const ClpTransactionHandle& p) { | ||
j = json::array(); | ||
j.push_back(p._type); | ||
j.push_back(p.instance); | ||
} | ||
Comment on lines
+29
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Validate JSON array length before indexing. |
||
|
||
void from_json(const json& j, ClpTransactionHandle& p) { | ||
j[0].get_to(p._type); | ||
j[1].get_to(p.instance); | ||
} | ||
} // namespace facebook::presto::protocol | ||
{{#.}} | ||
{{#cinc}} | ||
{{&cinc}} | ||
{{/cinc}} | ||
{{^cinc}} | ||
{{#struct}} | ||
namespace facebook::presto::protocol::clp { | ||
{{#super_class}} | ||
{{&class_name}}::{{&class_name}}() noexcept { | ||
_type = "{{json_key}}"; | ||
} | ||
{{/super_class}} | ||
|
||
void to_json(json& j, const {{&class_name}}& p) { | ||
j = json::object(); | ||
{{#super_class}} | ||
j["@type"] = "{{&json_key}}"; | ||
{{/super_class}} | ||
{{#fields}} | ||
to_json_key(j, "{{&field_name}}", p.{{field_name}}, "{{&class_name}}", "{{&field_text}}", "{{&field_name}}"); | ||
{{/fields}} | ||
} | ||
|
||
void from_json(const json& j, {{&class_name}}& p) { | ||
{{#super_class}} | ||
p._type = j["@type"]; | ||
{{/super_class}} | ||
{{#fields}} | ||
from_json_key(j, "{{&field_name}}", p.{{field_name}}, "{{&class_name}}", "{{&field_text}}", "{{&field_name}}"); | ||
{{/fields}} | ||
} | ||
} | ||
{{/struct}} | ||
{{#enum}} | ||
namespace facebook::presto::protocol::clp { | ||
//Loosly copied this here from NLOHMANN_JSON_SERIALIZE_ENUM() | ||
|
||
// NOLINTNEXTLINE: cppcoreguidelines-avoid-c-arrays | ||
static const std::pair<{{&class_name}}, json> | ||
{{&class_name}}_enum_table[] = { // NOLINT: cert-err58-cpp | ||
{{#elements}} | ||
{ {{&class_name}}::{{&element}}, "{{&element}}" }{{^_last}},{{/_last}} | ||
{{/elements}} | ||
}; | ||
void to_json(json& j, const {{&class_name}}& e) | ||
{ | ||
static_assert(std::is_enum<{{&class_name}}>::value, "{{&class_name}} must be an enum!"); | ||
const auto* it = std::find_if(std::begin({{&class_name}}_enum_table), std::end({{&class_name}}_enum_table), | ||
[e](const std::pair<{{&class_name}}, json>& ej_pair) -> bool | ||
{ | ||
return ej_pair.first == e; | ||
}); | ||
j = ((it != std::end({{&class_name}}_enum_table)) ? it : std::begin({{&class_name}}_enum_table))->second; | ||
} | ||
void from_json(const json& j, {{&class_name}}& e) | ||
{ | ||
static_assert(std::is_enum<{{&class_name}}>::value, "{{&class_name}} must be an enum!"); | ||
const auto* it = std::find_if(std::begin({{&class_name}}_enum_table), std::end({{&class_name}}_enum_table), | ||
[&j](const std::pair<{{&class_name}}, json>& ej_pair) -> bool | ||
{ | ||
return ej_pair.second == j; | ||
}); | ||
e = ((it != std::end({{&class_name}}_enum_table)) ? it : std::begin({{&class_name}}_enum_table))->first; | ||
} | ||
} | ||
{{/enum}} | ||
{{#abstract}} | ||
namespace facebook::presto::protocol::clp { | ||
void to_json(json& j, const std::shared_ptr<{{&class_name}}>& p) { | ||
if ( p == nullptr ) { | ||
return; | ||
} | ||
String type = p->_type; | ||
|
||
{{#subclasses}} | ||
if ( type == "{{&key}}" ) { | ||
j = *std::static_pointer_cast<{{&type}}>(p); | ||
return; | ||
} | ||
{{/subclasses}} | ||
|
||
throw TypeError(type + " no abstract type {{&class_name}} {{&key}}"); | ||
} | ||
|
||
void from_json(const json& j, std::shared_ptr<{{&class_name}}>& p) { | ||
String type; | ||
try { | ||
type = p->getSubclassKey(j); | ||
} catch (json::parse_error &e) { | ||
throw ParseError(std::string(e.what()) + " {{&class_name}} {{&key}} {{&class_name}}"); | ||
} | ||
|
||
{{#subclasses}} | ||
if ( type == "{{&key}}" ) { | ||
std::shared_ptr<{{&type}}> k = std::make_shared<{{&type}}>(); | ||
j.get_to(*k); | ||
p = std::static_pointer_cast<{{&class_name}}>(k); | ||
return; | ||
} | ||
{{/subclasses}} | ||
|
||
throw TypeError(type + " no abstract type {{&class_name}} {{&key}}"); | ||
} | ||
} | ||
{{/abstract}} | ||
{{/cinc}} | ||
{{/.}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use tab instead of spaces, otherwise the Makefile cannot run