Skip to content

Commit b68bef2

Browse files
fix review
1 parent 4ef3616 commit b68bef2

File tree

1 file changed

+19
-51
lines changed

1 file changed

+19
-51
lines changed

velox/substrait/SubstraitToVeloxPlan.cpp

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,66 +1763,34 @@ core::TypedExprPtr SubstraitVeloxPlanConverter::connectWithAnd(
17631763
auto inputType = ROW(std::move(inputNameList), std::move(inputTypeList));
17641764

17651765
// Filter for scalar functions.
1766-
std::shared_ptr<const core::ITypedExpr> scalarFilter = nullptr;
1767-
if (scalarFunctions.size() > 0) {
1768-
scalarFilter = exprConverter_->toVeloxExpr(scalarFunctions[0], inputType);
1769-
// Will connect multiple functions with AND.
1770-
uint32_t idx = 1;
1771-
while (idx < scalarFunctions.size()) {
1772-
scalarFilter = connectWithAnd(
1773-
scalarFilter,
1774-
exprConverter_->toVeloxExpr(scalarFunctions[idx], inputType));
1775-
idx += 1;
1766+
std::vector<std::shared_ptr<const core::ITypedExpr>> allFilters;
1767+
;
1768+
for (auto scalar : scalarFunctions) {
1769+
auto filter = exprConverter_->toVeloxExpr(scalar, inputType);
1770+
if (filter != nullptr) {
1771+
allFilters.emplace_back(filter);
17761772
}
17771773
}
17781774

1779-
// Filter for OrList.
1780-
std::shared_ptr<const core::ITypedExpr> orListFilter = nullptr;
1781-
if (singularOrLists.size() > 0) {
1782-
orListFilter = exprConverter_->toVeloxExpr(singularOrLists[0], inputType);
1783-
uint32_t idx = 1;
1784-
while (idx < singularOrLists.size()) {
1785-
orListFilter = connectWithAnd(
1786-
orListFilter,
1787-
exprConverter_->toVeloxExpr(singularOrLists[idx], inputType));
1788-
idx += 1;
1775+
for (auto orList : singularOrLists) {
1776+
auto filter = exprConverter_->toVeloxExpr(orList, inputType);
1777+
if (filter != nullptr) {
1778+
allFilters.emplace_back(filter);
17891779
}
17901780
}
17911781

1792-
std::shared_ptr<const core::ITypedExpr> ifThenFilter = nullptr;
1793-
if (ifThens.size() > 0) {
1794-
ifThenFilter = exprConverter_->toVeloxExpr(ifThens[0], inputType);
1795-
uint32_t idx = 1;
1796-
while (idx < ifThens.size()) {
1797-
ifThenFilter = connectWithAnd(
1798-
ifThenFilter, exprConverter_->toVeloxExpr(ifThens[idx], inputType));
1799-
idx += 1;
1782+
for (auto ifThen : ifThens) {
1783+
auto filter = exprConverter_->toVeloxExpr(ifThen, inputType);
1784+
if (filter != nullptr) {
1785+
allFilters.emplace_back(filter);
18001786
}
18011787
}
1802-
1803-
VELOX_CHECK(
1804-
scalarFilter != nullptr || orListFilter != nullptr ||
1805-
ifThenFilter != nullptr,
1806-
"One filter should be valid.");
1807-
if (scalarFilter != nullptr && orListFilter != nullptr) {
1808-
auto filter = connectWithAnd(scalarFilter, orListFilter);
1809-
if (ifThenFilter != nullptr) {
1810-
return connectWithAnd(filter, ifThenFilter);
1811-
}
1812-
return filter;
1813-
} else if (scalarFilter != nullptr) {
1814-
if (ifThenFilter != nullptr) {
1815-
return connectWithAnd(scalarFilter, ifThenFilter);
1816-
}
1817-
return scalarFilter;
1818-
} else if (orListFilter != nullptr) {
1819-
if (ifThenFilter != nullptr) {
1820-
return connectWithAnd(orListFilter, ifThenFilter);
1821-
}
1822-
return orListFilter;
1823-
} else {
1824-
return ifThenFilter;
1788+
VELOX_CHECK_GT(allFilters.size(), 0, "One filter should be valid.")
1789+
std::shared_ptr<const core::ITypedExpr> andFilter = allFilters[0];
1790+
for (auto i = 1; i < allFilters.size(); i++) {
1791+
andFilter = connectWithAnd(andFilter, allFilters[i]);
18251792
}
1793+
return andFilter;
18261794
}
18271795

18281796
core::TypedExprPtr SubstraitVeloxPlanConverter::connectWithAnd(

0 commit comments

Comments
 (0)