From 9030454132a60deec2b12c5f9a7b3a0df252761e Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 11 Mar 2017 16:11:30 +0100 Subject: [PATCH] Add compiler prototype entry point (work in progress). --- src/query/entry.hpp | 22 ++++++ tests/manual/compiler_prototype.cpp | 105 ++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 src/query/entry.hpp create mode 100644 tests/manual/compiler_prototype.cpp diff --git a/src/query/entry.hpp b/src/query/entry.hpp new file mode 100644 index 000000000..6a5ae25e2 --- /dev/null +++ b/src/query/entry.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "database/graph_db_accessor.hpp" +#include "query/frontend/opencypher/parser.hpp" + +namespace query { + +template +class Engine { + public: + Engine() {} + auto Execute(const std::string &query, GraphDbAccessor &db_accessor, + Stream &stream) { + frontend::opencypher::Parser parser(query); + auto low_level_tree = parser.tree(); + // high level tree + // typechecked tree + // logical tree + // interpret & stream results + } +}; +} diff --git a/tests/manual/compiler_prototype.cpp b/tests/manual/compiler_prototype.cpp new file mode 100644 index 000000000..7907978af --- /dev/null +++ b/tests/manual/compiler_prototype.cpp @@ -0,0 +1,105 @@ +#include + +#include "dbms/dbms.hpp" +#include "logging/default.hpp" +#include "logging/streams/stdout.cpp" +#include "query/entry.hpp" +#include "query/backend/cpp/typed_value.hpp" + +using std::cout; +using std::cin; +using std::endl; + +class ConsoleResultStream : public Loggable { + public: + ConsoleResultStream() : Loggable("ConsoleResultStream") {} + + void Header(const std::vector&) { logger.info("header"); } + + void Result(std::vector& values) { + for (auto value : values) { + logger.info(" result"); + } + } + + void Summary(const std::map&) { + logger.info("summary"); + } +}; + +int main(int argc, char* argv[]) { + // init arguments + REGISTER_ARGS(argc, argv); + + // init logger + logging::init_sync(); + logging::log->pipe(std::make_unique()); + + // init db context + Dbms dbms; + ConsoleResultStream stream; + query::Engine query_engine; + + // initialize the database + auto dba = dbms.active(); + + // props + auto name = dba.property("name"); + auto age = dba.property("age"); + auto type = dba.property("type"); + + // vertices + auto memgraph = dba.insert_vertex(); + memgraph.PropsSet(name, "Memgraph"); + auto teon = dba.insert_vertex(); + memgraph.PropsSet(name, "Teon"); + memgraph.PropsSet(age, 26); + auto mislav = dba.insert_vertex(); + memgraph.PropsSet(name, "Mislav"); + memgraph.PropsSet(age, 22); + auto florijan = dba.insert_vertex(); + memgraph.PropsSet(name, "Florijan"); + memgraph.PropsSet(age, 31); + auto xps_15 = dba.insert_vertex(); + memgraph.PropsSet(type, "PC"); + memgraph.PropsSet(name, "Dell XPS 15"); + + // edges + dba.insert_edge(teon, memgraph, dba.edge_type("MEMBER_OF")); + dba.insert_edge(mislav, memgraph, dba.edge_type("MEMBER_OF")); + dba.insert_edge(florijan, memgraph, dba.edge_type("MEMBER_OF")); + + dba.insert_edge(teon, mislav, dba.edge_type("FRIEND_OF")); + dba.insert_edge(mislav, teon, dba.edge_type("FRIEND_OF")); + dba.insert_edge(florijan, mislav, dba.edge_type("FRIEND_OF")); + dba.insert_edge(mislav, florijan, dba.edge_type("FRIEND_OF")); + dba.insert_edge(florijan, teon, dba.edge_type("FRIEND_OF")); + dba.insert_edge(teon, florijan, dba.edge_type("FRIEND_OF")); + + dba.insert_edge(memgraph, xps_15, dba.edge_type("OWNS")); + + dba.insert_edge(teon, xps_15, dba.edge_type("USES")); + dba.insert_edge(mislav, xps_15, dba.edge_type("USES")); + dba.insert_edge(florijan, xps_15, dba.edge_type("USES")); + + cout << "-- Memgraph Query Engine --" << endl; + + while (true) { + // read command + cout << "> "; + std::string command; + std::getline(cin, command); + if (command == "quit") break; + // execute command / query + try { + auto db_accessor = dbms.active(); + query_engine.Execute(command, db_accessor, stream); + } catch (const std::exception& e) { + cout << e.what() << endl; + } catch (...) { + // pass + } + } + + return 0; +}