Skip to content

Commit

Permalink
Add ut for testing push down function.
Browse files Browse the repository at this point in the history
  • Loading branch information
CPWstatic committed Dec 20, 2019
1 parent d032a78 commit 9c93643
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 29 deletions.
34 changes: 5 additions & 29 deletions src/graph/TraverseExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,33 +353,12 @@ bool WhereWrapper::rewrite(Expression *expr) const {
return false;
}
}
case Expression::kUnary: {
auto *unaExpr = static_cast<UnaryExpression*>(expr);
return rewrite(const_cast<Expression*>(unaExpr->operand()));
}
case Expression::kTypeCasting: {
auto *typExpr = static_cast<TypeCastingExpression*>(expr);
return rewrite(const_cast<Expression*>(typExpr->operand()));
}
case Expression::kArithmetic: {
auto *ariExp = static_cast<ArithmeticExpression*>(expr);
return rewrite(const_cast<Expression*>(ariExp->left()))
&& rewrite(const_cast<Expression*>(ariExp->right()));
}
case Expression::kRelational: {
auto *relExp = static_cast<RelationalExpression*>(expr);
return rewrite(const_cast<Expression*>(relExp->left()))
&& rewrite(const_cast<Expression*>(relExp->right()));
}
case Expression::kUnary:
case Expression::kTypeCasting:
case Expression::kArithmetic:
case Expression::kRelational:
case Expression::kFunctionCall: {
auto *funcExp = static_cast<FunctionCallExpression*>(expr);
auto &args = funcExp->args();
for (auto &arg : args) {
if (!rewrite(arg)) {
return false;
}
}
return true;
return canPushdown(expr);
}
case Expression::kPrimary:
case Expression::kSourceProp:
Expand All @@ -405,9 +384,6 @@ bool WhereWrapper::rewrite(Expression *expr) const {
}

bool WhereWrapper::canPushdown(Expression *expr) const {
if (expr->isFunCallExpression()) {
return false;
}
auto ectx = std::make_unique<ExpressionContext>();
expr->setContext(ectx.get());
auto status = expr->prepare();
Expand Down
90 changes: 90 additions & 0 deletions src/graph/test/GoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,96 @@ TEST_P(GoTest, FilterPushdown) {
std::vector<std::tuple<int64_t>> expected;
ASSERT_TRUE(verifyResult(resp, expected));
}
{
auto *fmt = "GO FROM %ld OVER serve "
"WHERE udf_is_in(serve._dst, %ld, 2, 3)";
auto query = folly::stringPrintf(fmt,
players_["Rajon Rondo"].vid(), teams_["Celtics"].vid());

TEST_FILTER_PUSHDOWN_REWRITE(
true,
folly::stringPrintf("udf_is_in(serve._dst,%ld,2,3)", teams_["Celtics"].vid()));

cpp2::ExecutionResponse resp;
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());

std::vector<std::string> expectedColNames{
{"serve._dst"}
};
ASSERT_TRUE(verifyColNames(resp, expectedColNames));

std::vector<std::tuple<int64_t>> expected = {
{teams_["Celtics"].vid()}
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
auto *fmt = "GO FROM %ld OVER serve "
"WHERE udf_is_in(\"test\", $$.team.name)";
auto query = folly::stringPrintf(fmt, players_["Rajon Rondo"].vid());

TEST_FILTER_PUSHDOWN_REWRITE(
false,
"");

cpp2::ExecutionResponse resp;
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());

std::vector<std::string> expectedColNames{
{"serve._dst"}
};
ASSERT_TRUE(verifyColNames(resp, expectedColNames));

std::vector<std::tuple<int64_t>> expected;
ASSERT_TRUE(verifyResult(resp, expected));
}
{
auto *fmt = "GO FROM %ld OVER serve "
"WHERE udf_is_in($^.player.name, \"Tim Duncan\")";
auto query = folly::stringPrintf(fmt, players_["Tim Duncan"].vid());

TEST_FILTER_PUSHDOWN_REWRITE(
true,
"udf_is_in($^.player.name,Tim Duncan)");

cpp2::ExecutionResponse resp;
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());

std::vector<std::string> expectedColNames{
{"serve._dst"}
};
ASSERT_TRUE(verifyColNames(resp, expectedColNames));

std::vector<std::tuple<int64_t>> expected = {
{teams_["Spurs"].vid()}
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
auto *fmt = "GO FROM %ld OVER serve "
"WHERE !udf_is_in($^.player.name, \"Tim Duncan\")";
auto query = folly::stringPrintf(fmt, players_["Tim Duncan"].vid());

TEST_FILTER_PUSHDOWN_REWRITE(
true,
"!(udf_is_in($^.player.name,Tim Duncan))");

cpp2::ExecutionResponse resp;
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());

std::vector<std::string> expectedColNames{
{"serve._dst"}
};
ASSERT_TRUE(verifyColNames(resp, expectedColNames));

std::vector<std::tuple<int64_t>> expected;
ASSERT_TRUE(verifyResult(resp, expected));
}

#undef TEST_FILTER_PUSHDWON_REWRITE
}

Expand Down

0 comments on commit 9c93643

Please sign in to comment.