Skip to content

Commit 21bdd48

Browse files
authored
Fix MV mapping (prestodb#24787)
The original approach will cause a "Unsupported table writer handle" error. We should use InsertHandle with the MaterializedViewHandle key. The order also needs to have MaterializedViewHandle key before InsertHandle key, otherwise the insertHandle type will be replaced with MaterializedViewHandle.
1 parent b175123 commit 21bdd48

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

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

+9-15
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,10 @@ void to_json(json& j, const std::shared_ptr<ExecutionWriterTarget>& p) {
24102410
j = *std::static_pointer_cast<CreateHandle>(p);
24112411
return;
24122412
}
2413+
if (type == "RefreshMaterializedViewHandle") {
2414+
j = *std::static_pointer_cast<InsertHandle>(p);
2415+
return;
2416+
}
24132417
if (type == "InsertHandle") {
24142418
j = *std::static_pointer_cast<InsertHandle>(p);
24152419
return;
@@ -2418,10 +2422,6 @@ void to_json(json& j, const std::shared_ptr<ExecutionWriterTarget>& p) {
24182422
j = *std::static_pointer_cast<DeleteHandle>(p);
24192423
return;
24202424
}
2421-
if (type == "RefreshMaterializedViewHandle") {
2422-
j = *std::static_pointer_cast<RefreshMaterializedViewHandle>(p);
2423-
return;
2424-
}
24252425

24262426
throw TypeError(type + " no abstract type ExecutionWriterTarget ");
24272427
}
@@ -2442,21 +2442,20 @@ void from_json(const json& j, std::shared_ptr<ExecutionWriterTarget>& p) {
24422442
p = std::static_pointer_cast<ExecutionWriterTarget>(k);
24432443
return;
24442444
}
2445-
if (type == "InsertHandle") {
2445+
if (type == "RefreshMaterializedViewHandle") {
24462446
std::shared_ptr<InsertHandle> k = std::make_shared<InsertHandle>();
24472447
j.get_to(*k);
24482448
p = std::static_pointer_cast<ExecutionWriterTarget>(k);
24492449
return;
24502450
}
2451-
if (type == "DeleteHandle") {
2452-
std::shared_ptr<DeleteHandle> k = std::make_shared<DeleteHandle>();
2451+
if (type == "InsertHandle") {
2452+
std::shared_ptr<InsertHandle> k = std::make_shared<InsertHandle>();
24532453
j.get_to(*k);
24542454
p = std::static_pointer_cast<ExecutionWriterTarget>(k);
24552455
return;
24562456
}
2457-
if (type == "RefreshMaterializedViewHandle") {
2458-
std::shared_ptr<RefreshMaterializedViewHandle> k =
2459-
std::make_shared<RefreshMaterializedViewHandle>();
2457+
if (type == "DeleteHandle") {
2458+
std::shared_ptr<DeleteHandle> k = std::make_shared<DeleteHandle>();
24602459
j.get_to(*k);
24612460
p = std::static_pointer_cast<ExecutionWriterTarget>(k);
24622461
return;
@@ -8461,13 +8460,9 @@ void from_json(const json& j, Range& p) {
84618460
}
84628461
} // namespace facebook::presto::protocol
84638462
namespace facebook::presto::protocol {
8464-
RefreshMaterializedViewHandle::RefreshMaterializedViewHandle() noexcept {
8465-
_type = "RefreshMaterializedViewHandle";
8466-
}
84678463

84688464
void to_json(json& j, const RefreshMaterializedViewHandle& p) {
84698465
j = json::object();
8470-
j["@type"] = "RefreshMaterializedViewHandle";
84718466
to_json_key(
84728467
j,
84738468
"handle",
@@ -8485,7 +8480,6 @@ void to_json(json& j, const RefreshMaterializedViewHandle& p) {
84858480
}
84868481

84878482
void from_json(const json& j, RefreshMaterializedViewHandle& p) {
8488-
p._type = j["@type"];
84898483
from_json_key(
84908484
j,
84918485
"handle",

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -1948,11 +1948,9 @@ void to_json(json& j, const Range& p);
19481948
void from_json(const json& j, Range& p);
19491949
} // namespace facebook::presto::protocol
19501950
namespace facebook::presto::protocol {
1951-
struct RefreshMaterializedViewHandle : public ExecutionWriterTarget {
1951+
struct RefreshMaterializedViewHandle {
19521952
InsertTableHandle handle = {};
19531953
SchemaTableName schemaTableName = {};
1954-
1955-
RefreshMaterializedViewHandle() noexcept;
19561954
};
19571955
void to_json(json& j, const RefreshMaterializedViewHandle& p);
19581956
void from_json(const json& j, RefreshMaterializedViewHandle& p);

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ AbstractClasses:
124124
ExecutionWriterTarget:
125125
super: JsonEncodedSubclass
126126
subclasses:
127-
- { name: CreateHandle, key: CreateHandle }
128-
- { name: InsertHandle, key: InsertHandle }
129-
- { name: DeleteHandle, key: DeleteHandle }
130-
- { name: RefreshMaterializedViewHandle, key: RefreshMaterializedViewHandle }
127+
- { name: CreateHandle, key: CreateHandle }
128+
- { name: InsertHandle, key: RefreshMaterializedViewHandle }
129+
- { name: InsertHandle, key: InsertHandle }
130+
- { name: DeleteHandle, key: DeleteHandle }
131+
131132

132133
InputDistribution:
133134
super: JsonEncodedSubclass

0 commit comments

Comments
 (0)