Skip to content

Commit

Permalink
allow 0 as bound node
Browse files Browse the repository at this point in the history
  • Loading branch information
AEsir777 committed Sep 15, 2023
1 parent 49850c8 commit 022978f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
8 changes: 3 additions & 5 deletions src/binder/bind/bind_graph_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,9 @@ std::pair<uint64_t, uint64_t> Binder::bindVariableLengthRelBound(
"Lower bound of rel " + relPattern.getVariableName() + " is greater than upperBound.");
}
if (upperBound > clientContext->varLengthExtendMaxDepth) {
throw BinderException("Upper bound of rel exceeds maximum: " +
std::to_string(clientContext->varLengthExtendMaxDepth) + ".");
}
if (lowerBound == 0 || upperBound == 0) {
throw BinderException("Lower and upper bound of a rel must be greater than 0.");
throw BinderException(
"Upper bound of rel " + relPattern.getVariableName() +
" exceeds maximum: " + std::to_string(clientContext->varLengthExtendMaxDepth) + ".");
}
if ((relPattern.getRelType() == QueryRelType::ALL_SHORTEST ||
relPattern.getRelType() == QueryRelType::SHORTEST) &&
Expand Down
12 changes: 10 additions & 2 deletions src/processor/operator/recursive_extend/frontier_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ void DstNodeScanner::scanFromDstOffset(RecursiveJoinVectors* vectors, sel_t& vec

void PathScanner::scanFromDstOffset(RecursiveJoinVectors* vectors, sel_t& vectorPos,
sel_t& nodeIDDataVectorPos, sel_t& relIDDataVectorPos) {
// when bound node is 0
if (k == 0) {
writePathToVector(vectors, vectorPos, nodeIDDataVectorPos, relIDDataVectorPos);
return;

Check warning on line 62 in src/processor/operator/recursive_extend/frontier_scanner.cpp

View check run for this annotation

Codecov / codecov/patch

src/processor/operator/recursive_extend/frontier_scanner.cpp#L61-L62

Added lines #L61 - L62 were not covered by tests
}

auto level = 0;
while (!nbrsStack.empty()) {
auto& cursor = cursorStack.top();
Expand Down Expand Up @@ -87,7 +93,9 @@ void PathScanner::initDfs(const frontier::node_rel_id_t& nodeAndRelID, size_t cu
nodeIDs[currentDepth] = nodeAndRelID.first;
relIDs[currentDepth] = nodeAndRelID.second;
if (currentDepth == 0) {
cursorStack.top() = -1;
if (k != 0) {
cursorStack.top() = -1;
}
return;
}
auto nbrs = &frontiers[currentDepth]->bwdEdges.at(nodeAndRelID.first);
Expand All @@ -99,7 +107,7 @@ void PathScanner::initDfs(const frontier::node_rel_id_t& nodeAndRelID, size_t cu
void PathScanner::writePathToVector(RecursiveJoinVectors* vectors, sel_t& vectorPos,
sel_t& nodeIDDataVectorPos, sel_t& relIDDataVectorPos) {
assert(vectorPos < DEFAULT_VECTOR_CAPACITY);
auto nodeEntry = ListVector::addList(vectors->pathNodesVector, k - 1);
auto nodeEntry = ListVector::addList(vectors->pathNodesVector, k ? k - 1 : 0);
auto relEntry = ListVector::addList(vectors->pathRelsVector, k);
vectors->pathNodesVector->setValue(vectorPos, nodeEntry);
vectors->pathRelsVector->setValue(vectorPos, relEntry);
Expand Down
5 changes: 0 additions & 5 deletions test/test_files/exceptions/binder/binder_error.test
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,6 @@ Binder exception: p1.age has data type INT64. (STRING) was expected.
---- error
Binder exception: Union and union all can't be used together.

-LOG VarLenExtendZeroLowerBound
-STATEMENT MATCH (a:person)-[:knows*0..5]->(b:person) return count(*)
---- error
Binder exception: Lower and upper bound of a rel must be greater than 0.

-LOG ReadAfterUpdate
-STATEMENT MATCH (a:person) SET a.age = 35 WITH a MATCH (a)-[:knows]->(b:person) RETURN a.age
---- error
Expand Down
3 changes: 1 addition & 2 deletions test/test_files/tck/match/match4.test
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

# Zero-length variable length pattern in the middle of the pattern
-CASE Scenario3
-SKIP
-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID));
---- ok
-STATEMENT CREATE REL TABLE CONTAIN(FROM A TO A);
Expand Down Expand Up @@ -146,7 +145,7 @@
(n2)-[:EDGE]->(n3);
---- ok
-STATEMENT MATCH ()-[r:EDGE]-()
MATCH p = (n)-[*0..1]-()-[p:EDGE]-()-[*0..1]-(m)
MATCH p = (n)-[*0..1]-()-[r:EDGE]-()-[*0..1]-(m)
RETURN count(p) AS c
---- 1
32
Expand Down
2 changes: 1 addition & 1 deletion test/test_files/tinysnb/call/call.test
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
10
-STATEMENT MATCH (a:person)-[:knows*1..28]->(b:person) RETURN COUNT(*);
---- error
Binder exception: Upper bound of rel exceeds maximum: 10.
Binder exception: Upper bound of rel exceeds maximum: 10.
-STATEMENT MATCH (a:person)-[:knows*1..10]->(b:person) RETURN COUNT(*);
---- 1
354290
Expand Down
46 changes: 43 additions & 3 deletions test/test_files/tinysnb/var_length_extend/range_literal.test
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,50 @@ QueryPlanner::getProperties
---- ok
-STATEMENT MATCH(a:person {fName: "Alice"})-[e:meets*11..23]->(b:person) RETURN b.fName;
---- error
Binder exception: Upper bound of rel exceeds maximum: 10.
Binder exception: Upper bound of rel e exceeds maximum: 10.
-STATEMENT MATCH(a:person {fName: "Alice"})-[e:meets*..11]->(b:person) RETURN b.fName;
---- error
Binder exception: Upper bound of rel exceeds maximum: 10.
Binder exception: Upper bound of rel e exceeds maximum: 10.
-STATEMENT MATCH(a:person {fName: "Alice"})-[e:meets*11]->(b:person) RETURN b.fName;
---- error
Binder exception: Upper bound of rel exceeds maximum: 10.
Binder exception: Upper bound of rel e exceeds maximum: 10.

-CASE ZeroBound
-STATEMENT MATCH(a:person)-[e:knows*0]-() RETURN a.ID;
---- 8
0
2
3
5
7
8
9
10
-STATEMENT MATCH(a:person {fName: "Alice"})-[e:meets*0..1]->(b:person) RETURN b.fName;
---- 2
Alice
Bob
-STATEMENT MATCH(a:person {fName: "Alice"})<-[e:meets*0..0]-(b:person) RETURN b.fName;
---- 1
Alice
-STATEMENT MATCH(a:person)-[e:meets*0..0]-(b:person) RETURN b.ID;
---- 8
0
2
3
5
7
8
9
10
-STATEMENT MATCH(a:person {fName: "Alice"})-[e:meets*0..3]->(b:person) RETURN b.fName;
---- 3
Alice
Bob
Dan
-STATEMENT MATCH(a:person {fName: "Alice"})-[e:meets*..0]->(b:person) RETURN b.fName;
---- error
Binder exception: Lower bound of rel e is greater than upperBound.
-STATEMENT MATCH(a:person {fName: "Alice"})-[e:meets*2..0]->(b:person) RETURN b.fName;
---- error
Binder exception: Lower bound of rel e is greater than upperBound.

0 comments on commit 022978f

Please sign in to comment.