Interpreter merge.
This commit is contained in:
parent
0eeb1fc5b4
commit
10062b143c
@ -1,45 +1,55 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "database/graph_db_accessor.hpp"
|
#include "database/graph_db_accessor.hpp"
|
||||||
#include "query/frontend/opencypher/parser.hpp"
|
|
||||||
#include "query/context.hpp"
|
#include "query/context.hpp"
|
||||||
|
#include "query/frontend/opencypher/parser.hpp"
|
||||||
|
#include "query/frontend/typecheck/typecheck.hpp"
|
||||||
|
|
||||||
namespace query {
|
namespace query {
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
class Engine {
|
class Engine {
|
||||||
public:
|
public:
|
||||||
Engine() {
|
Engine() {}
|
||||||
}
|
|
||||||
auto Execute(const std::string &query, GraphDbAccessor &db_accessor,
|
auto Execute(const std::string &query, GraphDbAccessor &db_accessor,
|
||||||
Stream &stream) {
|
Stream &stream) {
|
||||||
Config config;
|
Config config;
|
||||||
Context ctx(config, db_accessor);
|
Context ctx(config, db_accessor);
|
||||||
|
|
||||||
|
// query -> AST
|
||||||
::frontend::opencypher::Parser parser(query);
|
::frontend::opencypher::Parser parser(query);
|
||||||
auto low_level_tree = parser.tree();
|
auto low_level_tree = parser.tree();
|
||||||
auto high_level_tree = low2high_tree.Apply(ctx, low_level_tree);
|
|
||||||
TypedcheckedTree typechecked_tree;
|
|
||||||
auto logical_plan = LogicalPlanner(ctx).Apply(typechecked_tree);
|
|
||||||
|
|
||||||
// interpret & stream results
|
// AST -> high level tree
|
||||||
|
auto high_level_tree = low2high_tree.Apply(ctx, low_level_tree);
|
||||||
|
|
||||||
|
// symbol table fill
|
||||||
|
SymbolTable symbol_table;
|
||||||
|
TypeCheckVisitor typecheck_visitor;
|
||||||
|
high_level_tree.Accept(typecheck_visitor);
|
||||||
|
|
||||||
|
// high level tree -> logical plan
|
||||||
|
auto logical_plan = query::Apply(high_level_tree);
|
||||||
|
|
||||||
// generate frame based on symbol table max_position
|
// generate frame based on symbol table max_position
|
||||||
Frame frame(size);
|
Frame frame(symbol_table.max_position());
|
||||||
|
|
||||||
|
// interpret
|
||||||
auto cursor = logical_plan.MakeCursor(frame);
|
auto cursor = logical_plan.MakeCursor(frame);
|
||||||
logical_plan.WriteHeader(stream);
|
logical_plan.WriteHeader(stream);
|
||||||
auto symbols = logical_plan.OutputSymbols(symbol_table);
|
auto symbols = logical_plan.OutputSymbols(symbol_table);
|
||||||
while (cursor.pull(frame, context)) {
|
while (cursor.pull(frame, context)) {
|
||||||
std::vector<TypedValue> values(symbols.size());
|
std::vector<TypedValue> values(symbols.size());
|
||||||
for (auto symbol : symbols) {
|
for (auto symbol : symbols) {
|
||||||
values.emplace_back(frame[symbol]);
|
values.emplace_back(frame[symbol]);
|
||||||
}
|
}
|
||||||
stream.Result(values);
|
stream.Result(values);
|
||||||
}
|
}
|
||||||
stream.Summary({"type": "r"});
|
stream.Summary({"type" : "r"});
|
||||||
|
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
Context ctx;
|
|
||||||
HighLevelAstConversion low2high_tree;
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
Context ctx;
|
||||||
|
HighLevelAstConversion low2high_tree;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user