-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(search_family): Add options test for the FT.AGGREGATE command #4479
base: main
Are you sure you want to change the base?
fix(search_family): Add options test for the FT.AGGREGATE command #4479
Conversation
Signed-off-by: Stepan Bagritsevich <[email protected]>
Signed-off-by: Stepan Bagritsevich <[email protected]>
Signed-off-by: Stepan Bagritsevich <[email protected]>
Signed-off-by: Stepan Bagritsevich <[email protected]>
e1d3c11
to
3570612
Compare
@@ -119,7 +119,7 @@ struct CmdArgParser { | |||
|
|||
// Check if the next value is equal to a specific tag. If equal, its consumed. | |||
template <class... Args> bool Check(std::string_view tag, Args*... args) { | |||
if (cur_i_ + sizeof...(Args) >= args_.size()) | |||
if (cur_i_ + sizeof...(Args) >= args_.size() || error_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
nonstd::unexpected_type<ErrorReply> CreateSyntaxError(std::string message) { | ||
return make_unexpected(ErrorReply{std::move(message), kSyntaxErrType}); | ||
} | ||
|
||
nonstd::unexpected_type<ErrorReply> CreateSyntaxError(std::string_view message) { | ||
return make_unexpected(ErrorReply{message, kSyntaxErrType}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implementation of these functions is shorter than their names, I don't think that you need them
while (parser->HasNext()) { | ||
if (parser->Check("NOINDEX")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can use here TryMapNext
builder->SendError(err->MakeReply()); | ||
return nullopt; | ||
} | ||
auto type = parser->MapNext("TAG"sv, SchemaField::TAG, "TEXT"sv, SchemaField::TEXT, "NUMERIC"sv, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider instead of SchemaField type use function pointer
std::pair<SchemaField, search::SchemaField::ParamsVariant> (*f)(CmdArgParser*)
while (parser->HasNext()) { | ||
// ON HASH | JSON | ||
if (parser->Check("ON")) { | ||
index.type = parser->MapNext("HASH"sv, DocIndex::HASH, "JSON"sv, DocIndex::JSON); | ||
continue; | ||
} | ||
|
||
// PREFIX count prefix [prefix ...] | ||
if (parser->Check("PREFIX")) { | ||
if (!parser->Check("1")) | ||
return CreateSyntaxError("Multiple prefixes are not supported"sv); | ||
index.prefix = string(parser->Next()); | ||
continue; | ||
} | ||
|
||
// STOWORDS count [words...] | ||
if (parser->Check("STOPWORDS")) { | ||
index.options.stopwords.clear(); | ||
for (size_t num = parser->Next<size_t>(); num > 0; num--) | ||
index.options.stopwords.emplace(parser->Next()); | ||
continue; | ||
} | ||
|
||
// SCHEMA | ||
if (parser->Check("SCHEMA")) { | ||
auto schema = ParseSchema(index.type, parser); | ||
if (!schema) | ||
return make_unexpected(schema.error()); | ||
index.schema = std::move(*schema); | ||
break; // SCHEMA always comes last | ||
} | ||
|
||
// Unsupported parameters are ignored for now | ||
parser->Skip(1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using tryMapNext and return function that can parse the next args
related to the #4204
It was a bad decision to use it because, in some cases, we were returning an error with
builder->SendError(...)
. However, in those cases, we were not handling parser errors withparser->Error()
. As a result, debug builds were crashing because of this check:Now, we ensure that parsing errors are processed in all cases.
3. Add options test for the
FT.AGGREGATE
command