Skip to content

Commit ba6980c

Browse files
committed
PrestoToVeloxQueryPlan
1 parent f4626e0 commit ba6980c

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

presto-native-execution/presto_cpp/main/types/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_library(presto_types PrestoToVeloxQueryPlan.cpp VeloxPlanValidator.cpp
2121
PrestoToVeloxSplit.cpp)
2222
target_link_libraries(
2323
presto_types
24+
$<TARGET_OBJECTS:presto_tvf_core>
2425
presto_velox_expr_conversion
2526
presto_connectors
2627
presto_operators

presto-native-execution/presto_cpp/main/types/PrestoToVeloxQueryPlan.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,49 @@ VeloxQueryPlanConverterBase::toVeloxQueryPlan(
17691769
toVeloxQueryPlan(node->source, tableWriteInfo, taskId));
17701770
}
17711771

1772+
std::shared_ptr<const tvf::TableFunctionProcessorNode>
1773+
VeloxQueryPlanConverterBase::toVeloxQueryPlan(
1774+
const std::shared_ptr<const protocol::TableFunctionProcessorNode>& node,
1775+
const std::shared_ptr<protocol::TableWriteInfo>& tableWriteInfo,
1776+
const protocol::TaskId& taskId) {
1777+
const auto outputType = toRowType(node->properOutputs, typeParser_);
1778+
1779+
std::vector<column_index_t> requiredColumns;
1780+
std::vector<core::PlanNodePtr> sources;
1781+
if (node->source) {
1782+
const auto sourceNode = toVeloxQueryPlan(*node->source, tableWriteInfo, taskId);
1783+
const auto inputType = sourceNode->outputType();
1784+
for (const auto& variables : node->requiredVariables) {
1785+
for (const auto& expr : toVeloxExprs(variables)) {
1786+
requiredColumns.push_back(exprToChannel(expr.get(), inputType));
1787+
}
1788+
}
1789+
}
1790+
1791+
// TODO: deserialize node->handle.functionHandle to construct the handle
1792+
const auto tableFunctionHandlePtr = nullptr;
1793+
1794+
auto partitionKeys = toVeloxExprs(node->specification->partitionBy);
1795+
1796+
std::vector<core::FieldAccessTypedExprPtr> sortingKeys;
1797+
std::vector<core::SortOrder> sortingOrders;
1798+
for (const auto& orderby : node->specification->orderingScheme->orderBy) {
1799+
sortingKeys.emplace_back(exprConverter_.toVeloxExpr(orderby.variable));
1800+
sortingOrders.push_back(toVeloxSortOrder(orderby.sortOrder));
1801+
}
1802+
1803+
return std::make_shared<tvf::TableFunctionProcessorNode>(
1804+
node->id,
1805+
node->name,
1806+
tableFunctionHandlePtr,
1807+
partitionKeys,
1808+
sortingKeys,
1809+
sortingOrders,
1810+
outputType,
1811+
requiredColumns,
1812+
sources);
1813+
}
1814+
17721815
core::PlanNodePtr VeloxQueryPlanConverterBase::toVeloxQueryPlan(
17731816
const std::shared_ptr<const protocol::PlanNode>& node,
17741817
const std::shared_ptr<protocol::TableWriteInfo>& tableWriteInfo,

presto-native-execution/presto_cpp/main/types/PrestoToVeloxQueryPlan.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <stdexcept>
1616
#include <vector>
1717
#include "presto_cpp/main/operators/ShuffleInterface.h"
18+
#include "presto_cpp/main/tvf/core/TableFunctionProcessorNode.h"
1819
#include "presto_cpp/presto_protocol/core/presto_protocol_core.h"
1920
#include "velox/core/Expressions.h"
2021
#include "velox/core/PlanFragment.h"
@@ -190,6 +191,11 @@ class VeloxQueryPlanConverterBase {
190191
const std::shared_ptr<protocol::TableWriteInfo>& tableWriteInfo,
191192
const protocol::TaskId& taskId);
192193

194+
std::shared_ptr<const tvf::TableFunctionProcessorNode> toVeloxQueryPlan(
195+
const std::shared_ptr<const protocol::TableFunctionProcessorNode>& node,
196+
const std::shared_ptr<protocol::TableWriteInfo>& tableWriteInfo,
197+
const protocol::TaskId& taskId);
198+
193199
std::vector<velox::core::FieldAccessTypedExprPtr> toVeloxExprs(
194200
const std::vector<protocol::VariableReferenceExpression>& variables);
195201

presto-native-execution/presto_cpp/main/types/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ target_link_libraries(
5151
GTest::gtest_main
5252
presto_connectors
5353
$<TARGET_OBJECTS:presto_protocol>
54+
$<TARGET_OBJECTS:presto_tvf_core>
5455
$<TARGET_OBJECTS:presto_type_converter>
5556
$<TARGET_OBJECTS:presto_types>
5657
presto_operators

0 commit comments

Comments
 (0)