Fix query returning a map
Summary: Add curvy braces handling in `QueryStripper` and an accompanying test for it. Reviewers: mislav.bradac Reviewed By: mislav.bradac Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1051
This commit is contained in:
parent
27370b99ff
commit
4da8312abe
@ -176,10 +176,12 @@ StrippedQuery::StrippedQuery(const std::string &query) : original_(query) {
|
||||
// list literal / function call.
|
||||
int num_open_braces = 0;
|
||||
int num_open_parantheses = 0;
|
||||
for (; jt != tokens.end() &&
|
||||
(jt->second != "," || num_open_braces || num_open_parantheses) &&
|
||||
jt->second != "order" && jt->second != "skip" &&
|
||||
jt->second != "limit" && jt->second != "union";
|
||||
int num_open_brackets = 0;
|
||||
for (;
|
||||
jt != tokens.end() && (jt->second != "," || num_open_braces ||
|
||||
num_open_parantheses || num_open_brackets) &&
|
||||
jt->second != "order" && jt->second != "skip" &&
|
||||
jt->second != "limit" && jt->second != "union";
|
||||
++jt) {
|
||||
if (jt->second == "(") {
|
||||
++num_open_parantheses;
|
||||
@ -189,6 +191,10 @@ StrippedQuery::StrippedQuery(const std::string &query) : original_(query) {
|
||||
++num_open_braces;
|
||||
} else if (jt->second == "]") {
|
||||
--num_open_braces;
|
||||
} else if (jt->second == "{") {
|
||||
++num_open_brackets;
|
||||
} else if (jt->second == "}") {
|
||||
--num_open_brackets;
|
||||
}
|
||||
has_as |= jt->second == "as";
|
||||
if (jt->first != Token::SPACE) {
|
||||
|
@ -340,4 +340,10 @@ TEST(QueryStripper, UnionAllMultipleReturnStatementsNamedExpressions) {
|
||||
EXPECT_THAT(stripped.named_expressions(),
|
||||
UnorderedElementsAre(Pair(2, "x"), Pair(10, "x")));
|
||||
}
|
||||
|
||||
TEST(QueryStripper, QueryReturnMap) {
|
||||
StrippedQuery stripped("RETURN {a: 1, b: 'foo'}");
|
||||
EXPECT_THAT(stripped.named_expressions(),
|
||||
UnorderedElementsAre(Pair(2, "{a: 1, b: 'foo'}")));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user