Skip to content

Commit

Permalink
fix to edge type
Browse files Browse the repository at this point in the history
  • Loading branch information
jievince committed Dec 7, 2022
1 parent efcacb6 commit 11b6a55
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
14 changes: 11 additions & 3 deletions src/graph/optimizer/rule/PushEFilterDownRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ StatusOr<OptRule::TransformResult> PushEFilterDownRule::transform(
auto pool = qctx->objPool();
auto eFilter = traverse->eFilter()->clone();

eFilter = rewriteStarEdge(
eFilter, traverse->space(), *DCHECK_NOTNULL(traverse->edgeProps()), qctx->schemaMng(), pool);
eFilter = rewriteStarEdge(eFilter,
traverse->space(),
*DCHECK_NOTNULL(traverse->edgeProps()),
qctx->schemaMng(),
traverse->edgeDirection() == storage::cpp2::EdgeDirection::BOTH,
pool);
if (eFilter == nullptr) {
return TransformResult::noTransform();
}
Expand Down Expand Up @@ -93,6 +97,7 @@ std::string PushEFilterDownRule::toString() const {
GraphSpaceID spaceId,
const std::vector<storage::cpp2::EdgeProp> &edges,
meta::SchemaManager *schemaMng,
bool isBothDirection,
ObjectPool *pool) {
graph::RewriteVisitor::Matcher matcher = [](const Expression *exp) -> bool {
switch (exp->kind()) {
Expand All @@ -113,7 +118,7 @@ std::string PushEFilterDownRule::toString() const {
}
};
graph::RewriteVisitor::Rewriter rewriter =
[spaceId, &edges, schemaMng, pool](const Expression *exp) -> Expression * {
[spaceId, &edges, schemaMng, isBothDirection, pool](const Expression *exp) -> Expression * {
auto *propertyExpr = static_cast<const PropertyExpression *>(exp);
DCHECK_EQ(propertyExpr->sym(), "*");
DCHECK(!edges.empty());
Expand All @@ -126,6 +131,9 @@ std::string PushEFilterDownRule::toString() const {
} else {
auto args = ArgumentList::make(pool);
for (auto &edge : edges) {
if (isBothDirection && edge.get_type() < 0) {
continue;
}
auto reEdgeExp = rewriteStarEdge(propertyExpr, spaceId, edge, schemaMng, pool);
if (reEdgeExp == nullptr) {
return nullptr;
Expand Down
1 change: 1 addition & 0 deletions src/graph/optimizer/rule/PushEFilterDownRule.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class PushEFilterDownRule final : public OptRule {
GraphSpaceID spaceId,
const std::vector<storage::cpp2::EdgeProp> &edges,
meta::SchemaManager *schemaMng,
bool isBothDirection,
ObjectPool *pool);
static Expression *rewriteStarEdge(const PropertyExpression *exp,
GraphSpaceID spaceId,
Expand Down
14 changes: 7 additions & 7 deletions tests/tck/features/optimizer/PushEFilterDownRule.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Feature: Push EFilter down rule
Then the result should be, in any order:
| name |
| "Tim Duncan" |
| "Tim Duncan" |
And the execution plan should be:
| id | name | dependencies | operator info |
| 5 | Project | 8 | |
Expand All @@ -41,18 +40,19 @@ Feature: Push EFilter down rule
| 0 | Start | | |
When profiling query:
"""
MATCH (v:player{name: 'Tim Duncan'})-[e:like{likeness: 95}]-() return v.player.name AS name
MATCH (v:player{name: 'Tim Duncan'})-[e:like|serve{likeness: 95}]-() return v.player.name AS name
"""
Then the result should be, in any order:
| name |
| "Tim Duncan" |
| "Tim Duncan" |
| "Tim Duncan" |
And the execution plan should be:
| id | name | dependencies | operator info |
| 5 | Project | 8 | |
| 8 | Traverse | 7 | {"edge filter": "", "filter": "(like.likeness==95)"} |
| 7 | IndexScan | 0 | |
| 0 | Start | | |
| id | name | dependencies | operator info |
| 5 | Project | 8 | |
| 8 | Traverse | 7 | {"edge filter": "", "filter": "(_any(like.likeness,serve.likeness)==95)"} |
| 7 | IndexScan | 0 | |
| 0 | Start | | |
When profiling query:
"""
MATCH (v:player{name: 'Tim Duncan'})-[e:like*1..2{likeness: 95}]->() return v.player.name AS name
Expand Down

0 comments on commit 11b6a55

Please sign in to comment.