|
16 | 16 | #include "presto_cpp/main/common/Configs.h" |
17 | 17 | #include "presto_cpp/main/connectors/PrestoToVeloxConnector.h" |
18 | 18 | #include "presto_cpp/main/types/PrestoToVeloxQueryPlan.h" |
| 19 | +#include <velox/type/TypeUtil.h> |
19 | 20 | #include <velox/type/Filter.h> |
20 | 21 | #include "velox/core/QueryCtx.h" |
21 | 22 | #include "velox/exec/HashPartitionFunction.h" |
@@ -1116,6 +1117,8 @@ core::JoinType toJoinType(protocol::JoinType type) { |
1116 | 1117 | return core::JoinType::kRight; |
1117 | 1118 | case protocol::JoinType::FULL: |
1118 | 1119 | return core::JoinType::kFull; |
| 1120 | + case protocol::JoinType::SOURCE_OUTER: |
| 1121 | + return core::JoinType::kInner; // TODO: Map to proper join type. |
1119 | 1122 | } |
1120 | 1123 |
|
1121 | 1124 | VELOX_UNSUPPORTED("Unknown join type"); |
@@ -1198,6 +1201,54 @@ velox::core::PlanNodePtr VeloxQueryPlanConverterBase::toVeloxQueryPlan( |
1198 | 1201 | ROW(std::move(outputNames), std::move(outputTypes))); |
1199 | 1202 | } |
1200 | 1203 |
|
| 1204 | + |
| 1205 | +std::shared_ptr<const velox::core::IndexLookupJoinNode> |
| 1206 | +VeloxQueryPlanConverterBase::toVeloxQueryPlan( |
| 1207 | + const std::shared_ptr<const protocol::IndexJoinNode>& node, |
| 1208 | + const std::shared_ptr<protocol::TableWriteInfo>& tableWriteInfo, |
| 1209 | + const protocol::TaskId& taskId) { |
| 1210 | + std::vector<core::FieldAccessTypedExprPtr> leftKeys; |
| 1211 | + std::vector<core::FieldAccessTypedExprPtr> rightKeys; |
| 1212 | + |
| 1213 | + leftKeys.reserve(node->criteria.size()); |
| 1214 | + rightKeys.reserve(node->criteria.size()); |
| 1215 | + for (const auto& clause : node->criteria) { |
| 1216 | + leftKeys.emplace_back(exprConverter_.toVeloxExpr(clause.left)); |
| 1217 | + rightKeys.emplace_back(exprConverter_.toVeloxExpr(clause.right)); |
| 1218 | + } |
| 1219 | + |
| 1220 | + auto left = toVeloxQueryPlan(node->probeSource, tableWriteInfo, taskId); |
| 1221 | + auto right = toVeloxQueryPlan(node->indexSource, tableWriteInfo, taskId); |
| 1222 | + |
| 1223 | + return std::make_shared<core::IndexLookupJoinNode>( |
| 1224 | + node->id, |
| 1225 | + core::JoinType::kInner, |
| 1226 | + /*leftKeys=*/leftKeys, |
| 1227 | + /*rightKeys=*/rightKeys, |
| 1228 | + /*joinConditions=*/std::vector<velox::core::IndexLookupConditionPtr>{}, |
| 1229 | + /*left=*/left, |
| 1230 | + /*right=*/std::dynamic_pointer_cast<const core::TableScanNode>(right), |
| 1231 | + /*outputType=*/type::concatRowTypes({left->outputType(), right->outputType()})); |
| 1232 | +} |
| 1233 | + |
| 1234 | +std::shared_ptr<const velox::core::TableScanNode> |
| 1235 | +VeloxQueryPlanConverterBase::toVeloxQueryPlan( |
| 1236 | + const std::shared_ptr<const protocol::IndexSourceNode>& node, |
| 1237 | + const std::shared_ptr<protocol::TableWriteInfo>& tableWriteInfo, |
| 1238 | + const protocol::TaskId& taskId) { |
| 1239 | + auto rowType = toRowType(node->outputVariables, typeParser_); |
| 1240 | + std::unordered_map<std::string, std::shared_ptr<connector::ColumnHandle>> |
| 1241 | + assignments; |
| 1242 | + for (const auto& entry : node->assignments) { |
| 1243 | + assignments.emplace( |
| 1244 | + entry.first.name, toColumnHandle(entry.second.get(), typeParser_)); |
| 1245 | + } |
| 1246 | + auto connectorTableHandle = toConnectorTableHandle( |
| 1247 | + node->tableHandle, exprConverter_, typeParser_, assignments); |
| 1248 | + return std::make_shared<core::TableScanNode>( |
| 1249 | + node->id, rowType, connectorTableHandle, assignments); |
| 1250 | +} |
| 1251 | + |
1201 | 1252 | core::PlanNodePtr VeloxQueryPlanConverterBase::toVeloxQueryPlan( |
1202 | 1253 | const std::shared_ptr<const protocol::MarkDistinctNode>& node, |
1203 | 1254 | const std::shared_ptr<protocol::TableWriteInfo>& tableWriteInfo, |
@@ -1724,6 +1775,14 @@ core::PlanNodePtr VeloxQueryPlanConverterBase::toVeloxQueryPlan( |
1724 | 1775 | std::dynamic_pointer_cast<const protocol::SemiJoinNode>(node)) { |
1725 | 1776 | return toVeloxQueryPlan(join, tableWriteInfo, taskId); |
1726 | 1777 | } |
| 1778 | + if (auto join = |
| 1779 | + std::dynamic_pointer_cast<const protocol::IndexJoinNode>(node)) { |
| 1780 | + return toVeloxQueryPlan(join, tableWriteInfo, taskId); |
| 1781 | + } |
| 1782 | + if (auto indexSource = |
| 1783 | + std::dynamic_pointer_cast<const protocol::IndexSourceNode>(node)) { |
| 1784 | + return toVeloxQueryPlan(indexSource, tableWriteInfo, taskId); |
| 1785 | + } |
1727 | 1786 | if (auto join = |
1728 | 1787 | std::dynamic_pointer_cast<const protocol::MergeJoinNode>(node)) { |
1729 | 1788 | return toVeloxQueryPlan(join, tableWriteInfo, taskId); |
|
0 commit comments