@@ -23,12 +23,44 @@ bool CypherReadApp::Query(const GraphDBSession& graph, Decoder& input,
2323 auto txn = graph.GetReadTransaction ();
2424
2525 gs::runtime::GraphReadInterface gri (txn);
26- auto ctx = runtime::PlanParser::get ()
27- .parse_read_pipeline (graph.schema (),
28- gs::runtime::ContextMeta (), plan)
29- .Execute (gri, runtime::Context (), {}, timer_);
3026
27+ gs::runtime::Context ctx;
28+ gs::Status status = gs::Status::OK ();
29+ {
30+ ctx = bl::try_handle_all (
31+ [this , &gri, &plan]() -> bl::result<runtime::Context> {
32+ return runtime::PlanParser::get ()
33+ .parse_read_pipeline (gri.schema (), gs::runtime::ContextMeta (),
34+ plan)
35+ .value ()
36+ .Execute (gri, runtime::Context (), {}, timer_);
37+ },
38+ [&status](const gs::Status& err) {
39+ status = err;
40+ return runtime::Context ();
41+ },
42+ [&](const bl::error_info& err) {
43+ status =
44+ gs::Status (gs::StatusCode::INTERNAL_ERROR,
45+ " Error: " + std::to_string (err.error ().value ()) +
46+ " , Exception: " + err.exception ()->what ());
47+ return runtime::Context ();
48+ },
49+ [&]() {
50+ status = gs::Status (gs::StatusCode::UNKNOWN, " Unknown error" );
51+ return runtime::Context ();
52+ });
53+ }
54+
55+ if (!status.ok ()) {
56+ LOG (ERROR) << " Error: " << status.ToString ();
57+ // We encode the error message to the output, so that the client can
58+ // get the error message.
59+ output.put_string (status.ToString ());
60+ return false ;
61+ }
3162 runtime::Sink::sink (ctx, txn, output);
63+ return true ;
3264 } else {
3365 size_t sep = bytes.find_first_of (" &?" );
3466 auto query_str = bytes.substr (0 , sep);
@@ -38,7 +70,6 @@ bool CypherReadApp::Query(const GraphDBSession& graph, Decoder& input,
3870 auto query = std::string (query_str.data (), query_str.size ());
3971 if (!pipeline_cache_.count (query)) {
4072 if (plan_cache_.count (query)) {
41- // LOG(INFO) << "Hit cache for query ";
4273 } else {
4374 auto & query_cache = db_.getQueryCache ();
4475 std::string_view plan_str;
@@ -52,9 +83,10 @@ bool CypherReadApp::Query(const GraphDBSession& graph, Decoder& input,
5283 const std::string statistics = db_.work_dir () + " /statistics.json" ;
5384 const std::string& compiler_yaml = db_.work_dir () + " /graph.yaml" ;
5485 const std::string& tmp_dir = db_.work_dir () + " /runtime/tmp/" ;
86+ const auto & compiler_path = db_.schema ().get_compiler_path ();
5587 for (int i = 0 ; i < 3 ; ++i) {
56- if (!generate_plan (query, statistics, compiler_yaml, tmp_dir ,
57- plan_cache_)) {
88+ if (!generate_plan (query, statistics, compiler_path, compiler_yaml ,
89+ tmp_dir, plan_cache_)) {
5890 LOG (ERROR) << " Generate plan failed for query: " << query;
5991 } else {
6092 query_cache.put (query, plan_cache_[query].SerializeAsString ());
@@ -65,16 +97,18 @@ bool CypherReadApp::Query(const GraphDBSession& graph, Decoder& input,
6597 }
6698 const auto & plan = plan_cache_[query];
6799 pipeline_cache_.emplace (
68- query, runtime::PlanParser::get ().parse_read_pipeline (
69- db_.schema (), gs::runtime::ContextMeta (), plan));
100+ query, runtime::PlanParser::get ()
101+ .parse_read_pipeline (db_.schema (),
102+ gs::runtime::ContextMeta (), plan)
103+ .value ());
70104 }
71105 auto txn = graph.GetReadTransaction ();
72106
73107 gs::runtime::GraphReadInterface gri (txn);
74108 auto ctx = pipeline_cache_.at (query).Execute (gri, runtime::Context (),
75109 params, timer_);
76110
77- runtime::Sink::sink_encoder (ctx, gri, output);
111+ runtime::Sink::sink_encoder (ctx. value () , gri, output);
78112 }
79113 return true ;
80114}
0 commit comments