Skip to content

Commit d2ac312

Browse files
ghelmlingrschlussel
authored andcommitted
Add DeleteNode to presto_protocol serialization
1 parent 3f99d9c commit d2ac312

File tree

11 files changed

+428
-24
lines changed

11 files changed

+428
-24
lines changed

presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/AddExchanges.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.facebook.presto.spi.plan.EquiJoinClause;
3434
import com.facebook.presto.spi.plan.FilterNode;
3535
import com.facebook.presto.spi.plan.IndexSourceNode;
36+
import com.facebook.presto.spi.plan.InputDistribution;
3637
import com.facebook.presto.spi.plan.JoinDistributionType;
3738
import com.facebook.presto.spi.plan.JoinNode;
3839
import com.facebook.presto.spi.plan.LimitNode;
@@ -545,7 +546,7 @@ public PlanWithProperties visitDelete(DeleteNode node, PreferredProperties prefe
545546
if (!node.getInputDistribution().isPresent()) {
546547
return visitPlan(node, preferredProperties);
547548
}
548-
DeleteNode.InputDistribution inputDistribution = node.getInputDistribution().get();
549+
InputDistribution inputDistribution = node.getInputDistribution().get();
549550
List<LocalProperty<VariableReferenceExpression>> desiredProperties = new ArrayList<>();
550551
if (!inputDistribution.getPartitionBy().isEmpty()) {
551552
desiredProperties.add(new GroupingProperty<>(inputDistribution.getPartitionBy()));

presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/AddLocalExchanges.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.facebook.presto.spi.plan.DeleteNode;
2626
import com.facebook.presto.spi.plan.DistinctLimitNode;
2727
import com.facebook.presto.spi.plan.EquiJoinClause;
28+
import com.facebook.presto.spi.plan.InputDistribution;
2829
import com.facebook.presto.spi.plan.JoinNode;
2930
import com.facebook.presto.spi.plan.LimitNode;
3031
import com.facebook.presto.spi.plan.MarkDistinctNode;
@@ -469,7 +470,7 @@ public PlanWithProperties visitDelete(DeleteNode node, StreamPreferredProperties
469470
if (!node.getInputDistribution().isPresent()) {
470471
return visitPlan(node, parentPreferences);
471472
}
472-
DeleteNode.InputDistribution inputDistribution = node.getInputDistribution().get();
473+
InputDistribution inputDistribution = node.getInputDistribution().get();
473474
StreamPreferredProperties childRequirements = parentPreferences
474475
.constrainTo(node.getSource().getOutputVariables())
475476
.withDefaultParallelism(session)

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

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,10 @@ void to_json(json& j, const std::shared_ptr<PlanNode>& p) {
636636
j = *std::static_pointer_cast<GroupIdNode>(p);
637637
return;
638638
}
639+
if (type == ".DeleteNode") {
640+
j = *std::static_pointer_cast<DeleteNode>(p);
641+
return;
642+
}
639643
if (type == ".DistinctLimitNode") {
640644
j = *std::static_pointer_cast<DistinctLimitNode>(p);
641645
return;
@@ -756,6 +760,12 @@ void from_json(const json& j, std::shared_ptr<PlanNode>& p) {
756760
p = std::static_pointer_cast<PlanNode>(k);
757761
return;
758762
}
763+
if (type == ".DeleteNode") {
764+
std::shared_ptr<DeleteNode> k = std::make_shared<DeleteNode>();
765+
j.get_to(*k);
766+
p = std::static_pointer_cast<PlanNode>(k);
767+
return;
768+
}
759769
if (type == ".DistinctLimitNode") {
760770
std::shared_ptr<DistinctLimitNode> k =
761771
std::make_shared<DistinctLimitNode>();
@@ -1221,6 +1231,62 @@ void from_json(const json& j, Assignments& p) {
12211231
}
12221232
} // namespace facebook::presto::protocol
12231233
namespace facebook::presto::protocol {
1234+
BaseInputDistribution::BaseInputDistribution() noexcept {
1235+
_type = ".BaseInputDistribution";
1236+
}
1237+
1238+
void to_json(json& j, const BaseInputDistribution& p) {
1239+
j = json::object();
1240+
j["@type"] = ".BaseInputDistribution";
1241+
to_json_key(
1242+
j,
1243+
"partitionBy",
1244+
p.partitionBy,
1245+
"BaseInputDistribution",
1246+
"List<VariableReferenceExpression>",
1247+
"partitionBy");
1248+
to_json_key(
1249+
j,
1250+
"orderingScheme",
1251+
p.orderingScheme,
1252+
"BaseInputDistribution",
1253+
"OrderingScheme",
1254+
"orderingScheme");
1255+
to_json_key(
1256+
j,
1257+
"inputVariables",
1258+
p.inputVariables,
1259+
"BaseInputDistribution",
1260+
"List<VariableReferenceExpression>",
1261+
"inputVariables");
1262+
}
1263+
1264+
void from_json(const json& j, BaseInputDistribution& p) {
1265+
p._type = j["@type"];
1266+
from_json_key(
1267+
j,
1268+
"partitionBy",
1269+
p.partitionBy,
1270+
"BaseInputDistribution",
1271+
"List<VariableReferenceExpression>",
1272+
"partitionBy");
1273+
from_json_key(
1274+
j,
1275+
"orderingScheme",
1276+
p.orderingScheme,
1277+
"BaseInputDistribution",
1278+
"OrderingScheme",
1279+
"orderingScheme");
1280+
from_json_key(
1281+
j,
1282+
"inputVariables",
1283+
p.inputVariables,
1284+
"BaseInputDistribution",
1285+
"List<VariableReferenceExpression>",
1286+
"inputVariables");
1287+
}
1288+
} // namespace facebook::presto::protocol
1289+
namespace facebook::presto::protocol {
12241290
// Loosly copied this here from NLOHMANN_JSON_SERIALIZE_ENUM()
12251291

12261292
// NOLINTNEXTLINE: cppcoreguidelines-avoid-c-arrays
@@ -3216,6 +3282,101 @@ void from_json(const json& j, DeleteHandle& p) {
32163282
}
32173283
} // namespace facebook::presto::protocol
32183284
namespace facebook::presto::protocol {
3285+
void to_json(json& j, const std::shared_ptr<InputDistribution>& p) {
3286+
if (p == nullptr) {
3287+
return;
3288+
}
3289+
String type = p->_type;
3290+
3291+
if (type == ".BaseInputDistribution") {
3292+
j = *std::static_pointer_cast<BaseInputDistribution>(p);
3293+
return;
3294+
}
3295+
3296+
throw TypeError(type + " no abstract type InputDistribution ");
3297+
}
3298+
3299+
void from_json(const json& j, std::shared_ptr<InputDistribution>& p) {
3300+
String type;
3301+
try {
3302+
type = p->getSubclassKey(j);
3303+
} catch (json::parse_error& e) {
3304+
throw ParseError(
3305+
std::string(e.what()) + " InputDistribution InputDistribution");
3306+
}
3307+
3308+
if (type == ".BaseInputDistribution") {
3309+
std::shared_ptr<BaseInputDistribution> k =
3310+
std::make_shared<BaseInputDistribution>();
3311+
j.get_to(*k);
3312+
p = std::static_pointer_cast<InputDistribution>(k);
3313+
return;
3314+
}
3315+
3316+
throw TypeError(type + " no abstract type InputDistribution ");
3317+
}
3318+
} // namespace facebook::presto::protocol
3319+
namespace facebook::presto::protocol {
3320+
DeleteNode::DeleteNode() noexcept {
3321+
_type = ".DeleteNode";
3322+
}
3323+
3324+
void to_json(json& j, const DeleteNode& p) {
3325+
j = json::object();
3326+
j["@type"] = ".DeleteNode";
3327+
to_json_key(j, "id", p.id, "DeleteNode", "PlanNodeId", "id");
3328+
to_json_key(j, "source", p.source, "DeleteNode", "PlanNode", "source");
3329+
to_json_key(
3330+
j,
3331+
"rowId",
3332+
p.rowId,
3333+
"DeleteNode",
3334+
"VariableReferenceExpression",
3335+
"rowId");
3336+
to_json_key(
3337+
j,
3338+
"outputVariables",
3339+
p.outputVariables,
3340+
"DeleteNode",
3341+
"List<VariableReferenceExpression>",
3342+
"outputVariables");
3343+
to_json_key(
3344+
j,
3345+
"inputDistribution",
3346+
p.inputDistribution,
3347+
"DeleteNode",
3348+
"InputDistribution",
3349+
"inputDistribution");
3350+
}
3351+
3352+
void from_json(const json& j, DeleteNode& p) {
3353+
p._type = j["@type"];
3354+
from_json_key(j, "id", p.id, "DeleteNode", "PlanNodeId", "id");
3355+
from_json_key(j, "source", p.source, "DeleteNode", "PlanNode", "source");
3356+
from_json_key(
3357+
j,
3358+
"rowId",
3359+
p.rowId,
3360+
"DeleteNode",
3361+
"VariableReferenceExpression",
3362+
"rowId");
3363+
from_json_key(
3364+
j,
3365+
"outputVariables",
3366+
p.outputVariables,
3367+
"DeleteNode",
3368+
"List<VariableReferenceExpression>",
3369+
"outputVariables");
3370+
from_json_key(
3371+
j,
3372+
"inputDistribution",
3373+
p.inputDistribution,
3374+
"DeleteNode",
3375+
"InputDistribution",
3376+
"inputDistribution");
3377+
}
3378+
} // namespace facebook::presto::protocol
3379+
namespace facebook::presto::protocol {
32193380
DistinctLimitNode::DistinctLimitNode() noexcept {
32203381
_type = ".DistinctLimitNode";
32213382
}

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

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,21 @@ extern const char* const PRESTO_ABORT_TASK_URL_PARAM;
6767
class Exception : public std::runtime_error {
6868
public:
6969
explicit Exception(const std::string& message)
70-
: std::runtime_error(message){};
70+
: std::runtime_error(message) {};
7171
};
7272

7373
class TypeError : public Exception {
7474
public:
75-
explicit TypeError(const std::string& message) : Exception(message){};
75+
explicit TypeError(const std::string& message) : Exception(message) {};
7676
};
7777

7878
class OutOfRange : public Exception {
7979
public:
80-
explicit OutOfRange(const std::string& message) : Exception(message){};
80+
explicit OutOfRange(const std::string& message) : Exception(message) {};
8181
};
8282
class ParseError : public Exception {
8383
public:
84-
explicit ParseError(const std::string& message) : Exception(message){};
84+
explicit ParseError(const std::string& message) : Exception(message) {};
8585
};
8686

8787
using String = std::string;
@@ -312,6 +312,11 @@ void to_json(json& j, const std::shared_ptr<ConnectorOutputTableHandle>& p);
312312
void from_json(const json& j, std::shared_ptr<ConnectorOutputTableHandle>& p);
313313
} // namespace facebook::presto::protocol
314314
namespace facebook::presto::protocol {
315+
struct InputDistribution : public JsonEncodedSubclass {};
316+
void to_json(json& j, const std::shared_ptr<InputDistribution>& p);
317+
void from_json(const json& j, std::shared_ptr<InputDistribution>& p);
318+
} // namespace facebook::presto::protocol
319+
namespace facebook::presto::protocol {
315320
struct ValueSet : public JsonEncodedSubclass {};
316321
void to_json(json& j, const std::shared_ptr<ValueSet>& p);
317322
void from_json(const json& j, std::shared_ptr<ValueSet>& p);
@@ -523,6 +528,17 @@ void to_json(json& j, const Assignments& p);
523528
void from_json(const json& j, Assignments& p);
524529
} // namespace facebook::presto::protocol
525530
namespace facebook::presto::protocol {
531+
struct BaseInputDistribution : public InputDistribution {
532+
List<VariableReferenceExpression> partitionBy = {};
533+
std::shared_ptr<OrderingScheme> orderingScheme = {};
534+
List<VariableReferenceExpression> inputVariables = {};
535+
536+
BaseInputDistribution() noexcept;
537+
};
538+
void to_json(json& j, const BaseInputDistribution& p);
539+
void from_json(const json& j, BaseInputDistribution& p);
540+
} // namespace facebook::presto::protocol
541+
namespace facebook::presto::protocol {
526542
enum class BufferType {
527543
PARTITIONED,
528544
BROADCAST,
@@ -1020,6 +1036,18 @@ void to_json(json& j, const DeleteHandle& p);
10201036
void from_json(const json& j, DeleteHandle& p);
10211037
} // namespace facebook::presto::protocol
10221038
namespace facebook::presto::protocol {
1039+
struct DeleteNode : public PlanNode {
1040+
std::shared_ptr<PlanNode> source = {};
1041+
VariableReferenceExpression rowId = {};
1042+
List<VariableReferenceExpression> outputVariables = {};
1043+
std::shared_ptr<InputDistribution> inputDistribution = {};
1044+
1045+
DeleteNode() noexcept;
1046+
};
1047+
void to_json(json& j, const DeleteNode& p);
1048+
void from_json(const json& j, DeleteNode& p);
1049+
} // namespace facebook::presto::protocol
1050+
namespace facebook::presto::protocol {
10231051
struct DistinctLimitNode : public PlanNode {
10241052
std::shared_ptr<PlanNode> source = {};
10251053
int64_t limit = {};

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,17 @@ AbstractClasses:
124124
- { name: InsertHandle, key: InsertHandle }
125125
- { name: DeleteHandle, key: DeleteHandle }
126126

127+
InputDistribution:
128+
super: JsonEncodedSubclass
129+
subclasses:
130+
- { name: BaseInputDistribution, key: .BaseInputDistribution }
131+
127132
PlanNode:
128133
super: JsonEncodedSubclass
129134
subclasses:
130135
- { name: AggregationNode, key: .AggregationNode }
131136
- { name: GroupIdNode, key: com.facebook.presto.sql.planner.plan.GroupIdNode }
137+
- { name: DeleteNode, key: .DeleteNode }
132138
- { name: DistinctLimitNode, key: .DistinctLimitNode }
133139
- { name: EnforceSingleRowNode, key: com.facebook.presto.sql.planner.plan.EnforceSingleRowNode }
134140
- { name: ExchangeNode, key: com.facebook.presto.sql.planner.plan.ExchangeNode }
@@ -319,3 +325,5 @@ JavaClasses:
319325
- presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/nativechecker/PlanConversionFailureInfo.java
320326
- presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/nativechecker/PlanConversionResponse.java
321327
- presto-function-namespace-managers-common/src/main/java/com/facebook/presto/functionNamespace/JsonBasedUdfFunctionMetadata.java
328+
- presto-spi/src/main/java/com/facebook/presto/spi/plan/DeleteNode.java
329+
- presto-spi/src/main/java/com/facebook/presto/spi/plan/BaseInputDistribution.java

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,17 @@ AbstractClasses:
123123
- { name: InsertHandle, key: InsertHandle }
124124
- { name: DeleteHandle, key: DeleteHandle }
125125

126+
InputDistribution:
127+
super: JsonEncodedSubclass
128+
subclasses:
129+
- { name: BaseInputDistribution, key: BaseInputDistribution }
130+
126131
PlanNode:
127132
super: JsonEncodedSubclass
128133
subclasses:
129134
- { name: AggregationNode, key: .AggregationNode }
130135
- { name: GroupIdNode, key: com.facebook.presto.sql.planner.plan.GroupIdNode }
136+
- { name: DeleteNode, key: .DeleteNode }
131137
- { name: DistinctLimitNode, key: .DistinctLimitNode }
132138
- { name: EnforceSingleRowNode, key: com.facebook.presto.sql.planner.plan.EnforceSingleRowNode }
133139
- { name: ExchangeNode, key: com.facebook.presto.sql.planner.plan.ExchangeNode }
@@ -366,3 +372,5 @@ JavaClasses:
366372
- presto-main/src/main/java/com/facebook/presto/connector/system/SystemTransactionHandle.java
367373
- presto-spi/src/main/java/com/facebook/presto/spi/function/AggregationFunctionMetadata.java
368374
- presto-function-namespace-managers-common/src/main/java/com/facebook/presto/functionNamespace/JsonBasedUdfFunctionMetadata.java
375+
- presto-spi/src/main/java/com/facebook/presto/spi/plan/DeleteNode.java
376+
- presto-spi/src/main/java/com/facebook/presto/spi/plan/BaseInputDistribution.java

presto-native-execution/presto_cpp/presto_protocol/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_executable(
1616
CallExpressionTest.cpp
1717
ConstantExpressionTest.cpp
1818
DataSizeTest.cpp
19+
DeleteTest.cpp
1920
DomainTest.cpp
2021
DurationTest.cpp
2122
LifespanTest.cpp

0 commit comments

Comments
 (0)