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:
Matija Santl 2017-12-12 13:48:08 +01:00
parent 27370b99ff
commit 4da8312abe
2 changed files with 16 additions and 4 deletions

View File

@ -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) {

View File

@ -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'}")));
}
}