Skip to content

Commit

Permalink
refactor(search_family): address comments 2
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Bagritsevich <[email protected]>
  • Loading branch information
BagritsevichStepan committed Sep 8, 2024
1 parent 2d3c53e commit 75aa91a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/server/search/search_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,20 @@ optional<SearchParams> ParseSearchParamsOrReply(CmdArgParser parser, ConnectionC
return params;
}

std::optional<std::string_view> ParseField(CmdArgParser* parser, bool expect_at_sign = false) {
std::optional<std::string_view> ParseField(CmdArgParser* parser) {
std::string_view field = parser->Next();
if (field.front() == '@') {
field.remove_prefix(1); // remove leading @
} else if (expect_at_sign) {
field.remove_prefix(1); // remove leading @ if exists
}
return field;
}

std::optional<std::string_view> ParseFieldWithAtSign(CmdArgParser* parser) {
std::string_view field = parser->Next();
if (field.front() != '@') {
return std::nullopt; // if we expect @, but it's not there, return nullopt
}
field.remove_prefix(1); // remove leading @
return field;
}

Expand All @@ -262,7 +269,7 @@ optional<AggregateParams> ParseAggregatorParamsOrReply(CmdArgParser parser,
if (parser.Check("GROUPBY")) {
vector<string_view> fields(parser.Next<size_t>());
for (string_view& field : fields) {
auto parsed_field = ParseField(&parser, true);
auto parsed_field = ParseFieldWithAtSign(&parser);
if (!parsed_field) {
cntx->SendError(absl::StrCat("bad arguments for GROUPBY: Unknown property '", field,
"'. Did you mean '@", field, "`?"));
Expand Down

0 comments on commit 75aa91a

Please sign in to comment.