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

Add new query language plugin #2074

Merged
merged 12 commits into from
Feb 11, 2022
Prev Previous commit
Next Next commit
Try VAST language first, then all other languages
  • Loading branch information
mavam committed Feb 11, 2022
commit 243f866f968eacc21d6783b38d41c0dfaf736279
24 changes: 12 additions & 12 deletions libvast/src/system/spawn_arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ normalized_and_validated(std::vector<std::string>::const_iterator begin,
if (begin == end)
return caf::make_error(ec::syntax_error, "no query expression given");
auto query = detail::join(begin, end, " ");
// We are trying all query language plugins in a non-deterministic order.
for (const auto& plugin : plugins::get())
if (const auto* query_lang = plugin.as<query_language_plugin>()) {
if (auto expr = query_lang->parse(query))
// Always try parsing as VAST expression first.
if (auto e = to<expression>(query))
return normalize_and_validate(std::move(*e));
// If that fails, we try all query language plugins, currently in a
// non-deterministic order.
// TODO: let the user choose exactly one language instead.
for (const auto& plugin : plugins::get()) {
if (const auto* language = plugin.as<query_language_plugin>()) {
if (auto expr = language->parse(query))
return normalize_and_validate(std::move(*expr));
else
// TODO: Demote to DEBUG when polishing the PR.
VAST_ERROR("failed to parse query as {} languae: {}", plugin->name(),
VAST_DEBUG("failed to parse query as {} language: {}", language->name(),
expr.error());
mavam marked this conversation as resolved.
Show resolved Hide resolved
}
// TODO: rewrite the VAST expression as a query language plugin.
if (auto e = to<expression>(query)) {
return normalize_and_validate(std::move(*e));
} else {
VAST_DEBUG("failed to parse query as VAST expression: {}", e.error());
return std::move(e.error());
}
return caf::make_error(ec::syntax_error,
fmt::format("invalid query: {}", query));
}

caf::expected<expression>
Expand Down