Skip to content

Commit

Permalink
add single shortest case
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Aug 4, 2023
1 parent 123f9bd commit e9b6bf7
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 14 deletions.
6 changes: 0 additions & 6 deletions src/graph/executor/query/DataCollectExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ Status DataCollectExecutor::rowBasedMove(const std::vector<std::string>& vars) {
for (; seqIter->valid(); seqIter->next()) {
ds.rows.emplace_back(seqIter->moveRow());
}
} else {
return Status::Error("Iterator should be kind of SequentialIter.");
}
}
result_.setDataSet(std::move(ds));
Expand All @@ -140,10 +138,6 @@ Status DataCollectExecutor::collectAllPaths(const std::vector<std::string>& vars
for (; seqIter->valid(); seqIter->next()) {
ds.rows.emplace_back(seqIter->moveRow());
}
} else {
std::stringstream msg;
msg << "Iterator should be kind of SequentialIter, but was: " << iter->kind();
return Status::Error(msg.str());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/graph/validator/Validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ std::vector<std::string> Validator::getOutColNames() const {
Status Validator::appendPlan(PlanNode* node, PlanNode* appended) {
DCHECK(node != nullptr);
DCHECK(appended != nullptr);
if (node->kind() == PlanNode::Kind::kArgument) {
if (node->kind() == PlanNode::Kind::kArgument || node->kind() == PlanNode::Kind::kHashInnerJoin) {
return Status::OK();
}

Expand Down
21 changes: 15 additions & 6 deletions src/graph/validator/YieldValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,26 @@ Status YieldValidator::validateJoin(const JoinClause *join) {
}

Status YieldValidator::buildJoinPlan() {
PlanNode *leftDep = nullptr;
PlanNode *rightDep = nullptr;
auto *varPtr = qctx_->symTable()->getVar(leftVar_);
std::vector<std::string> colNames = varPtr->colNames;

DCHECK_EQ(varPtr->writtenBy.size(), 1);
for (auto node : varPtr->writtenBy) {
leftDep = node;
}

varPtr = qctx_->symTable()->getVar(rightVar_);
colNames.insert(colNames.end(), varPtr->colNames.begin(), varPtr->colNames.end());
DCHECK_EQ(varPtr->writtenBy.size(), 1);
for (auto node : varPtr->writtenBy) {
rightDep = node;
}

auto *join =
HashInnerJoin::make(qctx_, leftDep, rightDep, {leftConditionExpr_}, {rightConditionExpr_});

auto *join = InnerJoin::make(qctx_,
nullptr,
{leftVar_, ExecutionContext::kLatestVersion},
{rightVar_, ExecutionContext::kLatestVersion},
{leftConditionExpr_},
{rightConditionExpr_});
join->setColNames(std::move(colNames));

auto *project = Project::make(qctx_, join, columns_);
Expand Down
66 changes: 66 additions & 0 deletions tests/tck/features/path/singleShortestPath.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,75 @@ Feature: Single Shortest Path
"""
Then the result should be, in any order, with relax comparison:
| p |
When executing query:
"""
FIND SINGLE SHORTEST PATH FROM "Tim Duncan" TO "Tony Parker" OVER * UPTO 0 STEPS YIELD path as p
"""
Then the result should be, in any order, with relax comparison:
| p |
When executing query:
"""
FIND SINGLE SHORTEST PATH FROM "Tim Duncan", "Yao Ming" TO "Tony Parker", "Spurs" OVER * UPTO 0 STEPS YIELD path as p
"""
Then the result should be, in any order, with relax comparison:
| p |
When executing query:
"""
FIND SINGLE SHORTEST PATH FROM "Tim Duncan", "Yao Ming" TO "Tony Parker", "Spurs" OVER * UPTO -1 STEPS YIELD path as p
"""
Then a SyntaxError should be raised at runtime: syntax error near `-1 STEPS'

Scenario: [1] Single Shortest Path
When executing query:
"""
FIND SHORTEST PATH FROM "Tim Duncan" TO "Tony Parker" OVER * BIDIRECT YIELD path as p
"""
Then the result should be, in any order, with relax comparison:
| p |
| <("Tim Duncan")<-[:like@0 {}]-("Tony Parker")> |
| <("Tim Duncan")<-[:teammate@0 {}]-("Tony Parker")> |
| <("Tim Duncan")-[:like@0 {}]->("Tony Parker")> |
| <("Tim Duncan")-[:teammate@0 {}]->("Tony Parker")> |
When executing query:
"""
FIND SINGLE SHORTEST PATH FROM "Tim Duncan" TO "Tony Parker" OVER * BIDIRECT YIELD path as p
| YIELD startnode($-.p), endnode($-.p)
"""
Then the result should be, in any order, with relax comparison:
| startnode($-.p) | endnode($-.p) |
| ("Tim Duncan") | ("Tony Parker") |

Scenario: [2] Single Shortest Path
When executing query:
"""
FIND SHORTEST PATH FROM "Tim Duncan", "Joel Embiid" TO "Giannis Antetokounmpo", "Yao Ming" OVER * BIDIRECT UPTO 18 STEPS YIELD path as p
"""
Then the result should be, in any order, with relax comparison:
| p |
| <("Tim Duncan")<-[:like@0 {}]-("Shaquille O'Neal")<-[:like@0 {}]-("Yao Ming")> |
| <("Tim Duncan")-[:serve@0 {}]->("Spurs")<-[:serve@0 {}]-("Paul Gasol")-[:serve@0 {}]->("Bucks")<-[:serve@0 {}]-("Giannis Antetokounmpo")> |
| <("Joel Embiid")-[:serve@0 {}]->("76ers")<-[:serve@0 {}]-("Marco Belinelli")-[:like@0 {}]->("Tim Duncan")<-[:like@0 {}]-("Shaquille O'Neal")<-[:like@0 {}]-("Yao Ming")> |
| <("Joel Embiid")-[:serve@0 {}]->("76ers")<-[:serve@0 {}]-("Tiago Splitter")-[:like@0 {}]->("Tim Duncan")<-[:like@0 {}]-("Shaquille O'Neal")<-[:like@0 {}]-("Yao Ming")> |
| <("Joel Embiid")-[:serve@0 {}]->("76ers")<-[:serve@0 {}]-("Jonathon Simmons")-[:serve@0 {}]->("Spurs")<-[:serve@0 {}]-("Tracy McGrady")<-[:like@0 {}]-("Yao Ming")> |
| <("Joel Embiid")-[:serve@0 {}]->("76ers")<-[:serve@0 {}]-("Marco Belinelli")-[:serve@0 {}]->("Spurs")<-[:serve@0 {}]-("Tracy McGrady")<-[:like@0 {}]-("Yao Ming")> |
| <("Joel Embiid")-[:serve@0 {}]->("76ers")<-[:serve@0 {}]-("Marco Belinelli")-[:serve@1 {}]->("Spurs")<-[:serve@0 {}]-("Tracy McGrady")<-[:like@0 {}]-("Yao Ming")> |
| <("Joel Embiid")-[:serve@0 {}]->("76ers")<-[:serve@0 {}]-("Tiago Splitter")-[:serve@0 {}]->("Spurs")<-[:serve@0 {}]-("Tracy McGrady")<-[:like@0 {}]-("Yao Ming")> |
| <("Joel Embiid")-[:serve@0 {}]->("76ers")<-[:serve@0 {}]-("Jonathon Simmons")-[:serve@0 {}]->("Magic")<-[:serve@0 {}]-("Tracy McGrady")<-[:like@0 {}]-("Yao Ming")> |
| <("Joel Embiid")-[:serve@0 {}]->("76ers")<-[:serve@0 {}]-("Jonathon Simmons")-[:serve@0 {}]->("Magic")<-[:serve@0 {}]-("Shaquille O'Neal")<-[:like@0 {}]-("Yao Ming")> |
| <("Joel Embiid")-[:serve@0 {}]->("76ers")<-[:serve@0 {}]-("Marco Belinelli")-[:serve@0 {}]->("Raptors")<-[:serve@0 {}]-("Tracy McGrady")<-[:like@0 {}]-("Yao Ming")> |
| <("Joel Embiid")-[:serve@0 {}]->("76ers")<-[:serve@0 {}]-("Marco Belinelli")-[:serve@0 {}]->("Bulls")<-[:serve@0 {}]-("Paul Gasol")-[:serve@0 {}]->("Bucks")<-[:serve@0 {}]-("Giannis Antetokounmpo")> |
| <("Joel Embiid")-[:serve@0 {}]->("76ers")<-[:serve@0 {}]-("Jonathon Simmons")-[:serve@0 {}]->("Spurs")<-[:serve@0 {}]-("Paul Gasol")-[:serve@0 {}]->("Bucks")<-[:serve@0 {}]-("Giannis Antetokounmpo")> |
| <("Joel Embiid")-[:serve@0 {}]->("76ers")<-[:serve@0 {}]-("Marco Belinelli")-[:serve@0 {}]->("Spurs")<-[:serve@0 {}]-("Paul Gasol")-[:serve@0 {}]->("Bucks")<-[:serve@0 {}]-("Giannis Antetokounmpo")> |
| <("Joel Embiid")-[:serve@0 {}]->("76ers")<-[:serve@0 {}]-("Marco Belinelli")-[:serve@1 {}]->("Spurs")<-[:serve@0 {}]-("Paul Gasol")-[:serve@0 {}]->("Bucks")<-[:serve@0 {}]-("Giannis Antetokounmpo")> |
| <("Joel Embiid")-[:serve@0 {}]->("76ers")<-[:serve@0 {}]-("Tiago Splitter")-[:serve@0 {}]->("Spurs")<-[:serve@0 {}]-("Paul Gasol")-[:serve@0 {}]->("Bucks")<-[:serve@0 {}]-("Giannis Antetokounmpo")> |
When executing query:
"""
FIND SINGLE SHORTEST PATH FROM "Tim Duncan", "Joel Embiid" TO "Giannis Antetokounmpo", "Yao Ming" OVER * BIDIRECT UPTO 18 STEPS YIELD path as p
| YIELD startnode($-.p), endnode($-.p)
"""
Then the result should be, in any order, with relax comparison:
| startnode($-.p) | endnode($-.p) |
| ("Tim Duncan") | ("Yao Ming") |
| ("Tim Duncan") | ("Giannis Antetokounmpo") |
| ("Joel Embiid") | ("Yao Ming") |
| ("Joel Embiid") | ("Giannis Antetokounmpo") |
Loading

0 comments on commit e9b6bf7

Please sign in to comment.