Skip to content

Commit 6ba1e14

Browse files
zacw7xiaoxmeng
authored andcommitted
[native] Move parseIndexLookupCondition out so it can be reused
1 parent b7fc613 commit 6ba1e14

File tree

2 files changed

+67
-65
lines changed

2 files changed

+67
-65
lines changed

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

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -932,66 +932,6 @@ void VeloxQueryPlanConverterBase::toAggregations(
932932
}
933933
}
934934

935-
void VeloxQueryPlanConverterBase::parseIndexLookupCondition(
936-
const std::shared_ptr<protocol::RowExpression>& filter,
937-
std::vector<core::IndexLookupConditionPtr>& joinConditionPtrs) {
938-
if (const auto andForm = isAnd(filter)) {
939-
VELOX_CHECK_EQ(andForm->arguments.size(), 2);
940-
for (const auto& child : andForm->arguments) {
941-
parseIndexLookupCondition(child, joinConditionPtrs);
942-
}
943-
return;
944-
}
945-
946-
if (const auto between = isBetween(filter)) {
947-
VELOX_CHECK_EQ(between->arguments.size(), 3);
948-
const auto keyColumnExpr = exprConverter_.toVeloxExpr(
949-
std::dynamic_pointer_cast<protocol::VariableReferenceExpression>(
950-
between->arguments[0]));
951-
VELOX_CHECK_NOT_NULL(
952-
keyColumnExpr, "{}", toJsonString(between->arguments[0]));
953-
954-
const auto lowerExpr = exprConverter_.toVeloxExpr(between->arguments[1]);
955-
const auto upperExpr = exprConverter_.toVeloxExpr(between->arguments[2]);
956-
957-
VELOX_CHECK(
958-
!(core::TypedExprs::isConstant(lowerExpr) &&
959-
core::TypedExprs::isConstant(upperExpr)),
960-
"At least one of the between condition bounds needs to be not constant: {}",
961-
toJsonString(filter));
962-
963-
joinConditionPtrs.push_back(
964-
std::make_shared<core::BetweenIndexLookupCondition>(
965-
keyColumnExpr, lowerExpr, upperExpr));
966-
return;
967-
}
968-
969-
if (const auto contains = isContains(filter)) {
970-
VELOX_CHECK_EQ(contains->arguments.size(), 2);
971-
const auto keyColumnExpr = exprConverter_.toVeloxExpr(
972-
std::dynamic_pointer_cast<protocol::VariableReferenceExpression>(
973-
contains->arguments[1]));
974-
VELOX_CHECK_NOT_NULL(
975-
keyColumnExpr, "{}", toJsonString(contains->arguments[1]));
976-
977-
const auto conditionColumnExpr = exprConverter_.toVeloxExpr(
978-
std::dynamic_pointer_cast<protocol::VariableReferenceExpression>(
979-
contains->arguments[0]));
980-
VELOX_CHECK(
981-
!core::TypedExprs::isConstant(conditionColumnExpr),
982-
"The condition column needs to be not constant: {}",
983-
toJsonString(filter));
984-
985-
joinConditionPtrs.push_back(
986-
std::make_shared<core::InIndexLookupCondition>(
987-
keyColumnExpr, conditionColumnExpr));
988-
return;
989-
}
990-
991-
VELOX_UNSUPPORTED(
992-
"Unsupported index lookup condition: {}", toJsonString(filter));
993-
}
994-
995935
std::shared_ptr<const core::ValuesNode>
996936
VeloxQueryPlanConverterBase::toVeloxQueryPlan(
997937
const std::shared_ptr<const protocol::ValuesNode>& node,
@@ -1330,7 +1270,7 @@ VeloxQueryPlanConverterBase::toVeloxQueryPlan(
13301270

13311271
std::vector<core::IndexLookupConditionPtr> joinConditionPtrs{};
13321272
if (node->filter) {
1333-
parseIndexLookupCondition(*node->filter, joinConditionPtrs);
1273+
parseIndexLookupCondition(*node->filter, exprConverter_, joinConditionPtrs);
13341274
}
13351275

13361276
return std::make_shared<core::IndexLookupJoinNode>(
@@ -2349,4 +2289,65 @@ void parseSqlFunctionHandle(
23492289
}
23502290
}
23512291
}
2292+
2293+
void parseIndexLookupCondition(
2294+
const std::shared_ptr<protocol::RowExpression>& filter,
2295+
const VeloxExprConverter& exprConverter,
2296+
std::vector<core::IndexLookupConditionPtr>& joinConditionPtrs) {
2297+
if (const auto andForm = isAnd(filter)) {
2298+
VELOX_CHECK_EQ(andForm->arguments.size(), 2);
2299+
for (const auto& child : andForm->arguments) {
2300+
parseIndexLookupCondition(child, exprConverter, joinConditionPtrs);
2301+
}
2302+
return;
2303+
}
2304+
2305+
if (const auto between = isBetween(filter)) {
2306+
VELOX_CHECK_EQ(between->arguments.size(), 3);
2307+
const auto keyColumnExpr = exprConverter.toVeloxExpr(
2308+
std::dynamic_pointer_cast<protocol::VariableReferenceExpression>(
2309+
between->arguments[0]));
2310+
VELOX_CHECK_NOT_NULL(
2311+
keyColumnExpr, "{}", toJsonString(between->arguments[0]));
2312+
2313+
const auto lowerExpr = exprConverter.toVeloxExpr(between->arguments[1]);
2314+
const auto upperExpr = exprConverter.toVeloxExpr(between->arguments[2]);
2315+
2316+
VELOX_CHECK(
2317+
!(core::TypedExprs::isConstant(lowerExpr) &&
2318+
core::TypedExprs::isConstant(upperExpr)),
2319+
"At least one of the between condition bounds needs to be not constant: {}",
2320+
toJsonString(filter));
2321+
2322+
joinConditionPtrs.push_back(
2323+
std::make_shared<core::BetweenIndexLookupCondition>(
2324+
keyColumnExpr, lowerExpr, upperExpr));
2325+
return;
2326+
}
2327+
2328+
if (const auto contains = isContains(filter)) {
2329+
VELOX_CHECK_EQ(contains->arguments.size(), 2);
2330+
const auto keyColumnExpr = exprConverter.toVeloxExpr(
2331+
std::dynamic_pointer_cast<protocol::VariableReferenceExpression>(
2332+
contains->arguments[1]));
2333+
VELOX_CHECK_NOT_NULL(
2334+
keyColumnExpr, "{}", toJsonString(contains->arguments[1]));
2335+
2336+
const auto conditionColumnExpr = exprConverter.toVeloxExpr(
2337+
std::dynamic_pointer_cast<protocol::VariableReferenceExpression>(
2338+
contains->arguments[0]));
2339+
VELOX_CHECK(
2340+
!core::TypedExprs::isConstant(conditionColumnExpr),
2341+
"The condition column needs to be not constant: {}",
2342+
toJsonString(filter));
2343+
2344+
joinConditionPtrs.push_back(
2345+
std::make_shared<core::InIndexLookupCondition>(
2346+
keyColumnExpr, conditionColumnExpr));
2347+
return;
2348+
}
2349+
2350+
VELOX_UNSUPPORTED(
2351+
"Unsupported index lookup condition: {}", toJsonString(filter));
2352+
}
23522353
} // namespace facebook::presto

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@ class VeloxQueryPlanConverterBase {
227227
std::vector<velox::core::AggregationNode::Aggregate>& aggregates,
228228
std::vector<std::string>& aggregateNames);
229229

230-
void parseIndexLookupCondition(
231-
const std::shared_ptr<protocol::RowExpression>& filter,
232-
std::vector<velox::core::IndexLookupConditionPtr>& joinConditionPtrs);
233-
234230
velox::memory::MemoryPool* const pool_;
235231
velox::core::QueryCtx* const queryCtx_;
236232
VeloxExprConverter exprConverter_;
@@ -295,4 +291,9 @@ void parseSqlFunctionHandle(
295291
const std::shared_ptr<protocol::SqlFunctionHandle>& sqlFunction,
296292
std::vector<velox::TypePtr>& rawInputTypes,
297293
TypeParser& typeParser);
294+
295+
void parseIndexLookupCondition(
296+
const std::shared_ptr<protocol::RowExpression>& filter,
297+
const VeloxExprConverter& exprConverter,
298+
std::vector<velox::core::IndexLookupConditionPtr>& joinConditionPtrs);
298299
} // namespace facebook::presto

0 commit comments

Comments
 (0)