Skip to content

Commit

Permalink
fix dangling edge in path (#3008)
Browse files Browse the repository at this point in the history
* fix dangling edge

* add test case

* fix ci error
  • Loading branch information
nevermore3 authored Oct 14, 2021
1 parent e1de5af commit 1f78224
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 43 deletions.
19 changes: 10 additions & 9 deletions src/graph/executor/query/DataCollectExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ Status DataCollectExecutor::collectMultiplePairShortestPath(const std::vector<st
Status DataCollectExecutor::collectPathProp(const std::vector<std::string>& vars) {
DataSet ds;
ds.colNames = colNames_;
DCHECK(!ds.colNames.empty());
// 0: vertices's props, 1: Edges's props 2: paths without prop
DCHECK_EQ(vars.size(), 3);

Expand All @@ -284,7 +283,7 @@ Status DataCollectExecutor::collectPathProp(const std::vector<std::string>& vars
DCHECK(vIter->isPropIter());
for (; vIter->valid(); vIter->next()) {
const auto& vertexVal = vIter->getVertex();
if (!vertexVal.isVertex()) {
if (UNLIKELY(!vertexVal.isVertex())) {
continue;
}
const auto& vertex = vertexVal.getVertex();
Expand All @@ -296,8 +295,8 @@ Status DataCollectExecutor::collectPathProp(const std::vector<std::string>& vars
edgeMap.reserve(eIter->size());
DCHECK(eIter->isPropIter());
for (; eIter->valid(); eIter->next()) {
auto edgeVal = eIter->getEdge();
if (!edgeVal.isEdge()) {
const auto& edgeVal = eIter->getEdge();
if (UNLIKELY(!edgeVal.isEdge())) {
continue;
}
auto& edge = edgeVal.getEdge();
Expand All @@ -308,8 +307,8 @@ Status DataCollectExecutor::collectPathProp(const std::vector<std::string>& vars
auto pIter = ectx_->getResult(vars[2]).iter();
DCHECK(pIter->isSequentialIter());
for (; pIter->valid(); pIter->next()) {
auto& pathVal = pIter->getColumn(0);
if (!pathVal.isPath()) {
const auto& pathVal = pIter->getColumn(0);
if (UNLIKELY(!pathVal.isPath())) {
continue;
}
auto path = pathVal.getPath();
Expand All @@ -320,13 +319,15 @@ Status DataCollectExecutor::collectPathProp(const std::vector<std::string>& vars
}
for (auto& step : path.steps) {
auto dst = step.dst.vid;
step.dst = vertexMap[dst];
found = vertexMap.find(dst);
if (found != vertexMap.end()) {
step.dst = found->second;
}

auto type = step.type;
auto ranking = step.ranking;
if (type < 0) {
dst = src;
src = step.dst.vid;
std::swap(src, dst);
type = -type;
}
auto edgeKey = std::make_tuple(src, type, ranking, dst);
Expand Down
59 changes: 42 additions & 17 deletions tests/tck/features/path/AllPath.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
Feature: Integer Vid All Path

Background:
Given a graph with space named "nba_int_vid"

Scenario: Integer Vid [1] ALL Path
Given a graph with space named "nba_int_vid"
When executing query:
"""
FIND ALL PATH FROM hash("Tim Duncan") TO hash("Tim Duncan") OVER * UPTO 2 STEPS
Expand All @@ -33,8 +31,6 @@ Feature: Integer Vid All Path
| <("Tim Duncan")-[:like]->("Tony Parker")> |
| <("Tim Duncan")-[:like]->("Manu Ginobili")-[:like]->("Tim Duncan")-[:like]->("Tony Parker")> |
| <("Tim Duncan")-[:like]->("Tony Parker")-[:like]->("LaMarcus Aldridge")-[:like]->("Tony Parker")> |

Scenario: Integer Vid [2] ALL Path
When executing query:
"""
FIND ALL PATH FROM hash("Tim Duncan") TO hash("Tony Parker"), hash("Manu Ginobili") OVER like UPTO 3 STEPS
Expand All @@ -47,8 +43,6 @@ Feature: Integer Vid All Path
| <("Tim Duncan")-[:like]->("Manu Ginobili")-[:like]->("Tim Duncan")-[:like]->("Tony Parker")> |
| <("Tim Duncan")-[:like]->("Tony Parker")-[:like]->("LaMarcus Aldridge")-[:like]->("Tony Parker")> |
| <("Tim Duncan")-[:like]->("Tony Parker")-[:like]->("Tim Duncan")-[:like]->("Manu Ginobili")> |

Scenario: Integer Vid [3] ALL Path
When executing query:
"""
FIND ALL PATH FROM hash("Tim Duncan") TO hash("Tony Parker"), hash("LaMarcus Aldridge") OVER like UPTO 3 STEPS
Expand All @@ -59,8 +53,6 @@ Feature: Integer Vid All Path
| <("Tim Duncan")-[:like]->("Tony Parker")-[:like]->("LaMarcus Aldridge")> |
| <("Tim Duncan")-[:like]->("Manu Ginobili")-[:like]->("Tim Duncan")-[:like]->("Tony Parker")> |
| <("Tim Duncan")-[:like]->("Tony Parker")-[:like]->("LaMarcus Aldridge")-[:like]->("Tony Parker")> |

Scenario: Integer Vid [4] ALL Path
When executing query:
"""
FIND ALL PATH FROM hash("Tim Duncan") TO hash("Tony Parker"), hash("Spurs") OVER like,serve UPTO 3 STEPS
Expand All @@ -79,6 +71,7 @@ Feature: Integer Vid All Path
| <("Tim Duncan")-[:like]->("Tony Parker")-[:like]->("Manu Ginobili")-[:serve]->("Spurs")> |

Scenario: Integer Vid [1] ALL Path Run Time Input
Given a graph with space named "nba_int_vid"
When executing query:
"""
GO FROM hash("Tim Duncan") over * YIELD like._dst AS src, serve._src AS dst
Expand All @@ -93,8 +86,6 @@ Feature: Integer Vid All Path
| <("Manu Ginobili")-[:like]->("Tim Duncan")-[:like]->("Tony Parker")-[:like]->("Tim Duncan")> |
| <("Tony Parker")-[:like]->("LaMarcus Aldridge")-[:like]->("Tony Parker")-[:like]->("Tim Duncan")> |
| <("Tony Parker")-[:like]->("Tim Duncan")-[:like]->("Manu Ginobili")-[:like]->("Tim Duncan")> |

Scenario: Integer Vid [2] ALL Path Run Time Input
When executing query:
"""
$a = GO FROM hash("Tim Duncan") over * YIELD like._dst AS src, serve._src AS dst;
Expand All @@ -109,8 +100,6 @@ Feature: Integer Vid All Path
| <("Manu Ginobili")-[:like]->("Tim Duncan")-[:like]->("Tony Parker")-[:like]->("Tim Duncan")> |
| <("Tony Parker")-[:like]->("LaMarcus Aldridge")-[:like]->("Tony Parker")-[:like]->("Tim Duncan")> |
| <("Tony Parker")-[:like]->("Tim Duncan")-[:like]->("Manu Ginobili")-[:like]->("Tim Duncan")> |

Scenario: Integer Vid [1] ALL Path With Limit
When executing query:
"""
FIND ALL PATH FROM hash("Tim Duncan") TO hash("Tony Parker"), hash("Spurs") OVER like,serve UPTO 3 STEPS
Expand All @@ -123,6 +112,7 @@ Feature: Integer Vid All Path
| <("Tim Duncan")-[:like]->("Tony Parker")-[:like]->("LaMarcus Aldridge")-[:serve]->("Spurs")> |

Scenario: Integer Vid [2] ALL Path With Limit
Given a graph with space named "nba_int_vid"
When executing query:
"""
$a = GO FROM hash("Tim Duncan") over * YIELD like._dst AS src, serve._src AS dst;
Expand All @@ -138,14 +128,13 @@ Feature: Integer Vid All Path
| <("Tony Parker")-[:like@0]->("Tim Duncan")-[:like@0]->("Manu Ginobili")-[:like@0]->("Tim Duncan")> |

Scenario: Integer Vid [1] ALL PATH REVERSELY
Given a graph with space named "nba_int_vid"
When executing query:
"""
FIND ALL PATH FROM hash("Tim Duncan") TO hash("Nobody"), hash("Spur") OVER like REVERSELY UPTO 3 STEPS
"""
Then the result should be, in any order, with relax comparison:
| path |

Scenario: Integer Vid [2] ALL PATH REVERSELY
When executing query:
"""
FIND ALL PATH FROM hash("Tim Duncan") TO hash("Tony Parker") OVER like REVERSELY UPTO 3 STEPS
Expand All @@ -157,8 +146,6 @@ Feature: Integer Vid All Path
| <("Tim Duncan")<-[:like]-("Manu Ginobili")<-[:like]-("Tony Parker")> |
| <("Tim Duncan")<-[:like]-("Manu Ginobili")<-[:like]-("Tim Duncan")<-[:like]-("Tony Parker")> |
| <("Tim Duncan")<-[:like]-("Tony Parker")<-[:like]-("LaMarcus Aldridge")<-[:like]-("Tony Parker")> |

Scenario: Integer Vid [3] ALL PATH REVERSELY
When executing query:
"""
FIND ALL PATH FROM hash("Tim Duncan") TO hash("Tony Parker"), hash("LaMarcus Aldridge") OVER like REVERSELY UPTO 3 STEPS
Expand All @@ -178,6 +165,7 @@ Feature: Integer Vid All Path
| <("Tim Duncan")<-[:like]-("Tony Parker")<-[:like]-("LaMarcus Aldridge")<-[:like]-("Tony Parker")> |

Scenario: Integer Vid [2] ALL PATH BIDIRECT
Given a graph with space named "nba_int_vid"
When executing query:
"""
FIND ALL PATH FROM hash("Tim Duncan") TO hash("Tony Parker") OVER like BIDIRECT UPTO 3 STEPS
Expand Down Expand Up @@ -212,6 +200,7 @@ Feature: Integer Vid All Path
| <("Tim Duncan")<-[:like]-("Tiago Splitter")-[:like]->("Manu Ginobili")<-[:like]-("Tony Parker")> |

Scenario: Integer Vid ALL Path WITH PROP
Given a graph with space named "nba_int_vid"
When executing query:
"""
FIND ALL PATH WITH PROP FROM hash("Tim Duncan") TO hash("Tony Parker") OVER like UPTO 3 STEPS
Expand All @@ -223,6 +212,7 @@ Feature: Integer Vid All Path
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 95}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})-[:like@0 {likeness: 90}]->("LaMarcus Aldridge" :player{age: 33, name: "LaMarcus Aldridge"})-[:like@0 {likeness: 75}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})> |

Scenario: Integer Vid ALL Path WITH FILTER
Given a graph with space named "nba_int_vid"
When executing query:
"""
FIND ALL PATH WITH PROP FROM hash("Tim Duncan") TO hash("Yao Ming") OVER * BIDIRECT
Expand Down Expand Up @@ -253,3 +243,38 @@ Feature: Integer Vid All Path
| <("Yao Ming" :player{age: 38, name: "Yao Ming"})-[:like@0 {likeness: 90}]->("Shaquile O'Neal" :player{age: 47, name: "Shaquile O'Neal"})-[:like@0 {likeness: 80}]->("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:teammate@0 {end_year: 2016, start_year: 2010}]->("Danny Green" :player{age: 31, name: "Danny Green"})> |
| <("Yao Ming" :player{age: 38, name: "Yao Ming"})-[:like@0 {likeness: 90}]->("Tracy McGrady" :player{age: 39, name: "Tracy McGrady"})-[:serve@0 {end_year: 2000, start_year: 1997}]->("Raptors" :team{name: "Raptors"})<-[:serve@0 {end_year: 2019, start_year: 2018}]-("Danny Green" :player{age: 31, name: "Danny Green"})> |
| <("Yao Ming" :player{age: 38, name: "Yao Ming"})-[:like@0 {likeness: 90}]->("Tracy McGrady" :player{age: 39, name: "Tracy McGrady"})-[:serve@0 {end_year: 2013, start_year: 2013}]->("Spurs" :team{name: "Spurs"})<-[:serve@0 {end_year: 2018, start_year: 2010}]-("Danny Green" :player{age: 31, name: "Danny Green"})> |

Scenario: Integer Vid Dangling edge
Given an empty graph
And load "nba_int_vid" csv data to a new space
When executing query:
"""
INSERT EDGE like(likeness) VALUES hash("Tim Duncan")->hash("Tim Parker"):(99);
INSERT EDGE like(likeness) VALUES hash("Tim Parker")->hash("Tony Parker"):(90);
"""
Then the execution should be successful
When executing query:
"""
FIND ALL PATH WITH PROP FROM hash("Tim Duncan") TO hash("Tony Parker") OVER like UPTO 2 steps
"""
Then the result should be, in any order, with relax comparison:
| path |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 95}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 99}]->("Tim Parker")-[:like@0 {likeness: 90}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
When executing query:
"""
FIND ALL PATH WITH PROP FROM hash("Tim Duncan") TO hash("Tony Parker") OVER like BIDIRECT UPTO 2 steps
"""
Then the result should be, in any order, with relax comparison:
| path |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})<-[:like@0 {likeness: 95}]-("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 95}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 99}]->("Tim Parker")-[:like@0 {likeness: 90}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})<-[:like@0 {likeness: 55}]-("Marco Belinelli" :player{age: 32, name: "Marco Belinelli"})-[:like@0 {likeness: 50}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})<-[:like@0 {likeness: 99}]-("Dejounte Murray" :player{age: 29, name: "Dejounte Murray"})-[:like@0 {likeness: 99}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})<-[:like@0 {likeness: 75}]-("LaMarcus Aldridge" :player{age: 33, name: "LaMarcus Aldridge"})<-[:like@0 {likeness: 90}]-("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})<-[:like@0 {likeness: 75}]-("LaMarcus Aldridge" :player{age: 33, name: "LaMarcus Aldridge"})-[:like@0 {likeness: 75}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})<-[:like@0 {likeness: 90}]-("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"})<-[:like@0 {likeness: 95}]-("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 95}]->("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"})<-[:like@0 {likeness: 95}]-("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})<-[:like@0 {likeness: 80}]-("Boris Diaw" :player{age: 36, name: "Boris Diaw"})-[:like@0 {likeness: 80}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
Then drop the used space
Loading

0 comments on commit 1f78224

Please sign in to comment.