Add ProduceCursor and Evaluate to expression
This commit is contained in:
parent
1428ce0639
commit
ef764e0367
CMakeLists.txt
src/query
@ -350,6 +350,7 @@ set(memgraph_src_files
|
||||
${src_dir}/query/stripper.cpp
|
||||
${src_dir}/query/backend/cpp/cypher_main_visitor.cpp
|
||||
${src_dir}/query/backend/cpp/typed_value.cpp
|
||||
${src_dir}/query/frontend/ast/ast.cpp
|
||||
)
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
@ -25,7 +25,7 @@ typedef traversal_template::Path<VertexAccessor, EdgeAccessor> Path;
|
||||
* TypedValue::Type. Each such type corresponds to exactly one C++ type.
|
||||
*/
|
||||
class TypedValue : public TotalOrdering<TypedValue, TypedValue, TypedValue> {
|
||||
private:
|
||||
public:
|
||||
/** Private default constructor, makes Null */
|
||||
TypedValue() : type_(Type::Null) {}
|
||||
|
||||
|
10
src/query/frontend/ast/ast.cpp
Normal file
10
src/query/frontend/ast/ast.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "query/frontend/interpret/interpret.hpp"
|
||||
#include "query/frontend/typecheck/symbol_table.hpp"
|
||||
|
||||
namespace query {
|
||||
|
||||
TypedValue Ident::Evaluate(Frame& frame, SymbolTable& symbol_table) {
|
||||
return frame[symbol_table[*this].position_];
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "database/graph_db.hpp"
|
||||
#include "query/backend/cpp/typed_value.hpp"
|
||||
|
||||
namespace query {
|
||||
|
||||
@ -13,6 +14,9 @@ using sptr = std::shared_ptr<T>;
|
||||
template <typename T>
|
||||
using uptr = std::unique_ptr<T>;
|
||||
|
||||
class Frame;
|
||||
class SymbolTable;
|
||||
|
||||
class Tree {
|
||||
public:
|
||||
Tree(const int uid) : uid_(uid) {}
|
||||
@ -22,11 +26,14 @@ private:
|
||||
};
|
||||
|
||||
class Expr : public Tree {
|
||||
public:
|
||||
virtual TypedValue Evaluate(Frame&, SymbolTable&) = 0;
|
||||
};
|
||||
|
||||
class Ident : public Tree {
|
||||
class Ident : public Expr {
|
||||
public:
|
||||
std::string identifier_;
|
||||
std::string identifier_;
|
||||
TypedValue Evaluate(Frame& frame, SymbolTable& symbol_table) override;
|
||||
};
|
||||
|
||||
class Part {
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include "query/backend/cpp/typed_value.hpp"
|
||||
|
||||
namespace query {
|
||||
|
||||
class Frame {
|
||||
public:
|
||||
Frame(int size) : size_(size), elems_(size_) {}
|
||||
@ -16,3 +18,4 @@ class Frame {
|
||||
std::vector<TypedValue> elems_;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -55,14 +55,15 @@ class ScanAll : public LogicalOperator {
|
||||
for (auto label : node_part->labels_) {
|
||||
if (!vertex.has_label(label)) return false;
|
||||
}
|
||||
frame[symbol_table[parent_.node_part_->identifier_].position_] = vertex;
|
||||
frame[symbol_table[node_part->identifier_].position_] = vertex;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
uptr<Cursor> MakeCursor(GraphDbAccessor db) override {
|
||||
return new ScanAllCursor(*this, db);
|
||||
Cursor* cursor = new ScanAllCursor(*this, db);
|
||||
return uptr<Cursor>(cursor);
|
||||
}
|
||||
|
||||
friend class ScanAll::ScanAllCursor;
|
||||
@ -77,6 +78,18 @@ class Produce : public LogicalOperator {
|
||||
}
|
||||
|
||||
private:
|
||||
class ProduceCursor : public Cursor {
|
||||
public:
|
||||
ProduceCursor(Produce& parent) : parent_(parent) {}
|
||||
bool pull(Frame &frame, SymbolTable& symbol_table) override {
|
||||
for (auto expr : parent_.exprs_) {
|
||||
frame[symbol_table[*expr].position_] = expr->Evaluate(frame, symbol_table);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
Produce& parent_;
|
||||
};
|
||||
std::vector<sptr<Expr>> exprs_;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user