1616
1717#include " velox/substrait/SubstraitToVeloxPlan.h"
1818
19- #include < google/protobuf/wrappers.pb.h>
20-
2119#include " velox/substrait/TypeUtils.h"
2220#include " velox/substrait/VariantToVectorConverter.h"
2321#include " velox/type/Type.h"
@@ -63,26 +61,6 @@ const std::string sNot = "not";
6361const std::string sI32 = " i32" ;
6462const std::string sI64 = " i64" ;
6563
66- // / @brief Return whether a config is set as true in AdvancedExtension
67- // / optimization.
68- // / @param extension Substrait advanced extension.
69- // / @param config the key string of a config.
70- // / @return Whether the config is set as true.
71- bool configSetInOptimization (
72- const ::substrait::extensions::AdvancedExtension& extension,
73- const std::string& config) {
74- if (extension.has_optimization ()) {
75- google::protobuf::StringValue msg;
76- extension.optimization ().UnpackTo (&msg);
77- std::size_t pos = msg.value ().find (config);
78- if ((pos != std::string::npos) &&
79- (msg.value ().substr (pos + config.size (), 1 ) == " 1" )) {
80- return true ;
81- }
82- }
83- return false ;
84- }
85-
8664// / @brief Get the input type from both sides of join.
8765// / @param leftNode the plan node of left side.
8866// / @param rightNode the plan node of right side.
@@ -219,7 +197,7 @@ core::PlanNodePtr SubstraitVeloxPlanConverter::toVeloxPlan(
219197 case ::substrait::JoinRel_JoinType::JoinRel_JoinType_JOIN_TYPE_LEFT_SEMI:
220198 // Determine the semi join type based on extracted information.
221199 if (sJoin .has_advanced_extension () &&
222- configSetInOptimization (
200+ subParser_-> configSetInOptimization (
223201 sJoin .advanced_extension (), " isExistenceJoin=" )) {
224202 joinType = core::JoinType::kLeftSemiProject ;
225203 } else {
@@ -229,7 +207,7 @@ core::PlanNodePtr SubstraitVeloxPlanConverter::toVeloxPlan(
229207 case ::substrait::JoinRel_JoinType::JoinRel_JoinType_JOIN_TYPE_RIGHT_SEMI:
230208 // Determine the semi join type based on extracted information.
231209 if (sJoin .has_advanced_extension () &&
232- configSetInOptimization (
210+ subParser_-> configSetInOptimization (
233211 sJoin .advanced_extension (), " isExistenceJoin=" )) {
234212 joinType = core::JoinType::kRightSemiProject ;
235213 } else {
@@ -239,7 +217,7 @@ core::PlanNodePtr SubstraitVeloxPlanConverter::toVeloxPlan(
239217 case ::substrait::JoinRel_JoinType::JoinRel_JoinType_JOIN_TYPE_ANTI: {
240218 // Determine the anti join type based on extracted information.
241219 if (sJoin .has_advanced_extension () &&
242- configSetInOptimization (
220+ subParser_-> configSetInOptimization (
243221 sJoin .advanced_extension (), " isNullAwareAntiJoin=" )) {
244222 joinType = core::JoinType::kNullAwareAnti ;
245223 } else {
@@ -276,16 +254,32 @@ core::PlanNodePtr SubstraitVeloxPlanConverter::toVeloxPlan(
276254 exprConverter_->toVeloxExpr (sJoin .post_join_filter (), inputRowType);
277255 }
278256
279- // Create join node
280- return std::make_shared<core::HashJoinNode>(
281- nextPlanNodeId (),
282- joinType,
283- leftKeys,
284- rightKeys,
285- filter,
286- leftNode,
287- rightNode,
288- getJoinOutputType (leftNode, rightNode, joinType));
257+ if (sJoin .has_advanced_extension () &&
258+ subParser_->configSetInOptimization (
259+ sJoin .advanced_extension (), " isSMJ=" )) {
260+ // Create MergeJoinNode node
261+ return std::make_shared<core::MergeJoinNode>(
262+ nextPlanNodeId (),
263+ joinType,
264+ leftKeys,
265+ rightKeys,
266+ filter,
267+ leftNode,
268+ rightNode,
269+ getJoinOutputType (leftNode, rightNode, joinType));
270+
271+ } else {
272+ // Create HashJoinNode node
273+ return std::make_shared<core::HashJoinNode>(
274+ nextPlanNodeId (),
275+ joinType,
276+ leftKeys,
277+ rightKeys,
278+ filter,
279+ leftNode,
280+ rightNode,
281+ getJoinOutputType (leftNode, rightNode, joinType));
282+ }
289283}
290284
291285core::PlanNodePtr SubstraitVeloxPlanConverter::toVeloxPlan (
0 commit comments