Add support for query parameters in return limit (#1654)

This commit is contained in:
DavIvek 2024-01-23 19:17:27 +01:00 committed by GitHub
parent e7f6a5f4f4
commit 6706ebfa2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 2 deletions

View File

@ -1752,7 +1752,11 @@ antlrcpp::Any CypherMainVisitor::visitReturnBody(MemgraphCypher::ReturnBodyConte
body.skip = static_cast<Expression *>(std::any_cast<Expression *>(ctx->skip()->accept(this)));
}
if (ctx->limit()) {
body.limit = static_cast<Expression *>(std::any_cast<Expression *>(ctx->limit()->accept(this)));
if (ctx->limit()->expression()) {
body.limit = std::any_cast<Expression *>(ctx->limit()->accept(this));
} else {
body.limit = std::any_cast<ParameterLookup *>(ctx->limit()->accept(this));
}
}
std::tie(body.all_identifiers, body.named_expressions) =
std::any_cast<std::pair<bool, std::vector<NamedExpression *>>>(ctx->returnItems()->accept(this));

View File

@ -143,7 +143,7 @@ order : ORDER BY sortItem ( ',' sortItem )* ;
skip : L_SKIP expression ;
limit : LIMIT expression ;
limit : LIMIT ( expression | parameter ) ;
sortItem : expression ( ASCENDING | ASC | DESCENDING | DESC )? ;

View File

@ -153,3 +153,20 @@ Feature: Parameters
Then the result should be:
| a |
| (:Label1 {x: 10}) |
Scenario: Parameters for limit in return returnBody
Given an empty graph
And having executed:
"""
FOREACH (id IN range(1, 10) | CREATE (:Node {id: id}))
"""
And parameters are:
| limit | 2 |
When executing query:
"""
MATCH (n) RETURN n LIMIT $limit
"""
Then the result should be:
| n |
| (:Node {id: 1}) |
| (:Node {id: 2}) |