Skip to content
Snippets Groups Projects
Unverified Commit ad355b58 authored by jimingquan's avatar jimingquan Committed by GitHub
Browse files

Remove redundant project&dedup in findpath & fix path error (#912)


* remove redundant project&dedup in findpath

* fix path error & add testcase

* add testcase

Co-authored-by: default avatarYee <2520865+yixinglu@users.noreply.github.com>
parent 53aec708
No related branches found
No related tags found
No related merge requests found
...@@ -58,3 +58,6 @@ workspace.* ...@@ -58,3 +58,6 @@ workspace.*
*.py[co] *.py[co]
__pycache__ __pycache__
venv/ venv/
#lock
*.lock
...@@ -33,6 +33,9 @@ folly::Future<Status> ConjunctPathExecutor::bfsShortestPath() { ...@@ -33,6 +33,9 @@ folly::Future<Status> ConjunctPathExecutor::bfsShortestPath() {
<< " right input: " << conjunct->rightInputVar(); << " right input: " << conjunct->rightInputVar();
DCHECK(!!lIter); DCHECK(!!lIter);
auto steps = conjunct->steps();
count_++;
DataSet ds; DataSet ds;
ds.colNames = conjunct->colNames(); ds.colNames = conjunct->colNames();
...@@ -62,14 +65,16 @@ folly::Future<Status> ConjunctPathExecutor::bfsShortestPath() { ...@@ -62,14 +65,16 @@ folly::Future<Status> ConjunctPathExecutor::bfsShortestPath() {
} }
} }
auto latest = rHist.back().iter(); if (count_ * 2 <= steps) {
isLatest = true; auto latest = rHist.back().iter();
backward_.emplace_back(); isLatest = true;
VLOG(1) << "Find even length path."; backward_.emplace_back();
auto rows = findBfsShortestPath(latest.get(), isLatest, forward_.back()); VLOG(1) << "Find even length path.";
if (!rows.empty()) { auto rows = findBfsShortestPath(latest.get(), isLatest, forward_.back());
VLOG(1) << "Meet even length path."; if (!rows.empty()) {
ds.rows = std::move(rows); VLOG(1) << "Meet even length path.";
ds.rows = std::move(rows);
}
} }
return finish(ResultBuilder().value(Value(std::move(ds))).finish()); return finish(ResultBuilder().value(Value(std::move(ds))).finish());
} }
...@@ -77,7 +82,7 @@ folly::Future<Status> ConjunctPathExecutor::bfsShortestPath() { ...@@ -77,7 +82,7 @@ folly::Future<Status> ConjunctPathExecutor::bfsShortestPath() {
std::vector<Row> ConjunctPathExecutor::findBfsShortestPath( std::vector<Row> ConjunctPathExecutor::findBfsShortestPath(
Iterator* iter, Iterator* iter,
bool isLatest, bool isLatest,
std::multimap<Value, const Edge*>& table) { std::unordered_multimap<Value, const Edge*>& table) {
std::unordered_set<Value> meets; std::unordered_set<Value> meets;
for (; iter->valid(); iter->next()) { for (; iter->valid(); iter->next()) {
auto& dst = iter->getColumn(kVid); auto& dst = iter->getColumn(kVid);
...@@ -118,10 +123,10 @@ std::vector<Row> ConjunctPathExecutor::findBfsShortestPath( ...@@ -118,10 +123,10 @@ std::vector<Row> ConjunctPathExecutor::findBfsShortestPath(
return rows; return rows;
} }
std::multimap<Value, Path> ConjunctPathExecutor::buildBfsInterimPath( std::unordered_multimap<Value, Path> ConjunctPathExecutor::buildBfsInterimPath(
std::unordered_set<Value>& meets, std::unordered_set<Value>& meets,
std::vector<std::multimap<Value, const Edge*>>& hists) { std::vector<std::unordered_multimap<Value, const Edge*>>& hists) {
std::multimap<Value, Path> results; std::unordered_multimap<Value, Path> results;
for (auto& v : meets) { for (auto& v : meets) {
VLOG(1) << "Meet at: " << v; VLOG(1) << "Meet at: " << v;
Path start; Path start;
...@@ -205,7 +210,7 @@ folly::Future<Status> ConjunctPathExecutor::floydShortestPath() { ...@@ -205,7 +210,7 @@ folly::Future<Status> ConjunctPathExecutor::floydShortestPath() {
findPath(previous.get(), forwardCostPathMap, ds); findPath(previous.get(), forwardCostPathMap, ds);
} }
if (count_ * 2 < steps) { if (count_ * 2 <= steps) {
VLOG(1) << "Find even length path."; VLOG(1) << "Find even length path.";
auto latest = rHist.back().iter(); auto latest = rHist.back().iter();
findPath(latest.get(), forwardCostPathMap, ds); findPath(latest.get(), forwardCostPathMap, ds);
...@@ -224,7 +229,7 @@ Status ConjunctPathExecutor::conjunctPath(const List& forwardPaths, ...@@ -224,7 +229,7 @@ Status ConjunctPathExecutor::conjunctPath(const List& forwardPaths,
} }
for (auto& j : backwardPaths.values) { for (auto& j : backwardPaths.values) {
if (!j.isPath()) { if (!j.isPath()) {
return Status::Error("Forward Path Type Error"); return Status::Error("Backward Path Type Error");
} }
Row row; Row row;
auto forward = i.getPath(); auto forward = i.getPath();
......
...@@ -33,11 +33,11 @@ private: ...@@ -33,11 +33,11 @@ private:
std::vector<Row> findBfsShortestPath(Iterator* iter, std::vector<Row> findBfsShortestPath(Iterator* iter,
bool isLatest, bool isLatest,
std::multimap<Value, const Edge*>& table); std::unordered_multimap<Value, const Edge*>& table);
std::multimap<Value, Path> buildBfsInterimPath( std::unordered_multimap<Value, Path> buildBfsInterimPath(
std::unordered_set<Value>& meets, std::unordered_set<Value>& meets,
std::vector<std::multimap<Value, const Edge*>>& hist); std::vector<std::unordered_multimap<Value, const Edge*>>& hist);
folly::Future<Status> floydShortestPath(); folly::Future<Status> floydShortestPath();
...@@ -54,8 +54,8 @@ private: ...@@ -54,8 +54,8 @@ private:
void delPathFromConditionalVar(const Value& start, const Value& end); void delPathFromConditionalVar(const Value& start, const Value& end);
private: private:
std::vector<std::multimap<Value, const Edge*>> forward_; std::vector<std::unordered_multimap<Value, const Edge*>> forward_;
std::vector<std::multimap<Value, const Edge*>> backward_; std::vector<std::unordered_multimap<Value, const Edge*>> backward_;
size_t count_{0}; size_t count_{0};
// startVid : {endVid, cost} // startVid : {endVid, cost}
std::unordered_map<Value, std::unordered_map<Value, Value>> historyCostMap_; std::unordered_map<Value, std::unordered_map<Value, Value>> historyCostMap_;
......
...@@ -56,18 +56,14 @@ Status FindPathValidator::singlePairPlan() { ...@@ -56,18 +56,14 @@ Status FindPathValidator::singlePairPlan() {
auto* bodyStart = StartNode::make(qctx_); auto* bodyStart = StartNode::make(qctx_);
auto* passThrough = PassThroughNode::make(qctx_, bodyStart); auto* passThrough = PassThroughNode::make(qctx_, bodyStart);
std::string fromPathVar; auto* forward = bfs(passThrough, from_, false);
auto* forward = bfs(passThrough, from_, fromPathVar, false); VLOG(1) << "forward: " << forward->outputVar();
VLOG(1) << "forward: " << fromPathVar;
std::string toPathVar; auto* backward = bfs(passThrough, to_, true);
auto* backward = bfs(passThrough, to_, toPathVar, true); VLOG(1) << "backward: " << backward->outputVar();
VLOG(1) << "backward: " << toPathVar;
auto* conjunct = auto* conjunct =
ConjunctPath::make(qctx_, forward, backward, ConjunctPath::PathKind::kBiBFS, steps_.steps); ConjunctPath::make(qctx_, forward, backward, ConjunctPath::PathKind::kBiBFS, steps_.steps);
conjunct->setLeftVar(fromPathVar);
conjunct->setRightVar(toPathVar);
conjunct->setColNames({"_path"}); conjunct->setColNames({"_path"});
auto* loop = Loop::make( auto* loop = Loop::make(
...@@ -82,45 +78,28 @@ Status FindPathValidator::singlePairPlan() { ...@@ -82,45 +78,28 @@ Status FindPathValidator::singlePairPlan() {
return Status::OK(); return Status::OK();
} }
PlanNode* FindPathValidator::bfs(PlanNode* dep, PlanNode* FindPathValidator::bfs(PlanNode* dep, Starts& starts, bool reverse) {
Starts& starts,
std::string& pathVar,
bool reverse) {
std::string startVidsVar; std::string startVidsVar;
buildConstantInput(starts, startVidsVar); buildConstantInput(starts, startVidsVar);
auto* gn = GetNeighbors::make(qctx_, dep, space_.id); auto* gn = GetNeighbors::make(qctx_, dep, space_.id);
gn->setSrc(starts.src); gn->setSrc(starts.src);
gn->setEdgeProps(buildEdgeKey(reverse)); gn->setEdgeProps(buildEdgeKey(reverse));
gn->setDedup();
gn->setInputVar(startVidsVar); gn->setInputVar(startVidsVar);
auto* bfs = BFSShortestPath::make(qctx_, gn); auto* bfs = BFSShortestPath::make(qctx_, gn);
bfs->setColNames({"_vid", "edge"}); bfs->setOutputVar(startVidsVar);
pathVar = bfs->outputVar(); bfs->setColNames({nebula::kVid, "edge"});
auto* columns = qctx_->objPool()->add(new YieldColumns());
auto* column =
new YieldColumn(new VariablePropertyExpression(new std::string("*"), new std::string(kVid)),
new std::string(kVid));
columns->addColumn(column);
auto* project = Project::make(qctx_, bfs, columns);
project->setColNames(deduceColNames(columns));
auto* dedup = Dedup::make(qctx_, project);
auto* startVidsVarPtr = qctx_->symTable()->getVar(startVidsVar);
startVidsVarPtr->colNames = project->colNames();
dedup->setOutputVar(startVidsVar);
DataSet ds; DataSet ds;
ds.colNames = {"_vid", "edge"}; ds.colNames = {nebula::kVid, "edge"};
Row row; Row row;
row.values.emplace_back(starts.vids.front()); row.values.emplace_back(starts.vids.front());
row.values.emplace_back(Value::kEmpty); row.values.emplace_back(Value::kEmpty);
ds.rows.emplace_back(std::move(row)); ds.rows.emplace_back(std::move(row));
qctx_->ectx()->setResult(pathVar, ResultBuilder().value(Value(std::move(ds))).finish()); qctx_->ectx()->setResult(startVidsVar, ResultBuilder().value(Value(std::move(ds))).finish());
return dedup; return bfs;
} }
Expression* FindPathValidator::buildBfsLoopCondition(uint32_t steps, const std::string& pathVar) { Expression* FindPathValidator::buildBfsLoopCondition(uint32_t steps, const std::string& pathVar) {
...@@ -186,9 +165,7 @@ GetNeighbors::EdgeProps FindPathValidator::buildEdgeKey(bool reverse) { ...@@ -186,9 +165,7 @@ GetNeighbors::EdgeProps FindPathValidator::buildEdgeKey(bool reverse) {
return edgeProps; return edgeProps;
} }
PlanNode* FindPathValidator::buildAllPairFirstDataSet(PlanNode* dep, PlanNode* FindPathValidator::buildAllPairFirstDataSet(PlanNode* dep, const std::string& inputVar) {
const std::string& inputVar,
const std::string& outputVar) {
auto* vid = auto* vid =
new YieldColumn(new VariablePropertyExpression(new std::string("*"), new std::string(kVid)), new YieldColumn(new VariablePropertyExpression(new std::string("*"), new std::string(kVid)),
new std::string(kVid)); new std::string(kVid));
...@@ -206,9 +183,9 @@ PlanNode* FindPathValidator::buildAllPairFirstDataSet(PlanNode* dep, ...@@ -206,9 +183,9 @@ PlanNode* FindPathValidator::buildAllPairFirstDataSet(PlanNode* dep,
auto* project = Project::make(qctx_, dep, columns); auto* project = Project::make(qctx_, dep, columns);
project->setInputVar(inputVar); project->setInputVar(inputVar);
auto* outputVarPtr = qctx_->symTable()->getVar(outputVar); auto* outputVarPtr = qctx_->symTable()->getVar(inputVar);
outputVarPtr->colNames = {kVid, "path"}; outputVarPtr->colNames = {nebula::kVid, "path"};
project->setOutputVar(outputVar); project->setOutputVar(inputVar);
return project; return project;
} }
...@@ -218,28 +195,25 @@ Status FindPathValidator::allPairPaths() { ...@@ -218,28 +195,25 @@ Status FindPathValidator::allPairPaths() {
std::string fromStartVidsVar; std::string fromStartVidsVar;
buildStart(from_, fromStartVidsVar, false); buildStart(from_, fromStartVidsVar, false);
std::string fromPathVar;
auto* forward = allPaths(passThrough, from_, fromStartVidsVar, fromPathVar, false); auto* forward = allPaths(passThrough, from_, fromStartVidsVar, false);
VLOG(1) << "forward: " << fromPathVar; VLOG(1) << "forward: " << forward->outputVar();
std::string toStartVidsVar; std::string toStartVidsVar;
buildStart(to_, toStartVidsVar, true); buildStart(to_, toStartVidsVar, true);
std::string toPathVar; auto* backward = allPaths(passThrough, to_, toStartVidsVar, true);
auto* backward = allPaths(passThrough, to_, toStartVidsVar, toPathVar, true); VLOG(1) << "backward: " << backward->outputVar();
VLOG(1) << "backward: " << toPathVar;
auto* conjunct = ConjunctPath::make( auto* conjunct = ConjunctPath::make(
qctx_, forward, backward, ConjunctPath::PathKind::kAllPaths, steps_.steps); qctx_, forward, backward, ConjunctPath::PathKind::kAllPaths, steps_.steps);
conjunct->setLeftVar(fromPathVar);
conjunct->setRightVar(toPathVar);
conjunct->setColNames({"_path"}); conjunct->setColNames({"_path"});
conjunct->setNoLoop(noLoop_); conjunct->setNoLoop(noLoop_);
PlanNode* projectFromDep = nullptr; PlanNode* projectFromDep = nullptr;
linkLoopDepFromTo(projectFromDep); linkLoopDepFromTo(projectFromDep);
auto* projectFrom = buildAllPairFirstDataSet(projectFromDep, fromStartVidsVar, fromPathVar); auto* projectFrom = buildAllPairFirstDataSet(projectFromDep, fromStartVidsVar);
auto* projectTo = buildAllPairFirstDataSet(projectFrom, toStartVidsVar, toPathVar); auto* projectTo = buildAllPairFirstDataSet(projectFrom, toStartVidsVar);
auto* loop = auto* loop =
Loop::make(qctx_, projectTo, conjunct, buildAllPathsLoopCondition(steps_.steps)); Loop::make(qctx_, projectTo, conjunct, buildAllPathsLoopCondition(steps_.steps));
...@@ -256,31 +230,17 @@ Status FindPathValidator::allPairPaths() { ...@@ -256,31 +230,17 @@ Status FindPathValidator::allPairPaths() {
PlanNode* FindPathValidator::allPaths(PlanNode* dep, PlanNode* FindPathValidator::allPaths(PlanNode* dep,
Starts& starts, Starts& starts,
std::string& startVidsVar, std::string& startVidsVar,
std::string& pathVar,
bool reverse) { bool reverse) {
auto* gn = GetNeighbors::make(qctx_, dep, space_.id); auto* gn = GetNeighbors::make(qctx_, dep, space_.id);
gn->setSrc(starts.src); gn->setSrc(starts.src);
gn->setEdgeProps(buildEdgeKey(reverse)); gn->setEdgeProps(buildEdgeKey(reverse));
gn->setInputVar(startVidsVar); gn->setInputVar(startVidsVar);
gn->setDedup();
auto* allPaths = ProduceAllPaths::make(qctx_, gn); auto* allPaths = ProduceAllPaths::make(qctx_, gn);
allPaths->setColNames({kVid, "path"}); allPaths->setOutputVar(startVidsVar);
pathVar = allPaths->outputVar(); allPaths->setColNames({nebula::kVid, "path"});
return allPaths;
auto* columns = qctx_->objPool()->add(new YieldColumns());
auto* column =
new YieldColumn(new VariablePropertyExpression(new std::string("*"), new std::string(kVid)),
new std::string(kVid));
columns->addColumn(column);
auto* project = Project::make(qctx_, allPaths, columns);
project->setColNames(deduceColNames(columns));
auto* dedup = Dedup::make(qctx_, project);
auto* startVidsVarPtr = qctx_->symTable()->getVar(startVidsVar);
startVidsVarPtr->colNames = project->colNames();
dedup->setOutputVar(startVidsVar);
return dedup;
} }
Expression* FindPathValidator::buildAllPathsLoopCondition(uint32_t steps) { Expression* FindPathValidator::buildAllPathsLoopCondition(uint32_t steps) {
...@@ -419,9 +379,10 @@ PlanNode* FindPathValidator::multiPairShortestPath(PlanNode* dep, ...@@ -419,9 +379,10 @@ PlanNode* FindPathValidator::multiPairShortestPath(PlanNode* dep,
gn->setSrc(starts.src); gn->setSrc(starts.src);
gn->setEdgeProps(buildEdgeKey(reverse)); gn->setEdgeProps(buildEdgeKey(reverse));
gn->setInputVar(startVidsVar); gn->setInputVar(startVidsVar);
gn->setDedup();
auto* pssp = ProduceSemiShortestPath::make(qctx_, gn); auto* pssp = ProduceSemiShortestPath::make(qctx_, gn);
pssp->setColNames({kDst, kSrc, "cost", "paths"}); pssp->setColNames({nebula::kDst, nebula::kSrc, "cost", "paths"});
pathVar = pssp->outputVar(); pathVar = pssp->outputVar();
auto* columns = qctx_->objPool()->add(new YieldColumns()); auto* columns = qctx_->objPool()->add(new YieldColumns());
...@@ -430,14 +391,10 @@ PlanNode* FindPathValidator::multiPairShortestPath(PlanNode* dep, ...@@ -430,14 +391,10 @@ PlanNode* FindPathValidator::multiPairShortestPath(PlanNode* dep,
new std::string(kVid)); new std::string(kVid));
columns->addColumn(column); columns->addColumn(column);
auto* project = Project::make(qctx_, pssp, columns); auto* project = Project::make(qctx_, pssp, columns);
project->setOutputVar(startVidsVar);
project->setColNames(deduceColNames(columns)); project->setColNames(deduceColNames(columns));
auto* dedup = Dedup::make(qctx_, project); return project;
auto* startVidsVarPtr = qctx_->symTable()->getVar(startVidsVar);
startVidsVarPtr->colNames = project->colNames();
dedup->setOutputVar(startVidsVar);
return dedup;
} }
Expression* FindPathValidator::buildMultiPairLoopCondition(uint32_t steps, Expression* FindPathValidator::buildMultiPairLoopCondition(uint32_t steps,
......
...@@ -28,20 +28,14 @@ private: ...@@ -28,20 +28,14 @@ private:
void linkLoopDepFromTo(PlanNode*& projectDep); void linkLoopDepFromTo(PlanNode*& projectDep);
// bfs // bfs
Status singlePairPlan(); Status singlePairPlan();
PlanNode* bfs(PlanNode* dep, Starts& starts, std::string& pathVar, bool reverse); PlanNode* bfs(PlanNode* dep, Starts& starts, bool reverse);
Expression* buildBfsLoopCondition(uint32_t steps, const std::string& pathVar); Expression* buildBfsLoopCondition(uint32_t steps, const std::string& pathVar);
// allPath // allPath
Status allPairPaths(); Status allPairPaths();
PlanNode* allPaths(PlanNode* dep, PlanNode* allPaths(PlanNode* dep, Starts& starts, std::string& startVidsVar, bool reverse);
Starts& starts,
std::string& startVidsVar,
std::string& pathVar,
bool reverse);
Expression* buildAllPathsLoopCondition(uint32_t steps); Expression* buildAllPathsLoopCondition(uint32_t steps);
PlanNode* buildAllPairFirstDataSet(PlanNode* dep, PlanNode* buildAllPairFirstDataSet(PlanNode* dep, const std::string& inputVar);
const std::string& inputVar,
const std::string& outputVar);
// multi-pair // multi-pair
Status multiPairPlan(); Status multiPairPlan();
......
...@@ -27,10 +27,6 @@ TEST_F(FindPathValidatorTest, SinglePairPath) { ...@@ -27,10 +27,6 @@ TEST_F(FindPathValidatorTest, SinglePairPath) {
PK::kLoop, PK::kLoop,
PK::kStart, PK::kStart,
PK::kConjunctPath, PK::kConjunctPath,
PK::kDedup,
PK::kDedup,
PK::kProject,
PK::kProject,
PK::kBFSShortest, PK::kBFSShortest,
PK::kBFSShortest, PK::kBFSShortest,
PK::kGetNeighbors, PK::kGetNeighbors,
...@@ -47,30 +43,6 @@ TEST_F(FindPathValidatorTest, SinglePairPath) { ...@@ -47,30 +43,6 @@ TEST_F(FindPathValidatorTest, SinglePairPath) {
PK::kLoop, PK::kLoop,
PK::kStart, PK::kStart,
PK::kConjunctPath, PK::kConjunctPath,
PK::kDedup,
PK::kDedup,
PK::kProject,
PK::kProject,
PK::kBFSShortest,
PK::kBFSShortest,
PK::kGetNeighbors,
PK::kGetNeighbors,
PK::kPassThrough,
PK::kStart,
};
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query = "FIND SHORTEST PATH FROM \"1\" TO \"2\" OVER * UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kDataCollect,
PK::kLoop,
PK::kStart,
PK::kConjunctPath,
PK::kDedup,
PK::kDedup,
PK::kProject,
PK::kProject,
PK::kBFSShortest, PK::kBFSShortest,
PK::kBFSShortest, PK::kBFSShortest,
PK::kGetNeighbors, PK::kGetNeighbors,
...@@ -91,37 +63,12 @@ TEST_F(FindPathValidatorTest, MultiPairPath) { ...@@ -91,37 +63,12 @@ TEST_F(FindPathValidatorTest, MultiPairPath) {
PK::kCartesianProduct, PK::kCartesianProduct,
PK::kConjunctPath, PK::kConjunctPath,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kProject, PK::kProject,
PK::kProject, PK::kProject,
PK::kProject, PK::kProject,
PK::kStart,
PK::kProduceSemiShortestPath, PK::kProduceSemiShortestPath,
PK::kProduceSemiShortestPath, PK::kProduceSemiShortestPath,
PK::kGetNeighbors,
PK::kGetNeighbors,
PK::kPassThrough,
PK::kStart, PK::kStart,
};
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query = "FIND SHORTEST PATH FROM \"1\" TO \"2\",\"3\" OVER *";
std::vector<PlanNode::Kind> expected = {
PK::kDataCollect,
PK::kLoop,
PK::kCartesianProduct,
PK::kConjunctPath,
PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kProject,
PK::kProject,
PK::kProject,
PK::kStart,
PK::kProduceSemiShortestPath,
PK::kProduceSemiShortestPath,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kPassThrough, PK::kPassThrough,
...@@ -138,14 +85,12 @@ TEST_F(FindPathValidatorTest, MultiPairPath) { ...@@ -138,14 +85,12 @@ TEST_F(FindPathValidatorTest, MultiPairPath) {
PK::kCartesianProduct, PK::kCartesianProduct,
PK::kConjunctPath, PK::kConjunctPath,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kProject, PK::kProject,
PK::kProject, PK::kProject,
PK::kProject, PK::kProject,
PK::kStart,
PK::kProduceSemiShortestPath, PK::kProduceSemiShortestPath,
PK::kProduceSemiShortestPath, PK::kProduceSemiShortestPath,
PK::kStart,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kPassThrough, PK::kPassThrough,
...@@ -164,35 +109,9 @@ TEST_F(FindPathValidatorTest, ALLPath) { ...@@ -164,35 +109,9 @@ TEST_F(FindPathValidatorTest, ALLPath) {
PK::kProject, PK::kProject,
PK::kConjunctPath, PK::kConjunctPath,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kStart,
PK::kProject,
PK::kProject,
PK::kProduceAllPaths, PK::kProduceAllPaths,
PK::kProduceAllPaths, PK::kProduceAllPaths,
PK::kGetNeighbors,
PK::kGetNeighbors,
PK::kPassThrough,
PK::kStart, PK::kStart,
};
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query = "FIND ALL PATH FROM \"1\" TO \"2\",\"3\" OVER like UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kDataCollect,
PK::kLoop,
PK::kProject,
PK::kConjunctPath,
PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kStart,
PK::kProject,
PK::kProject,
PK::kProduceAllPaths,
PK::kProduceAllPaths,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kPassThrough, PK::kPassThrough,
...@@ -201,42 +120,16 @@ TEST_F(FindPathValidatorTest, ALLPath) { ...@@ -201,42 +120,16 @@ TEST_F(FindPathValidatorTest, ALLPath) {
EXPECT_TRUE(checkResult(query, expected)); EXPECT_TRUE(checkResult(query, expected));
} }
{ {
std::string query = "FIND ALL PATH FROM \"1\",\"2\" TO \"3\",\"4\" OVER like UPTO 5 STEPS"; std::string query = "FIND ALL PATH FROM \"1\" TO \"2\",\"3\" OVER like UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = { std::vector<PlanNode::Kind> expected = {
PK::kDataCollect, PK::kDataCollect,
PK::kLoop, PK::kLoop,
PK::kProject, PK::kProject,
PK::kConjunctPath, PK::kConjunctPath,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kStart,
PK::kProject,
PK::kProject,
PK::kProduceAllPaths, PK::kProduceAllPaths,
PK::kProduceAllPaths, PK::kProduceAllPaths,
PK::kGetNeighbors,
PK::kGetNeighbors,
PK::kPassThrough,
PK::kStart,
};
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query = "FIND ALL PATH FROM \"1\" TO \"2\" OVER like, serve UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kDataCollect,
PK::kLoop,
PK::kProject,
PK::kConjunctPath,
PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kStart, PK::kStart,
PK::kProject,
PK::kProject,
PK::kProduceAllPaths,
PK::kProduceAllPaths,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kPassThrough, PK::kPassThrough,
...@@ -257,22 +150,20 @@ TEST_F(FindPathValidatorTest, RunTimePath) { ...@@ -257,22 +150,20 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
PK::kCartesianProduct, PK::kCartesianProduct,
PK::kConjunctPath, PK::kConjunctPath,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kProject, PK::kProject,
PK::kProject, PK::kProject,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kProduceSemiShortestPath, PK::kProduceSemiShortestPath,
PK::kProduceSemiShortestPath, PK::kProduceSemiShortestPath,
PK::kProject, PK::kDedup,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kDedup,
PK::kPassThrough,
PK::kProject, PK::kProject,
PK::kPassThrough,
PK::kDedup,
PK::kStart, PK::kStart,
PK::kProject, PK::kProject,
PK::kProject,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kStart, PK::kStart,
}; };
...@@ -288,12 +179,6 @@ TEST_F(FindPathValidatorTest, RunTimePath) { ...@@ -288,12 +179,6 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
PK::kProject, PK::kProject,
PK::kConjunctPath, PK::kConjunctPath,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kDedup,
PK::kProject,
PK::kProject,
PK::kProject,
PK::kProduceAllPaths, PK::kProduceAllPaths,
PK::kProduceAllPaths, PK::kProduceAllPaths,
PK::kDedup, PK::kDedup,
...@@ -301,8 +186,10 @@ TEST_F(FindPathValidatorTest, RunTimePath) { ...@@ -301,8 +186,10 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kProject, PK::kProject,
PK::kPassThrough, PK::kPassThrough,
PK::kProject, PK::kDedup,
PK::kStart, PK::kStart,
PK::kProject,
PK::kProject,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kStart, PK::kStart,
}; };
...@@ -318,21 +205,19 @@ TEST_F(FindPathValidatorTest, RunTimePath) { ...@@ -318,21 +205,19 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
PK::kCartesianProduct, PK::kCartesianProduct,
PK::kConjunctPath, PK::kConjunctPath,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kProject, PK::kProject,
PK::kProject, PK::kProject,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kProduceSemiShortestPath, PK::kProduceSemiShortestPath,
PK::kProduceSemiShortestPath, PK::kProduceSemiShortestPath,
PK::kProject, PK::kDedup,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kProject, PK::kProject,
PK::kPassThrough, PK::kPassThrough,
PK::kGetNeighbors, PK::kProject,
PK::kStart, PK::kStart,
PK::kGetNeighbors,
PK::kStart, PK::kStart,
}; };
EXPECT_TRUE(checkResult(query, expected)); EXPECT_TRUE(checkResult(query, expected));
...@@ -347,51 +232,18 @@ TEST_F(FindPathValidatorTest, RunTimePath) { ...@@ -347,51 +232,18 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
PK::kCartesianProduct, PK::kCartesianProduct,
PK::kConjunctPath, PK::kConjunctPath,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kProject, PK::kProject,
PK::kProject, PK::kProject,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kProduceSemiShortestPath, PK::kProduceSemiShortestPath,
PK::kProduceSemiShortestPath, PK::kProduceSemiShortestPath,
PK::kProject,
PK::kGetNeighbors,
PK::kGetNeighbors,
PK::kProject,
PK::kPassThrough,
PK::kGetNeighbors,
PK::kStart,
PK::kStart,
};
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query =
"$a = GO FROM \"1\" OVER like YIELD like._src AS src, like._dst AS dst; "
"FIND SHORTEST PATH FROM $a.src TO $a.dst OVER like, serve UPTO 5 STEPS";
std::vector<PlanNode::Kind> expected = {
PK::kDataCollect,
PK::kLoop,
PK::kCartesianProduct,
PK::kConjunctPath,
PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kProject,
PK::kProject,
PK::kProject,
PK::kDedup, PK::kDedup,
PK::kProduceSemiShortestPath,
PK::kProduceSemiShortestPath,
PK::kProject,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kDedup, PK::kProject,
PK::kPassThrough, PK::kPassThrough,
PK::kProject, PK::kProject,
PK::kStart, PK::kStart,
PK::kProject,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kStart, PK::kStart,
}; };
...@@ -407,22 +259,20 @@ TEST_F(FindPathValidatorTest, RunTimePath) { ...@@ -407,22 +259,20 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
PK::kCartesianProduct, PK::kCartesianProduct,
PK::kConjunctPath, PK::kConjunctPath,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kProject, PK::kProject,
PK::kProject, PK::kProject,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kProduceSemiShortestPath, PK::kProduceSemiShortestPath,
PK::kProduceSemiShortestPath, PK::kProduceSemiShortestPath,
PK::kProject, PK::kDedup,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kDedup,
PK::kPassThrough,
PK::kProject, PK::kProject,
PK::kPassThrough,
PK::kDedup,
PK::kStart, PK::kStart,
PK::kProject, PK::kProject,
PK::kProject,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kProject, PK::kProject,
PK::kGetNeighbors, PK::kGetNeighbors,
...@@ -440,22 +290,20 @@ TEST_F(FindPathValidatorTest, RunTimePath) { ...@@ -440,22 +290,20 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
PK::kCartesianProduct, PK::kCartesianProduct,
PK::kConjunctPath, PK::kConjunctPath,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kProject, PK::kProject,
PK::kProject, PK::kProject,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kProduceSemiShortestPath, PK::kProduceSemiShortestPath,
PK::kProduceSemiShortestPath, PK::kProduceSemiShortestPath,
PK::kProject, PK::kDedup,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kDedup,
PK::kPassThrough,
PK::kProject, PK::kProject,
PK::kPassThrough,
PK::kDedup,
PK::kStart, PK::kStart,
PK::kProject, PK::kProject,
PK::kProject,
PK::kStart, PK::kStart,
}; };
EXPECT_TRUE(checkResult(query, expected)); EXPECT_TRUE(checkResult(query, expected));
...@@ -469,12 +317,6 @@ TEST_F(FindPathValidatorTest, RunTimePath) { ...@@ -469,12 +317,6 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
PK::kProject, PK::kProject,
PK::kConjunctPath, PK::kConjunctPath,
PK::kProject, PK::kProject,
PK::kDedup,
PK::kDedup,
PK::kDedup,
PK::kProject,
PK::kProject,
PK::kProject,
PK::kProduceAllPaths, PK::kProduceAllPaths,
PK::kProduceAllPaths, PK::kProduceAllPaths,
PK::kDedup, PK::kDedup,
...@@ -482,8 +324,10 @@ TEST_F(FindPathValidatorTest, RunTimePath) { ...@@ -482,8 +324,10 @@ TEST_F(FindPathValidatorTest, RunTimePath) {
PK::kGetNeighbors, PK::kGetNeighbors,
PK::kProject, PK::kProject,
PK::kPassThrough, PK::kPassThrough,
PK::kProject, PK::kDedup,
PK::kStart, PK::kStart,
PK::kProject,
PK::kProject,
PK::kStart, PK::kStart,
}; };
EXPECT_TRUE(checkResult(query, expected)); EXPECT_TRUE(checkResult(query, expected));
......
# Copyright (c) 2020 vesoft inc. All rights reserved. # Copyright (c) 2021 vesoft inc. All rights reserved.
# #
# This source code is licensed under Apache 2.0 License, # This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory. # attached with Common Clause Condition 1.0, found in the LICENSES directory.
...@@ -52,6 +52,21 @@ Feature: Integer Vid Shortest Path ...@@ -52,6 +52,21 @@ Feature: Integer Vid Shortest Path
| path | | path |
| <("Tiago Splitter")-[:like]->("Tim Duncan")-[:teammate]->("LaMarcus Aldridge")> | | <("Tiago Splitter")-[:like]->("Tim Duncan")-[:teammate]->("LaMarcus Aldridge")> |
Scenario: Integer Vid [6] SinglePair Shortest Path limit steps
When executing query:
"""
FIND SHORTEST PATH FROM hash("Tiago Splitter") TO hash("Tony Parker") OVER * UPTO 1 STEPS
"""
Then the result should be, in any order, with relax comparison:
| path |
When executing query:
"""
FIND SHORTEST PATH FROM hash("Tiago Splitter") TO hash("Tim Duncan") OVER * UPTO 1 STEPS
"""
Then the result should be, in any order, with relax comparison:
| path |
| <("Tiago Splitter")-[:like]->("Tim Duncan")> |
Scenario: Integer Vid [1] MultiPair Shortest Path Scenario: Integer Vid [1] MultiPair Shortest Path
When executing query: When executing query:
""" """
...@@ -104,6 +119,15 @@ Feature: Integer Vid Shortest Path ...@@ -104,6 +119,15 @@ Feature: Integer Vid Shortest Path
| <("Tony Parker")-[:like]->("Manu Ginobili")> | | <("Tony Parker")-[:like]->("Manu Ginobili")> |
| <("Tony Parker")-[:teammate]->("Manu Ginobili")> | | <("Tony Parker")-[:teammate]->("Manu Ginobili")> |
| <("Tony Parker")-[:serve]->("Spurs")> | | <("Tony Parker")-[:serve]->("Spurs")> |
When executing query:
"""
FIND SHORTEST PATH FROM hash("Yao Ming") TO hash("Tim Duncan"), hash("Spurs"), hash("Lakers") OVER * UPTO 2 STEPS
"""
Then the result should be, in any order, with relax comparison:
| path |
| <("Yao Ming")-[:like]->("Shaquile O'Neal")-[:like]->("Tim Duncan")> |
| <("Yao Ming")-[:like]->("Tracy McGrady")-[:serve]->("Spurs")> |
| <("Yao Ming")-[:like]->("Shaquile O'Neal")-[:serve]->("Lakers")> |
Scenario: Integer Vid [5] MultiPair Shortest Path Scenario: Integer Vid [5] MultiPair Shortest Path
When executing query: When executing query:
...@@ -390,11 +414,13 @@ Feature: Integer Vid Shortest Path ...@@ -390,11 +414,13 @@ Feature: Integer Vid Shortest Path
FIND SHORTEST PATH FROM hash("Tony Parker"), hash("Yao Ming") TO hash("Manu Ginobili"), hash("Spurs"), hash("Lakers") OVER * BIDIRECT UPTO 2 STEPS FIND SHORTEST PATH FROM hash("Tony Parker"), hash("Yao Ming") TO hash("Manu Ginobili"), hash("Spurs"), hash("Lakers") OVER * BIDIRECT UPTO 2 STEPS
""" """
Then the result should be, in any order, with relax comparison: Then the result should be, in any order, with relax comparison:
| path | | path |
| <("Tony Parker")-[:serve]->("Spurs")> | | <("Yao Ming")-[:like]->("Tracy McGrady")-[:serve]->("Spurs")> |
| <("Tony Parker")<-[:teammate]-("Manu Ginobili")> | | <("Yao Ming")-[:like]->("Shaquile O'Neal")-[:serve]->("Lakers")> |
| <("Tony Parker")-[:like]->("Manu Ginobili")> | | <("Tony Parker")-[:serve]->("Spurs")> |
| <("Tony Parker")-[:teammate]->("Manu Ginobili")> | | <("Tony Parker")<-[:teammate]-("Manu Ginobili")> |
| <("Tony Parker")-[:like]->("Manu Ginobili")> |
| <("Tony Parker")-[:teammate]->("Manu Ginobili")> |
Scenario: Integer Vid [3] Shortest Path BIDIRECT Scenario: Integer Vid [3] Shortest Path BIDIRECT
When executing query: When executing query:
......
# Copyright (c) 2020 vesoft inc. All rights reserved. # Copyright (c) 2021 vesoft inc. All rights reserved.
# #
# This source code is licensed under Apache 2.0 License, # This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory. # attached with Common Clause Condition 1.0, found in the LICENSES directory.
...@@ -52,6 +52,21 @@ Feature: Shortest Path ...@@ -52,6 +52,21 @@ Feature: Shortest Path
| path | | path |
| <("Tiago Splitter")-[:like]->("Tim Duncan")-[:teammate]->("LaMarcus Aldridge")> | | <("Tiago Splitter")-[:like]->("Tim Duncan")-[:teammate]->("LaMarcus Aldridge")> |
Scenario: [6] SinglePair Shortest Path limit steps
When executing query:
"""
FIND SHORTEST PATH FROM "Tiago Splitter" TO "Tony Parker" OVER * UPTO 1 STEPS
"""
Then the result should be, in any order, with relax comparison:
| path |
When executing query:
"""
FIND SHORTEST PATH FROM "Tiago Splitter" TO "Tim Duncan" OVER * UPTO 1 STEPS
"""
Then the result should be, in any order, with relax comparison:
| path |
| <("Tiago Splitter")-[:like]->("Tim Duncan")> |
Scenario: [1] MultiPair Shortest Path Scenario: [1] MultiPair Shortest Path
When executing query: When executing query:
""" """
...@@ -104,6 +119,15 @@ Feature: Shortest Path ...@@ -104,6 +119,15 @@ Feature: Shortest Path
| <("Tony Parker")-[:like]->("Manu Ginobili")> | | <("Tony Parker")-[:like]->("Manu Ginobili")> |
| <("Tony Parker")-[:teammate]->("Manu Ginobili")> | | <("Tony Parker")-[:teammate]->("Manu Ginobili")> |
| <("Tony Parker")-[:serve]->("Spurs")> | | <("Tony Parker")-[:serve]->("Spurs")> |
When executing query:
"""
FIND SHORTEST PATH FROM "Yao Ming" TO "Tim Duncan", "Spurs", "Lakers" OVER * UPTO 2 STEPS
"""
Then the result should be, in any order, with relax comparison:
| path |
| <("Yao Ming")-[:like]->("Shaquile O'Neal")-[:like]->("Tim Duncan")> |
| <("Yao Ming")-[:like]->("Tracy McGrady")-[:serve]->("Spurs")> |
| <("Yao Ming")-[:like]->("Shaquile O'Neal")-[:serve]->("Lakers")> |
Scenario: [5] MultiPair Shortest Path Scenario: [5] MultiPair Shortest Path
When executing query: When executing query:
...@@ -390,11 +414,13 @@ Feature: Shortest Path ...@@ -390,11 +414,13 @@ Feature: Shortest Path
FIND SHORTEST PATH FROM "Tony Parker", "Yao Ming" TO "Manu Ginobili", "Spurs", "Lakers" OVER * BIDIRECT UPTO 2 STEPS FIND SHORTEST PATH FROM "Tony Parker", "Yao Ming" TO "Manu Ginobili", "Spurs", "Lakers" OVER * BIDIRECT UPTO 2 STEPS
""" """
Then the result should be, in any order, with relax comparison: Then the result should be, in any order, with relax comparison:
| path | | path |
| <("Tony Parker")-[:serve]->("Spurs")> | | <("Yao Ming")-[:like]->("Tracy McGrady")-[:serve]->("Spurs")> |
| <("Tony Parker")<-[:teammate]-("Manu Ginobili")> | | <("Yao Ming")-[:like]->("Shaquile O'Neal")-[:serve]->("Lakers")> |
| <("Tony Parker")-[:like]->("Manu Ginobili")> | | <("Tony Parker")-[:serve]->("Spurs")> |
| <("Tony Parker")-[:teammate]->("Manu Ginobili")> | | <("Tony Parker")<-[:teammate]-("Manu Ginobili")> |
| <("Tony Parker")-[:like]->("Manu Ginobili")> |
| <("Tony Parker")-[:teammate]->("Manu Ginobili")> |
Scenario: [3] Shortest Path BIDIRECT Scenario: [3] Shortest Path BIDIRECT
When executing query: When executing query:
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment