Fix bug in named expression
Summary: Fix stripped named expression keyword case bug Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D670
This commit is contained in:
parent
e2a53b82c4
commit
6db9e38e1e
@ -6,6 +6,8 @@
|
||||
|
||||
### Bug Fixes and Other Changes
|
||||
|
||||
* Keywords appearing in header (named expressions) keep original case.
|
||||
|
||||
## v0.7.0
|
||||
|
||||
### Major Features and Improvements
|
||||
|
@ -70,6 +70,9 @@ StrippedQuery::StrippedQuery(const std::string &query) : original_(query) {
|
||||
token_strings.push_back(new_value);
|
||||
};
|
||||
|
||||
// Copy original tokens because we need to use original case in named
|
||||
// expressions and keywords in tokens will be lowercased in the next loop.
|
||||
auto original_tokens = tokens;
|
||||
// For every token in original query remember token index in stripped query.
|
||||
std::vector<int> position_mapping(tokens.size(), -1);
|
||||
|
||||
@ -192,9 +195,13 @@ StrippedQuery::StrippedQuery(const std::string &query) : original_(query) {
|
||||
}
|
||||
if (!has_as) {
|
||||
// Named expression is not aliased. Save string disregarding leading and
|
||||
// trailing whitespaces.
|
||||
// trailing whitespaces. Use original_tokens in which case of the keywords
|
||||
// is not lowercased.
|
||||
std::string s;
|
||||
for (auto kt = it; kt != last_non_space + 1; ++kt) {
|
||||
auto begin_token = it - tokens.begin() + original_tokens.begin();
|
||||
auto end_token =
|
||||
last_non_space - tokens.begin() + original_tokens.begin() + 1;
|
||||
for (auto kt = begin_token; kt != end_token; ++kt) {
|
||||
s += kt->second;
|
||||
}
|
||||
named_exprs_[position_mapping[it - tokens.begin()]] = s;
|
||||
|
@ -299,4 +299,12 @@ TEST(QueryStripper, Parameters) {
|
||||
UnorderedElementsAre(Pair(2, "$123"), Pair(7, "$pero"),
|
||||
Pair(12, "$`mirko ``slavko`")));
|
||||
}
|
||||
|
||||
TEST(QueryStripper, KeywordInNamedExpression) {
|
||||
StrippedQuery stripped("RETURN CoUnT(n)");
|
||||
EXPECT_EQ(stripped.literals().size(), 0);
|
||||
EXPECT_EQ(stripped.query(), "return count ( n )");
|
||||
EXPECT_THAT(stripped.named_expressions(),
|
||||
UnorderedElementsAre(Pair(2, "CoUnT(n)")));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user