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

Fix #2158 #2171

Merged
merged 1 commit into from
Oct 9, 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
31 changes: 30 additions & 1 deletion src/binder/bind_expression/bind_function_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,36 @@ std::shared_ptr<Expression> ExpressionBinder::bindRecursiveJoinLengthFunction(
if (expression.getDataType().getLogicalTypeID() != LogicalTypeID::RECURSIVE_REL) {
return nullptr;
}
return ((RelExpression&)expression).getLengthExpression();
if (expression.expressionType == common::PATH) {
int64_t numRels = 0u;
expression_vector recursiveRels;
for (auto& child : expression.getChildren()) {
if (ExpressionUtil::isRelVariable(*child)) {
numRels++;
} else if (ExpressionUtil::isRecursiveRelVariable(*child)) {
recursiveRels.push_back(child);
}
}
auto numRelsExpression = createLiteralExpression(std::make_unique<Value>(numRels));
if (recursiveRels.empty()) {
return numRelsExpression;
}
expression_vector children;
children.push_back(std::move(numRelsExpression));
children.push_back(
reinterpret_cast<RelExpression&>(*recursiveRels[0]).getLengthExpression());
auto result = bindScalarFunctionExpression(children, ADD_FUNC_NAME);
for (auto i = 1u; i < recursiveRels.size(); ++i) {
children[0] = std::move(result);
children[1] = reinterpret_cast<RelExpression&>(*recursiveRels[i]).getLengthExpression();
result = bindScalarFunctionExpression(children, ADD_FUNC_NAME);
}
return result;
} else if (ExpressionUtil::isRecursiveRelVariable(expression)) {
auto& recursiveRel = reinterpret_cast<const RelExpression&>(expression);
return recursiveRel.getLengthExpression();
}
return nullptr;
}

} // namespace binder
Expand Down
20 changes: 20 additions & 0 deletions test/test_files/issue/issue.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-GROUP IssueTest
-DATASET CSV empty

--

-CASE 2158

-STATEMENT CREATE NODE TABLE N1(name STRING, PRIMARY KEY(name));
---- ok
-STATEMENT CREATE NODE TABLE N2(name STRING, PRIMARY KEY(name));
---- ok
-STATEMENT CREATE REL TABLE Rel1(FROM N1 TO N2);
---- ok
-STATEMENT CREATE REL TABLE Rel2(FROM N1 TO N2);
---- ok
-STATEMENT CREATE (n1:N1 {name: "n1a"}), (n2:N2 {name: "n2a"}), (n1)-[:Rel1]->(n2);
---- ok
-STATEMENT MATCH p = (n1:N1)-[:Rel1]->() return length(p);
---- 1
1
41 changes: 41 additions & 0 deletions test/test_files/tinysnb/path/path.test
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,44 @@
[(0:0)-{_LABEL: knows, _ID: 3:2, date: 2021-06-30, meetTime: 2012-12-11 20:07:22, validInterval: 10 days, comments: [ioji232,jifhe8w99u43434]}->(0:3),(0:3)-{_LABEL: workAt, _ID: 5:1, year: 2010, grading: [2.100000,4.400000], rating: 7.600000}->(1:2)]
[(0:0)-{_LABEL: marries, _ID: 7:0, usedAddress: [toronto], address: [4,5]}->(0:1),(0:1)-{_LABEL: studyAt, _ID: 4:1, year: 2020, places: [anew,jsdnwusklklklwewsd], length: 55, level: 120, code: 6689, temprature: 1, ulength: 90, ulevel: 220}->(1:0)]
[(0:0)-{_LABEL: meets, _ID: 6:0, location: [7.820000,3.540000], times: 5, data: \xAA\xBB\xCC\xDD}->(0:1),(0:1)-{_LABEL: studyAt, _ID: 4:1, year: 2020, places: [anew,jsdnwusklklklwewsd], length: 55, level: 120, code: 6689, temprature: 1, ulength: 90, ulevel: 220}->(1:0)]

-LOG PathLength
-STATEMENT MATCH p = (a:person)-[e:knows]->(b:person) WHERE a.ID = 0 RETURN length(p), b.fName
---- 3
1|Bob
1|Carol
1|Dan
-STATEMENT MATCH p = (a:person)-[e:knows*1..2]->(b:person) WHERE a.ID = 0 AND b.ID = 2 RETURN length(p), length(e)
---- 3
1|1
2|2
2|2
-STATEMENT MATCH p = (a:person)-[e:knows*1..2]->(b:person)-[:knows]->(c:person) WHERE a.ID = 0 AND b.ID = 2 AND c.ID = 0 RETURN length(p), length(e)
---- 3
2|1
3|2
3|2
-STATEMENT MATCH p = (a:person)-[e:knows*1..2]->(b:person)-[k:knows*1..2]->(c:person) WHERE a.ID = 0 AND b.ID = 2 AND c.ID = 0 RETURN length(p), length(e), length(k)
---- 9
2|1|1
3|1|2
3|1|2
3|2|1
3|2|1
4|2|2
4|2|2
4|2|2
4|2|2
-STATEMENT MATCH p = (a:person)-[e:knows*1..2]->(b:person) RETURN length(a)
---- error
Binder exception: Cannot match a built-in function for given function LENGTH(NODE). Supported inputs are
(STRING) -> INT64
-STATEMENT MATCH p = (a:person)-[e:knows*1..2]->(b:person) RETURN len(p)
---- error
Binder exception: Cannot match a built-in function for given function LEN(RECURSIVE_REL). Supported inputs are
(VAR_LIST) -> INT64
(MAP) -> INT64
-STATEMENT MATCH p = (a:person)-[e:knows]->(b:person) RETURN length(e)
---- error
Binder exception: Cannot match a built-in function for given function LENGTH(REL). Supported inputs are
(STRING) -> INT64