Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow node bound to include 0 [*0..4] #2041

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}

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 > 0 ? 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, length(e);
---- 2
Alice|0
Bob|1
-STATEMENT MATCH(a:person {fName: "Alice"})<-[e:meets*0..0]-(b:person) RETURN e, b.fName;
---- 1
{_NODES: [], _RELS: []}|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 e;
---- 3
{_NODES: [], _RELS: []}
{_NODES: [], _RELS: [(0:0)-{_LABEL: meets, _ID: 6:0, location: [7.820000,3.540000], times: 5, data: \xAA\xBB\xCC\xDD}->(0:1)]}
{_NODES: [{_ID: 0:1, _LABEL: person, ID: 2, fName: Bob, gender: 2, isStudent: True, isWorker: False, age: 30, eyeSight: 5.100000, birthdate: 1900-01-01, registerTime: 2008-11-03 15:25:30.000526, lastJobDuration: 10 years 5 months 13:00:00.000024, workedHours: [12,8], usedNames: [Bobby], courseScoresPerTerm: [[8,9],[9,10]], grades: [98,42,93,88], height: 0.990000}], _RELS: [(0:0)-{_LABEL: meets, _ID: 6:0, location: [7.820000,3.540000], times: 5, data: \xAA\xBB\xCC\xDD}->(0:1),(0:1)-{_LABEL: meets, _ID: 6:1, location: [2.870000,4.230000], times: 2, data: NO hex code}->(0:3)]}
-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.