Rerun antlr on original query to generate appropriate error message
Reviewers: buda, florijan, teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D858
This commit is contained in:
parent
76fe8bfadf
commit
1f01ef6cd1
@ -42,7 +42,7 @@ class Parser {
|
|||||||
const std::string &message, std::exception_ptr) override {
|
const std::string &message, std::exception_ptr) override {
|
||||||
if (error_.empty()) {
|
if (error_.empty()) {
|
||||||
error_ = "line " + std::to_string(line) + ":" +
|
error_ = "line " + std::to_string(line) + ":" +
|
||||||
std::to_string(position) + " " + message;
|
std::to_string(position + 1) + " " + message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
#include "query/interpreter.hpp"
|
#include "query/interpreter.hpp"
|
||||||
|
|
||||||
|
#include <glog/logging.h>
|
||||||
|
|
||||||
|
#include "query/exceptions.hpp"
|
||||||
#include "query/plan/cost_estimator.hpp"
|
#include "query/plan/cost_estimator.hpp"
|
||||||
#include "query/plan/planner.hpp"
|
#include "query/plan/planner.hpp"
|
||||||
#include "query/plan/vertex_count_cache.hpp"
|
#include "query/plan/vertex_count_cache.hpp"
|
||||||
#include "utils/flag_validation.hpp"
|
#include "utils/flag_validation.hpp"
|
||||||
|
|
||||||
DEFINE_bool(query_cost_planner, true,
|
DEFINE_bool(query_cost_planner, true, "Use the cost-estimating query planner.");
|
||||||
"Use the cost-estimating query planner.");
|
|
||||||
DEFINE_bool(query_plan_cache, true, "Cache generated query plans");
|
DEFINE_bool(query_plan_cache, true, "Cache generated query plans");
|
||||||
DEFINE_VALIDATED_int32(query_plan_cache_ttl, 60,
|
DEFINE_VALIDATED_int32(query_plan_cache_ttl, 60,
|
||||||
"Time to live for cached query plans, in seconds.",
|
"Time to live for cached query plans, in seconds.",
|
||||||
@ -37,7 +39,18 @@ AstTreeStorage Interpreter::QueryToAst(const StrippedQuery &stripped,
|
|||||||
auto parser = [&] {
|
auto parser = [&] {
|
||||||
// Be careful about unlocking since parser can throw.
|
// Be careful about unlocking since parser can throw.
|
||||||
std::unique_lock<SpinLock> guard(antlr_lock_);
|
std::unique_lock<SpinLock> guard(antlr_lock_);
|
||||||
|
try {
|
||||||
return std::make_unique<frontend::opencypher::Parser>(stripped.query());
|
return std::make_unique<frontend::opencypher::Parser>(stripped.query());
|
||||||
|
} catch (const SyntaxException &e) {
|
||||||
|
// There is syntax exception in stripped query. Rerun parser with
|
||||||
|
// original query to get appropriate error messsage.
|
||||||
|
auto parser = std::make_unique<frontend::opencypher::Parser>(
|
||||||
|
stripped.original_query());
|
||||||
|
// If exception was not thrown here, it means StrippedQuery messed up
|
||||||
|
// something.
|
||||||
|
LOG(FATAL) << "Stripped query can't be parsed, original can";
|
||||||
|
return parser;
|
||||||
|
}
|
||||||
}();
|
}();
|
||||||
auto low_level_tree = parser->tree();
|
auto low_level_tree = parser->tree();
|
||||||
// AST -> high level tree
|
// AST -> high level tree
|
||||||
|
Loading…
Reference in New Issue
Block a user