1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-14 11:58:02 +00:00

fix(search_family): Temporary remove the error when a field name does not have the '@' sign at the beginning in the FT.AGGREGATE command (#3956)

This commit is contained in:
Stepan Bagritsevich 2024-10-21 18:35:23 +02:00 committed by GitHub
parent 478a5d476d
commit e96a99a868
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 5 deletions

View file

@ -238,12 +238,15 @@ std::string_view ParseField(CmdArgParser* parser) {
return field;
}
std::optional<std::string_view> ParseFieldWithAtSign(CmdArgParser* parser) {
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
// Temporary warning until we can throw an error
LOG(WARNING) << "bad arguments: Field name '" << field << "' should start with '@'. '@" << field
<< "' is expected";
} else {
field.remove_prefix(1); // remove leading @
}
field.remove_prefix(1); // remove leading @
return field;
}
@ -273,12 +276,17 @@ optional<AggregateParams> ParseAggregatorParamsOrReply(CmdArgParser parser,
vector<string_view> fields(parser.Next<size_t>());
for (string_view& field : fields) {
auto parsed_field = ParseFieldWithAtSign(&parser);
/*
TODO: Throw an error if the field has no '@' sign at the beginning
if (!parsed_field) {
cntx->SendError(absl::StrCat("bad arguments for GROUPBY: Unknown property '", field,
"'. Did you mean '@", field, "`?"));
return nullopt;
}
field = parsed_field.value();
} */
field = parsed_field;
}
vector<aggregate::Reducer> reducers;

View file

@ -894,6 +894,22 @@ TEST_F(SearchFamilyTest, JsonAggregateGroupBy) {
EXPECT_THAT(resp, IsUnordArrayWithSize(IsMap("avg_price", "20")));
}
TEST_F(SearchFamilyTest, JsonAggregateGroupByWithoutAtSign) {
Run({"HSET", "h1", "group", "first", "value", "1"});
Run({"HSET", "h2", "group", "second", "value", "2"});
Run({"HSET", "h3", "group", "first", "value", "3"});
auto resp =
Run({"FT.CREATE", "index", "ON", "HASH", "SCHEMA", "group", "TAG", "value", "NUMERIC"});
EXPECT_EQ(resp, "OK");
// TODO: Throw an error when no '@' is provided in the GROUPBY option
resp = Run({"FT.AGGREGATE", "index", "*", "GROUPBY", "1", "group", "REDUCE", "COUNT", "0", "AS",
"count"});
EXPECT_THAT(resp, IsUnordArrayWithSize(IsMap("count", "2", "group", "first"),
IsMap("group", "second", "count", "1")));
}
TEST_F(SearchFamilyTest, AggregateGroupByReduceSort) {
for (size_t i = 0; i < 101; i++) { // 51 even, 50 odd
Run({"hset", absl::StrCat("k", i), "even", (i % 2 == 0) ? "true" : "false", "value",