Skip to content

Commit cb32c73

Browse files
committed
feat: Add SpatialJoinNode to presto_cpp protocol
This will allow SpatialJoinNode to be serialized for Velox.
1 parent c83e6e5 commit cb32c73

4 files changed

Lines changed: 141 additions & 4 deletions

File tree

presto-native-execution/presto_cpp/presto_protocol/core/presto_protocol_core.cpp

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,37 @@ void from_json(const json& j, std::shared_ptr<RowExpression>& p) {
269269
}
270270
} // namespace facebook::presto::protocol
271271
namespace facebook::presto::protocol {
272+
// Loosly copied this here from NLOHMANN_JSON_SERIALIZE_ENUM()
273+
274+
// NOLINTNEXTLINE: cppcoreguidelines-avoid-c-arrays
275+
static const std::pair<Type, json> Type_enum_table[] =
276+
{ // NOLINT: cert-err58-cpp
277+
{Type::INNER, "INNER"},
278+
{Type::LEFT, "LEFT"}};
279+
void to_json(json& j, const Type& e) {
280+
static_assert(std::is_enum<Type>::value, "Type must be an enum!");
281+
const auto* it = std::find_if(
282+
std::begin(Type_enum_table),
283+
std::end(Type_enum_table),
284+
[e](const std::pair<Type, json>& ej_pair) -> bool {
285+
return ej_pair.first == e;
286+
});
287+
j = ((it != std::end(Type_enum_table)) ? it : std::begin(Type_enum_table))
288+
->second;
289+
}
290+
void from_json(const json& j, Type& e) {
291+
static_assert(std::is_enum<Type>::value, "Type must be an enum!");
292+
const auto* it = std::find_if(
293+
std::begin(Type_enum_table),
294+
std::end(Type_enum_table),
295+
[&j](const std::pair<Type, json>& ej_pair) -> bool {
296+
return ej_pair.second == j;
297+
});
298+
e = ((it != std::end(Type_enum_table)) ? it : std::begin(Type_enum_table))
299+
->first;
300+
}
301+
} // namespace facebook::presto::protocol
302+
namespace facebook::presto::protocol {
272303
CallExpression::CallExpression() noexcept {
273304
_type = "call";
274305
}
@@ -730,6 +761,10 @@ void to_json(json& j, const std::shared_ptr<PlanNode>& p) {
730761
j = *std::static_pointer_cast<SemiJoinNode>(p);
731762
return;
732763
}
764+
if (type == ".SpatialJoinNode") {
765+
j = *std::static_pointer_cast<SpatialJoinNode>(p);
766+
return;
767+
}
733768
if (type == ".TableScanNode") {
734769
j = *std::static_pointer_cast<TableScanNode>(p);
735770
return;
@@ -898,6 +933,12 @@ void from_json(const json& j, std::shared_ptr<PlanNode>& p) {
898933
p = std::static_pointer_cast<PlanNode>(k);
899934
return;
900935
}
936+
if (type == ".SpatialJoinNode") {
937+
std::shared_ptr<SpatialJoinNode> k = std::make_shared<SpatialJoinNode>();
938+
j.get_to(*k);
939+
p = std::static_pointer_cast<PlanNode>(k);
940+
return;
941+
}
901942
if (type == ".TableScanNode") {
902943
std::shared_ptr<TableScanNode> k = std::make_shared<TableScanNode>();
903944
j.get_to(*k);
@@ -9294,6 +9335,77 @@ void from_json(const json& j, SortedRangeSet& p) {
92949335
}
92959336
} // namespace facebook::presto::protocol
92969337
namespace facebook::presto::protocol {
9338+
SpatialJoinNode::SpatialJoinNode() noexcept {
9339+
_type = ".SpatialJoinNode";
9340+
}
9341+
9342+
void to_json(json& j, const SpatialJoinNode& p) {
9343+
j = json::object();
9344+
j["@type"] = ".SpatialJoinNode";
9345+
to_json_key(j, "id", p.id, "SpatialJoinNode", "PlanNodeId", "id");
9346+
to_json_key(j, "type", p.type, "SpatialJoinNode", "Type", "type");
9347+
to_json_key(j, "left", p.left, "SpatialJoinNode", "PlanNode", "left");
9348+
to_json_key(j, "right", p.right, "SpatialJoinNode", "PlanNode", "right");
9349+
to_json_key(
9350+
j,
9351+
"outputVariables",
9352+
p.outputVariables,
9353+
"SpatialJoinNode",
9354+
"List<VariableReferenceExpression>",
9355+
"outputVariables");
9356+
to_json_key(
9357+
j, "filter", p.filter, "SpatialJoinNode", "RowExpression", "filter");
9358+
to_json_key(
9359+
j,
9360+
"leftPartitionVariable",
9361+
p.leftPartitionVariable,
9362+
"SpatialJoinNode",
9363+
"VariableReferenceExpression",
9364+
"leftPartitionVariable");
9365+
to_json_key(
9366+
j,
9367+
"rightPartitionVariable",
9368+
p.rightPartitionVariable,
9369+
"SpatialJoinNode",
9370+
"VariableReferenceExpression",
9371+
"rightPartitionVariable");
9372+
to_json_key(j, "kdbTree", p.kdbTree, "SpatialJoinNode", "String", "kdbTree");
9373+
}
9374+
9375+
void from_json(const json& j, SpatialJoinNode& p) {
9376+
p._type = j["@type"];
9377+
from_json_key(j, "id", p.id, "SpatialJoinNode", "PlanNodeId", "id");
9378+
from_json_key(j, "type", p.type, "SpatialJoinNode", "Type", "type");
9379+
from_json_key(j, "left", p.left, "SpatialJoinNode", "PlanNode", "left");
9380+
from_json_key(j, "right", p.right, "SpatialJoinNode", "PlanNode", "right");
9381+
from_json_key(
9382+
j,
9383+
"outputVariables",
9384+
p.outputVariables,
9385+
"SpatialJoinNode",
9386+
"List<VariableReferenceExpression>",
9387+
"outputVariables");
9388+
from_json_key(
9389+
j, "filter", p.filter, "SpatialJoinNode", "RowExpression", "filter");
9390+
from_json_key(
9391+
j,
9392+
"leftPartitionVariable",
9393+
p.leftPartitionVariable,
9394+
"SpatialJoinNode",
9395+
"VariableReferenceExpression",
9396+
"leftPartitionVariable");
9397+
from_json_key(
9398+
j,
9399+
"rightPartitionVariable",
9400+
p.rightPartitionVariable,
9401+
"SpatialJoinNode",
9402+
"VariableReferenceExpression",
9403+
"rightPartitionVariable");
9404+
from_json_key(
9405+
j, "kdbTree", p.kdbTree, "SpatialJoinNode", "String", "kdbTree");
9406+
}
9407+
} // namespace facebook::presto::protocol
9408+
namespace facebook::presto::protocol {
92979409
// Loosly copied this here from NLOHMANN_JSON_SERIALIZE_ENUM()
92989410

92999411
// NOLINTNEXTLINE: cppcoreguidelines-avoid-c-arrays

presto-native-execution/presto_cpp/presto_protocol/core/presto_protocol_core.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,21 @@ extern const char* const PRESTO_ABORT_TASK_URL_PARAM;
6969
class Exception : public std::runtime_error {
7070
public:
7171
explicit Exception(const std::string& message)
72-
: std::runtime_error(message){};
72+
: std::runtime_error(message) {};
7373
};
7474

7575
class TypeError : public Exception {
7676
public:
77-
explicit TypeError(const std::string& message) : Exception(message){};
77+
explicit TypeError(const std::string& message) : Exception(message) {};
7878
};
7979

8080
class OutOfRange : public Exception {
8181
public:
82-
explicit OutOfRange(const std::string& message) : Exception(message){};
82+
explicit OutOfRange(const std::string& message) : Exception(message) {};
8383
};
8484
class ParseError : public Exception {
8585
public:
86-
explicit ParseError(const std::string& message) : Exception(message){};
86+
explicit ParseError(const std::string& message) : Exception(message) {};
8787
};
8888

8989
using String = std::string;
@@ -329,6 +329,11 @@ void to_json(json& j, const SourceLocation& p);
329329
void from_json(const json& j, SourceLocation& p);
330330
} // namespace facebook::presto::protocol
331331
namespace facebook::presto::protocol {
332+
enum class Type { INNER, LEFT };
333+
extern void to_json(json& j, const Type& e);
334+
extern void from_json(const json& j, Type& e);
335+
} // namespace facebook::presto::protocol
336+
namespace facebook::presto::protocol {
332337
struct CallExpression : public RowExpression {
333338
String displayName = {};
334339
std::shared_ptr<FunctionHandle> functionHandle = {};
@@ -2158,6 +2163,22 @@ void to_json(json& j, const SortedRangeSet& p);
21582163
void from_json(const json& j, SortedRangeSet& p);
21592164
} // namespace facebook::presto::protocol
21602165
namespace facebook::presto::protocol {
2166+
struct SpatialJoinNode : public PlanNode {
2167+
Type type = {};
2168+
std::shared_ptr<PlanNode> left = {};
2169+
std::shared_ptr<PlanNode> right = {};
2170+
List<VariableReferenceExpression> outputVariables = {};
2171+
std::shared_ptr<RowExpression> filter = {};
2172+
std::shared_ptr<VariableReferenceExpression> leftPartitionVariable = {};
2173+
std::shared_ptr<VariableReferenceExpression> rightPartitionVariable = {};
2174+
std::shared_ptr<String> kdbTree = {};
2175+
2176+
SpatialJoinNode() noexcept;
2177+
};
2178+
void to_json(json& j, const SpatialJoinNode& p);
2179+
void from_json(const json& j, SpatialJoinNode& p);
2180+
} // namespace facebook::presto::protocol
2181+
namespace facebook::presto::protocol {
21612182
enum class Form {
21622183
IF,
21632184
NULL_IF,

presto-native-execution/presto_cpp/presto_protocol/core/presto_protocol_core.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ AbstractClasses:
160160
- { name: RemoteSourceNode, key: com.facebook.presto.sql.planner.plan.RemoteSourceNode }
161161
- { name: SampleNode, key: com.facebook.presto.sql.planner.plan.SampleNode }
162162
- { name: SemiJoinNode, key: .SemiJoinNode }
163+
- { name: SpatialJoinNode, key: .SpatialJoinNode }
163164
- { name: TableScanNode, key: .TableScanNode }
164165
- { name: TableWriterNode, key: .TableWriterNode }
165166
- { name: TableWriterMergeNode, key: com.facebook.presto.sql.planner.plan.TableWriterMergeNode }
@@ -320,6 +321,7 @@ JavaClasses:
320321
- presto-spi/src/main/java/com/facebook/presto/spi/plan/JoinNode.java
321322
- presto-spi/src/main/java/com/facebook/presto/spi/plan/SemiJoinNode.java
322323
- presto-spi/src/main/java/com/facebook/presto/spi/plan/MergeJoinNode.java
324+
- presto-spi/src/main/java/com/facebook/presto/spi/plan/SpatialJoinNode.java
323325
- presto-main-base/src/main/java/com/facebook/presto/sql/planner/plan/IndexJoinNode.java
324326
- presto-spi/src/main/java/com/facebook/presto/spi/plan/IndexSourceNode.java
325327
- presto-spi/src/main/java/com/facebook/presto/spi/plan/TopNNode.java

presto-native-execution/presto_cpp/presto_protocol/presto_protocol.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ AbstractClasses:
155155
- { name: RemoteSourceNode, key: com.facebook.presto.sql.planner.plan.RemoteSourceNode }
156156
- { name: SampleNode, key: com.facebook.presto.sql.planner.plan.SampleNode }
157157
- { name: SemiJoinNode, key: .SemiJoinNode }
158+
- { name: SpatialoinNode, key: .SpatialJoinNode }
158159
- { name: TableScanNode, key: .TableScanNode }
159160
- { name: TableWriterNode, key: .TableWriterNode }
160161
- { name: TableWriterMergeNode, key: com.facebook.presto.sql.planner.plan.TableWriterMergeNode }
@@ -360,6 +361,7 @@ JavaClasses:
360361
- presto-spi/src/main/java/com/facebook/presto/spi/plan/JoinNode.java
361362
- presto-spi/src/main/java/com/facebook/presto/spi/plan/SemiJoinNode.java
362363
- presto-spi/src/main/java/com/facebook/presto/spi/plan/MergeJoinNode.java
364+
- presto-spi/src/main/java/com/facebook/presto/spi/plan/SpatialJoinNode.java
363365
- presto-spi/src/main/java/com/facebook/presto/spi/plan/TopNNode.java
364366
- presto-hive/src/main/java/com/facebook/presto/hive/HivePartitioningHandle.java
365367
- presto-main/src/main/java/com/facebook/presto/split/EmptySplit.java

0 commit comments

Comments
 (0)