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

clp-s: Return success code from cli for legitimate queries proven to match no results before decompression and scan. #268

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions components/core/src/clp_s/clp-s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ int main(int argc, char const* argv[]) {
spdlog::set_pattern("%Y-%m-%dT%H:%M:%S.%e%z [%l] %v");
} catch (std::exception& e) {
// NOTE: We can't log an exception if the logger couldn't be constructed
return -1;
return 1;
}

CommandLineArguments command_line_arguments("clp-s");
auto parsing_result = command_line_arguments.parse_arguments(argc, argv);
switch (parsing_result) {
case CommandLineArguments::ParsingResult::Failure:
return -1;
return 1;
case CommandLineArguments::ParsingResult::InfoCommand:
return 0;
case CommandLineArguments::ParsingResult::Success:
Expand Down Expand Up @@ -133,6 +133,9 @@ int main(int argc, char const* argv[]) {

auto query_stream = std::istringstream(query);
auto expr = kql::parse_kql_expression(query_stream);
if (nullptr == expr) {
return 1;
}

if (std::dynamic_pointer_cast<EmptyExpr>(expr)) {
SPDLOG_ERROR("Query '{}' is logically false", query);
Expand Down Expand Up @@ -178,8 +181,8 @@ int main(int argc, char const* argv[]) {
// the timestamp index
EvaluateTimestampIndex timestamp_index(timestamp_dict);
if (clp_s::EvaluatedValue::False == timestamp_index.run(expr)) {
SPDLOG_ERROR("No matching timestamp ranges for query '{}'", query);
return 1;
SPDLOG_INFO("No matching timestamp ranges for query '{}'", query);
return 0;
}

auto schema_tree = clp_s::ReaderUtils::read_schema_tree(archives_dir);
Expand All @@ -188,8 +191,8 @@ int main(int argc, char const* argv[]) {
// Narrow against schemas
SchemaMatch match_pass(schema_tree, schemas);
if (expr = match_pass.run(expr); std::dynamic_pointer_cast<EmptyExpr>(expr)) {
SPDLOG_ERROR("No matching schemas for query '{}'", query);
return 1;
SPDLOG_INFO("No matching schemas for query '{}'", query);
return 0;
}

std::unique_ptr<OutputHandler> output_handler;
Expand Down
13 changes: 6 additions & 7 deletions components/core/src/clp_s/search/kql/kql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vector>

#include <antlr4-runtime.h>
#include <spdlog/spdlog.h>

#include "KqlBaseVisitor.h"
#include "KqlLexer.h"
Expand Down Expand Up @@ -221,7 +222,6 @@ class ParseTreeVisitor : public KqlBaseVisitor {
};

std::shared_ptr<Expression> parse_kql_expression(std::istream& in) {
std::shared_ptr<Expression> expr = EmptyExpr::create();
ErrorListener lexer_error_listener;
ErrorListener parser_error_listener;

Expand All @@ -234,15 +234,14 @@ std::shared_ptr<Expression> parse_kql_expression(std::istream& in) {
KqlParser::StartContext* tree = parser.start();

if (lexer_error_listener.error()) {
std::cout << "Lexer Error" << std::endl;
return expr;
SPDLOG_ERROR("Lexer error");
return {};
} else if (parser_error_listener.error()) {
std::cout << "Parser Error" << std::endl;
return expr;
SPDLOG_ERROR("Parser error");
return {};
}

ParseTreeVisitor visitor;
expr = std::any_cast<std::shared_ptr<Expression>>(visitor.visitStart(tree));
return expr;
return std::any_cast<std::shared_ptr<Expression>>(visitor.visitStart(tree));
}
} // namespace clp_s::search::kql
2 changes: 1 addition & 1 deletion components/core/src/clp_s/search/kql/kql.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace clp_s::search::kql {
/**
* Generate a search AST from a Kibana expression in an input stream
* @param in input stream containing a Kibana expression followed by EOF
* @return a search AST
* @return a search AST on success, nullptr otherwise
*/
std::shared_ptr<Expression> parse_kql_expression(std::istream& in);
} // namespace clp_s::search::kql
Expand Down
Loading