Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

BagritsevichStepan
Copy link
Contributor

@BagritsevichStepan BagritsevichStepan commented Jan 20, 2025

related to the #4204

  1. Fix some small issues during parsing of the several SEARCH methods
  2. Remove using builder in Parse* methods.
    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 with parser->Error(). As a result, debug builds were crashing because of this check:
CmdArgParser::~CmdArgParser() {
  DCHECK(!error_.has_value()) << "Parsing error occured but not checked";
}

Now, we ensure that parsing errors are processed in all cases.
3. Add options test for the FT.AGGREGATE command

@BagritsevichStepan BagritsevichStepan force-pushed the search/ft-aggregate-add-option-tests branch from e1d3c11 to 3570612 Compare January 30, 2025 16:46
@@ -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_)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Comment on lines +43 to +49
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});
}
Copy link
Contributor

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

Comment on lines +177 to +178
while (parser->HasNext()) {
if (parser->Check("NOINDEX")) {
Copy link
Contributor

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,
Copy link
Contributor

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*)

Comment on lines +212 to +246
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);
}
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants