Skip to content

Commit 49d218d

Browse files
marin-maU-CCR\zhenhuiz
authored andcommitted
[OPPRO-10] Enable hash join in Substrait-to-Velox conversion (#9)
* hash join * remove extra projection
1 parent 42ac958 commit 49d218d

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

velox/substrait/SubstraitToVeloxExpr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SubstraitVeloxExprConverter {
2828
/// subParser: A Substrait parser used to convert Substrait representations
2929
/// into recognizable representations. functionMap: A pre-constructed map
3030
/// storing the relations between the function id and the function name.
31-
SubstraitVeloxExprConverter(
31+
explicit SubstraitVeloxExprConverter(
3232
const std::unordered_map<uint64_t, std::string>& functionMap)
3333
: functionMap_(functionMap) {}
3434

velox/substrait/SubstraitToVeloxPlanValidator.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,75 @@ bool SubstraitToVeloxPlanValidator::validate(
115115
return false;
116116
}
117117

118+
bool SubstraitToVeloxPlanValidator::validate(
119+
const ::substrait::JoinRel& sJoin) {
120+
if (sJoin.has_left() && !validate(sJoin.left())) {
121+
return false;
122+
}
123+
if (sJoin.has_right() && !validate(sJoin.right())) {
124+
return false;
125+
}
126+
127+
switch (sJoin.type()) {
128+
case ::substrait::JoinRel_JoinType_JOIN_TYPE_INNER:
129+
case ::substrait::JoinRel_JoinType_JOIN_TYPE_OUTER:
130+
case ::substrait::JoinRel_JoinType_JOIN_TYPE_LEFT:
131+
case ::substrait::JoinRel_JoinType_JOIN_TYPE_RIGHT:
132+
case ::substrait::JoinRel_JoinType_JOIN_TYPE_SEMI:
133+
case ::substrait::JoinRel_JoinType_JOIN_TYPE_ANTI:
134+
break;
135+
default:
136+
return false;
137+
}
138+
139+
// Validate input types.
140+
if (!sJoin.has_advanced_extension()) {
141+
std::cout << "Input types are expected in JoinRel." << std::endl;
142+
return false;
143+
}
144+
145+
const auto& extension = sJoin.advanced_extension();
146+
std::vector<TypePtr> types;
147+
if (!validateInputTypes(extension, types)) {
148+
std::cout << "Validation failed for input types in JoinRel" << std::endl;
149+
return false;
150+
}
151+
152+
int32_t inputPlanNodeId = 0;
153+
std::vector<std::string> names;
154+
names.reserve(types.size());
155+
for (auto colIdx = 0; colIdx < types.size(); colIdx++) {
156+
names.emplace_back(subParser_->makeNodeName(inputPlanNodeId, colIdx));
157+
}
158+
auto rowType = std::make_shared<RowType>(std::move(names), std::move(types));
159+
160+
if (sJoin.has_expression()) {
161+
std::vector<const ::substrait::Expression::FieldReference*> leftExprs,
162+
rightExprs;
163+
try {
164+
planConverter_->extractJoinKeys(
165+
sJoin.expression(), leftExprs, rightExprs);
166+
} catch (const VeloxException& err) {
167+
std::cout << "Validation failed for expression in JoinRel due to:"
168+
<< err.message() << std::endl;
169+
return false;
170+
}
171+
}
172+
173+
if (sJoin.has_post_join_filter()) {
174+
try {
175+
auto expression =
176+
exprConverter_->toVeloxExpr(sJoin.post_join_filter(), rowType);
177+
exec::ExprSet exprSet({std::move(expression)}, &execCtx_);
178+
} catch (const VeloxException& err) {
179+
std::cout << "Validation failed for expression in ProjectRel due to:"
180+
<< err.message() << std::endl;
181+
return false;
182+
}
183+
}
184+
return true;
185+
}
186+
118187
bool SubstraitToVeloxPlanValidator::validate(
119188
const ::substrait::AggregateRel& sAgg) {
120189
if (sAgg.has_input() && !validate(sAgg.input())) {
@@ -304,6 +373,9 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::Rel& sRel) {
304373
if (sRel.has_filter()) {
305374
return validate(sRel.filter());
306375
}
376+
if (sRel.has_join()) {
377+
return validate(sRel.join());
378+
}
307379
if (sRel.has_read()) {
308380
return validate(sRel.read());
309381
}

velox/substrait/SubstraitToVeloxPlanValidator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class SubstraitToVeloxPlanValidator {
3636
/// Used to validate whether the computing of this Filter is supported.
3737
bool validate(const ::substrait::FilterRel& sFilter);
3838

39+
/// Used to validate Join.
40+
bool validate(const ::substrait::JoinRel& sJoin);
41+
3942
/// Used to validate whether the computing of this Read is supported.
4043
bool validate(const ::substrait::ReadRel& sRead);
4144

0 commit comments

Comments
 (0)