2017-03-12 03:49:22 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
#include "query/frontend/ast/ast.hpp"
|
|
|
|
#include "query/frontend/logical/operator.hpp"
|
|
|
|
|
|
|
|
namespace query {
|
|
|
|
|
|
|
|
std::shared_ptr<LogicalOperator> GenMatch(
|
|
|
|
Match& match, std::shared_ptr<LogicalOperator> current_op)
|
|
|
|
{
|
|
|
|
if (current_op) {
|
|
|
|
throw std::runtime_error("Not implemented");
|
|
|
|
}
|
|
|
|
if (match.patterns_.size() != 1) {
|
|
|
|
throw std::runtime_error("Not implemented");
|
|
|
|
}
|
|
|
|
auto& pattern = match.patterns_[0];
|
2017-03-13 23:53:35 +08:00
|
|
|
if (pattern->atoms_.size() != 1) {
|
2017-03-12 03:49:22 +08:00
|
|
|
throw std::runtime_error("Not implemented");
|
|
|
|
}
|
2017-03-13 23:53:35 +08:00
|
|
|
auto node_part = std::dynamic_pointer_cast<NodeAtom>(pattern->atoms_[0]);
|
2017-03-12 06:05:38 +08:00
|
|
|
return std::make_shared<ScanAll>(node_part);
|
2017-03-12 03:49:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<LogicalOperator> GenReturn(
|
|
|
|
Return& ret, std::shared_ptr<LogicalOperator> current_op)
|
|
|
|
{
|
|
|
|
if (!current_op) {
|
|
|
|
throw std::runtime_error("Not implemented");
|
|
|
|
}
|
2017-03-13 23:53:35 +08:00
|
|
|
return std::make_shared<Produce>(current_op, ret.named_expressions_);
|
2017-03-12 03:49:22 +08:00
|
|
|
}
|
|
|
|
|
2017-03-14 16:27:46 +08:00
|
|
|
std::shared_ptr<LogicalOperator> MakeLogicalPlan(Query& query)
|
2017-03-12 03:49:22 +08:00
|
|
|
{
|
|
|
|
std::shared_ptr<LogicalOperator> current_op;
|
|
|
|
for (auto& clause : query.clauses_) {
|
|
|
|
auto* clause_ptr = clause.get();
|
|
|
|
auto* match = dynamic_cast<Match*>(clause_ptr);
|
|
|
|
auto* ret = dynamic_cast<Return*>(clause_ptr);
|
|
|
|
if (match) {
|
|
|
|
current_op = GenMatch(*match, current_op);
|
|
|
|
} else if (ret) {
|
|
|
|
return GenReturn(*ret, current_op);
|
|
|
|
} else {
|
|
|
|
throw std::runtime_error("Not implemented");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return current_op;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|