@@ -10,52 +10,72 @@ namespace gs {
1010bool CypherReadApp::Query (const GraphDBSession& graph, Decoder& input,
1111 Encoder& output) {
1212 auto txn = graph.GetReadTransaction ();
13- std::string_view bytes = input.get_bytes ();
13+ std::string_view _bytes = input.get_bytes ();
14+ uint8_t type = static_cast <uint8_t >(_bytes.back ());
15+ std::string_view bytes = std::string_view (_bytes.data (), _bytes.size () - 1 );
16+ if (type == Schema::ADHOC_READ_PLUGIN_ID) {
17+ auto txn = graph.GetReadTransaction ();
1418
15- size_t sep = bytes.find_first_of (" &?" );
16- auto query_str = bytes.substr (0 , sep);
17- auto params_str = bytes.substr (sep + 2 );
18- std::map<std::string, std::string> params;
19- parse_params (params_str, params);
20- auto query = std::string (query_str.data (), query_str.size ());
21- if (!pipeline_cache_.count (query)) {
22- if (plan_cache_.count (query)) {
23- // LOG(INFO) << "Hit cache for query ";
24- } else {
25- auto & query_cache = db_.getQueryCache ();
26- std::string_view plan_str;
27- if (query_cache.get (query, plan_str)) {
28- physical::PhysicalPlan plan;
29- if (!plan.ParseFromString (std::string (plan_str))) {
30- return false ;
31- }
32- plan_cache_[query] = plan;
19+ physical::PhysicalPlan plan;
20+ if (!plan.ParseFromString (std::string (bytes))) {
21+ LOG (ERROR) << " Parse plan failed..." ;
22+ return false ;
23+ }
24+
25+ LOG (INFO) << " plan: " << plan.DebugString ();
26+ gs::runtime::GraphReadInterface gri (txn);
27+ auto ctx = runtime::PlanParser::get ()
28+ .parse_read_pipeline (graph.schema (),
29+ gs::runtime::ContextMeta (), plan)
30+ .Execute (gri, runtime::Context (), {}, timer_);
31+
32+ runtime::Sink::sink (ctx, txn, output);
33+ } else {
34+ size_t sep = bytes.find_first_of (" &?" );
35+ auto query_str = bytes.substr (0 , sep);
36+ auto params_str = bytes.substr (sep + 2 );
37+ std::map<std::string, std::string> params;
38+ parse_params (params_str, params);
39+ auto query = std::string (query_str.data (), query_str.size ());
40+ if (!pipeline_cache_.count (query)) {
41+ if (plan_cache_.count (query)) {
42+ // LOG(INFO) << "Hit cache for query ";
3343 } else {
34- const std::string statistics = db_.work_dir () + " /statistics.json" ;
35- const std::string& compiler_yaml = db_.work_dir () + " /graph.yaml" ;
36- const std::string& tmp_dir = db_.work_dir () + " /runtime/tmp/" ;
37- for (int i = 0 ; i < 3 ; ++i) {
38- if (!generate_plan (query, statistics, compiler_yaml, tmp_dir,
39- plan_cache_)) {
40- LOG (ERROR) << " Generate plan failed for query: " << query;
41- } else {
42- query_cache.put (query, plan_cache_[query].SerializeAsString ());
43- break ;
44+ auto & query_cache = db_.getQueryCache ();
45+ std::string_view plan_str;
46+ if (query_cache.get (query, plan_str)) {
47+ physical::PhysicalPlan plan;
48+ if (!plan.ParseFromString (std::string (plan_str))) {
49+ return false ;
50+ }
51+ plan_cache_[query] = plan;
52+ } else {
53+ const std::string statistics = db_.work_dir () + " /statistics.json" ;
54+ const std::string& compiler_yaml = db_.work_dir () + " /graph.yaml" ;
55+ const std::string& tmp_dir = db_.work_dir () + " /runtime/tmp/" ;
56+ for (int i = 0 ; i < 3 ; ++i) {
57+ if (!generate_plan (query, statistics, compiler_yaml, tmp_dir,
58+ plan_cache_)) {
59+ LOG (ERROR) << " Generate plan failed for query: " << query;
60+ } else {
61+ query_cache.put (query, plan_cache_[query].SerializeAsString ());
62+ break ;
63+ }
4464 }
4565 }
4666 }
67+ const auto & plan = plan_cache_[query];
68+ pipeline_cache_.emplace (
69+ query, runtime::PlanParser::get ().parse_read_pipeline (
70+ db_.schema (), gs::runtime::ContextMeta (), plan));
4771 }
48- const auto & plan = plan_cache_[query];
49- pipeline_cache_.emplace (
50- query, runtime::PlanParser::get ().parse_read_pipeline (
51- db_.schema (), gs::runtime::ContextMeta (), plan));
52- }
5372
54- gs::runtime::GraphReadInterface gri (txn);
55- auto ctx = pipeline_cache_.at (query).Execute (gri, runtime::Context (), params ,
56- timer_);
73+ gs::runtime::GraphReadInterface gri (txn);
74+ auto ctx = pipeline_cache_.at (query).Execute (gri, runtime::Context (),
75+ params, timer_);
5776
58- runtime::Sink::sink_encoder (ctx, gri, output);
77+ runtime::Sink::sink_encoder (ctx, gri, output);
78+ }
5979 return true ;
6080}
6181AppWrapper CypherReadAppFactory::CreateApp (const GraphDB& db) {
0 commit comments