Query::Plan - const correctness

Summary:
Made all LogicalOperators const correct.
Fixed one LogicalOperator test.
Added explicit return values to Frame and SymbolTable at and [] methods.

Reviewers: teon.banek

Reviewed By: teon.banek

Differential Revision: https://phabricator.memgraph.io/D259
This commit is contained in:
florijan 2017-04-11 12:29:20 +02:00
parent d92caf1163
commit 7981bd19e0
5 changed files with 233 additions and 223 deletions

View File

@ -15,8 +15,8 @@ class Frame {
public:
Frame(int size) : size_(size), elems_(size_) {}
auto &operator[](const Symbol &symbol) { return elems_[symbol.position_]; }
const auto &operator[](const Symbol &symbol) const {
TypedValue &operator[](const Symbol &symbol) { return elems_[symbol.position_]; }
const TypedValue &operator[](const Symbol &symbol) const {
return elems_[symbol.position_];
}
@ -27,7 +27,7 @@ class Frame {
class ExpressionEvaluator : public TreeVisitorBase {
public:
ExpressionEvaluator(Frame &frame, SymbolTable &symbol_table)
ExpressionEvaluator(Frame &frame, const SymbolTable &symbol_table)
: frame_(frame), symbol_table_(symbol_table) {}
/** When evaluting @c RecordAccessor, use @c SwitchNew to get the new data, as
@ -63,12 +63,12 @@ class ExpressionEvaluator : public TreeVisitorBase {
using TreeVisitorBase::PostVisit;
void PostVisit(NamedExpression &named_expression) override {
auto symbol = symbol_table_[named_expression];
auto symbol = symbol_table_.at(named_expression);
frame_[symbol] = PopBack();
}
void Visit(Identifier &ident) override {
auto value = frame_[symbol_table_[ident]];
auto value = frame_[symbol_table_.at(ident)];
SwitchAccessors(value);
result_stack_.emplace_back(std::move(value));
}
@ -180,7 +180,7 @@ class ExpressionEvaluator : public TreeVisitorBase {
}
Frame &frame_;
SymbolTable &symbol_table_;
const SymbolTable &symbol_table_;
std::list<TypedValue> result_stack_;
// If true, use SwitchNew on evaluated record accessors. This should be done
// only in expressions which may return one. E.g. identifier, list indexing.

View File

@ -7,8 +7,8 @@
namespace query {
namespace plan {
CreateNode::CreateNode(NodeAtom *node_atom,
std::shared_ptr<LogicalOperator> input)
CreateNode::CreateNode(const NodeAtom *node_atom,
const std::shared_ptr<LogicalOperator> &input)
: node_atom_(node_atom), input_(input) {}
void CreateNode::Accept(LogicalOperatorVisitor &visitor) {
@ -23,14 +23,14 @@ std::unique_ptr<Cursor> CreateNode::MakeCursor(GraphDbAccessor &db) {
return std::make_unique<CreateNodeCursor>(*this, db);
}
CreateNode::CreateNodeCursor::CreateNodeCursor(CreateNode &self,
CreateNode::CreateNodeCursor::CreateNodeCursor(const CreateNode &self,
GraphDbAccessor &db)
: self_(self),
db_(db),
input_cursor_(self.input_ ? self.input_->MakeCursor(db) : nullptr) {}
bool CreateNode::CreateNodeCursor::Pull(Frame &frame,
SymbolTable &symbol_table) {
const SymbolTable &symbol_table) {
if (input_cursor_) {
if (input_cursor_->Pull(frame, symbol_table)) {
Create(frame, symbol_table);
@ -46,7 +46,7 @@ bool CreateNode::CreateNodeCursor::Pull(Frame &frame,
}
void CreateNode::CreateNodeCursor::Create(Frame &frame,
SymbolTable &symbol_table) {
const SymbolTable &symbol_table) {
auto new_node = db_.insert_vertex();
for (auto label : self_.node_atom_->labels_) new_node.add_label(label);
@ -58,12 +58,12 @@ void CreateNode::CreateNodeCursor::Create(Frame &frame,
kv.second->Accept(evaluator);
new_node.PropsSet(kv.first, evaluator.PopBack());
}
frame[symbol_table[*self_.node_atom_->identifier_]] = new_node;
frame[symbol_table.at(*self_.node_atom_->identifier_)] = new_node;
}
CreateExpand::CreateExpand(NodeAtom *node_atom, EdgeAtom *edge_atom,
CreateExpand::CreateExpand(const NodeAtom *node_atom, const EdgeAtom *edge_atom,
const std::shared_ptr<LogicalOperator> &input,
const Symbol &input_symbol, bool node_existing)
Symbol input_symbol, bool node_existing)
: node_atom_(node_atom),
edge_atom_(edge_atom),
input_(input),
@ -82,12 +82,12 @@ std::unique_ptr<Cursor> CreateExpand::MakeCursor(GraphDbAccessor &db) {
return std::make_unique<CreateExpandCursor>(*this, db);
}
CreateExpand::CreateExpandCursor::CreateExpandCursor(CreateExpand &self,
CreateExpand::CreateExpandCursor::CreateExpandCursor(const CreateExpand &self,
GraphDbAccessor &db)
: self_(self), db_(db), input_cursor_(self.input_->MakeCursor(db)) {}
bool CreateExpand::CreateExpandCursor::Pull(Frame &frame,
SymbolTable &symbol_table) {
const SymbolTable &symbol_table) {
if (!input_cursor_->Pull(frame, symbol_table)) return false;
// get the origin vertex
@ -121,10 +121,11 @@ bool CreateExpand::CreateExpandCursor::Pull(Frame &frame,
}
VertexAccessor &CreateExpand::CreateExpandCursor::OtherVertex(
Frame &frame, SymbolTable &symbol_table, ExpressionEvaluator &evaluator) {
Frame &frame, const SymbolTable &symbol_table,
ExpressionEvaluator &evaluator) {
if (self_.node_existing_) {
TypedValue &dest_node_value =
frame[symbol_table[*self_.node_atom_->identifier_]];
frame[symbol_table.at(*self_.node_atom_->identifier_)];
return dest_node_value.Value<VertexAccessor>();
} else {
// the node does not exist, it needs to be created
@ -134,7 +135,7 @@ VertexAccessor &CreateExpand::CreateExpandCursor::OtherVertex(
kv.second->Accept(evaluator);
node.PropsSet(kv.first, evaluator.PopBack());
}
auto symbol = symbol_table[*self_.node_atom_->identifier_];
auto symbol = symbol_table.at(*self_.node_atom_->identifier_);
frame[symbol] = node;
return frame[symbol].Value<VertexAccessor>();
}
@ -142,20 +143,21 @@ VertexAccessor &CreateExpand::CreateExpandCursor::OtherVertex(
void CreateExpand::CreateExpandCursor::CreateEdge(
VertexAccessor &from, VertexAccessor &to, Frame &frame,
SymbolTable &symbol_table, ExpressionEvaluator &evaluator) {
const SymbolTable &symbol_table, ExpressionEvaluator &evaluator) {
EdgeAccessor edge =
db_.insert_edge(from, to, self_.edge_atom_->edge_types_[0]);
for (auto kv : self_.edge_atom_->properties_) {
kv.second->Accept(evaluator);
edge.PropsSet(kv.first, evaluator.PopBack());
}
frame[symbol_table[*self_.edge_atom_->identifier_]] = edge;
frame[symbol_table.at(*self_.edge_atom_->identifier_)] = edge;
}
ScanAll::ScanAll(NodeAtom *node_atom)
ScanAll::ScanAll(const NodeAtom *node_atom)
: node_atom_(node_atom), input_(nullptr) {}
ScanAll::ScanAll(NodeAtom *node_atom, std::shared_ptr<LogicalOperator> input)
ScanAll::ScanAll(const NodeAtom *node_atom,
const std::shared_ptr<LogicalOperator> &input)
: node_atom_(node_atom), input_(input) {}
void ScanAll::Accept(LogicalOperatorVisitor &visitor) {
@ -170,13 +172,14 @@ std::unique_ptr<Cursor> ScanAll::MakeCursor(GraphDbAccessor &db) {
return std::make_unique<ScanAllCursor>(*this, db);
}
ScanAll::ScanAllCursor::ScanAllCursor(ScanAll &self, GraphDbAccessor &db)
ScanAll::ScanAllCursor::ScanAllCursor(const ScanAll &self, GraphDbAccessor &db)
: self_(self),
input_cursor_(self.input_ ? self.input_->MakeCursor(db) : nullptr),
vertices_(db.vertices()),
vertices_it_(vertices_.begin()) {}
bool ScanAll::ScanAllCursor::Pull(Frame &frame, SymbolTable &symbol_table) {
bool ScanAll::ScanAllCursor::Pull(Frame &frame,
const SymbolTable &symbol_table) {
if (input_cursor_) {
// using an input. we need to pull from it if we are in the first pull
// of this cursor, or if we have exhausted vertices_it_
@ -193,13 +196,13 @@ bool ScanAll::ScanAllCursor::Pull(Frame &frame, SymbolTable &symbol_table) {
// through it once
if (vertices_it_ == vertices_.end()) return false;
frame[symbol_table[*self_.node_atom_->identifier_]] = *vertices_it_++;
frame[symbol_table.at(*self_.node_atom_->identifier_)] = *vertices_it_++;
return true;
}
Expand::Expand(NodeAtom *node_atom, EdgeAtom *edge_atom,
Expand::Expand(const NodeAtom *node_atom, const EdgeAtom *edge_atom,
const std::shared_ptr<LogicalOperator> &input,
const Symbol &input_symbol, bool node_cycle, bool edge_cycle)
Symbol input_symbol, bool node_cycle, bool edge_cycle)
: node_atom_(node_atom),
edge_atom_(edge_atom),
input_(input),
@ -219,10 +222,10 @@ std::unique_ptr<Cursor> Expand::MakeCursor(GraphDbAccessor &db) {
return std::make_unique<ExpandCursor>(*this, db);
}
Expand::ExpandCursor::ExpandCursor(Expand &self, GraphDbAccessor &db)
Expand::ExpandCursor::ExpandCursor(const Expand &self, GraphDbAccessor &db)
: self_(self), input_cursor_(self.input_->MakeCursor(db)) {}
bool Expand::ExpandCursor::Pull(Frame &frame, SymbolTable &symbol_table) {
bool Expand::ExpandCursor::Pull(Frame &frame, const SymbolTable &symbol_table) {
while (true) {
// attempt to get a value from the incoming edges
if (in_edges_ && *in_edges_it_ != in_edges_->end()) {
@ -253,7 +256,8 @@ bool Expand::ExpandCursor::Pull(Frame &frame, SymbolTable &symbol_table) {
}
}
bool Expand::ExpandCursor::InitEdges(Frame &frame, SymbolTable &symbol_table) {
bool Expand::ExpandCursor::InitEdges(Frame &frame,
const SymbolTable &symbol_table) {
if (!input_cursor_->Pull(frame, symbol_table)) return false;
TypedValue &vertex_value = frame[self_.input_symbol_];
@ -286,22 +290,23 @@ bool Expand::ExpandCursor::InitEdges(Frame &frame, SymbolTable &symbol_table) {
return true;
}
bool Expand::ExpandCursor::HandleEdgeCycle(EdgeAccessor &new_edge, Frame &frame,
SymbolTable &symbol_table) {
bool Expand::ExpandCursor::HandleEdgeCycle(const EdgeAccessor &new_edge,
Frame &frame,
const SymbolTable &symbol_table) {
if (self_.edge_cycle_) {
TypedValue &old_edge_value =
frame[symbol_table[*self_.edge_atom_->identifier_]];
frame[symbol_table.at(*self_.edge_atom_->identifier_)];
return old_edge_value.Value<EdgeAccessor>() == new_edge;
} else {
// not doing a cycle, so put the new_edge into the frame and return true
frame[symbol_table[*self_.edge_atom_->identifier_]] = new_edge;
frame[symbol_table.at(*self_.edge_atom_->identifier_)] = new_edge;
return true;
}
}
bool Expand::ExpandCursor::PullNode(EdgeAccessor &new_edge,
bool Expand::ExpandCursor::PullNode(const EdgeAccessor &new_edge,
EdgeAtom::Direction direction, Frame &frame,
SymbolTable &symbol_table) {
const SymbolTable &symbol_table) {
switch (direction) {
case EdgeAtom::Direction::LEFT:
return HandleNodeCycle(new_edge.from(), frame, symbol_table);
@ -312,22 +317,22 @@ bool Expand::ExpandCursor::PullNode(EdgeAccessor &new_edge,
}
}
bool Expand::ExpandCursor::HandleNodeCycle(VertexAccessor new_node,
bool Expand::ExpandCursor::HandleNodeCycle(const VertexAccessor new_node,
Frame &frame,
SymbolTable &symbol_table) {
const SymbolTable &symbol_table) {
if (self_.node_cycle_) {
TypedValue &old_node_value =
frame[symbol_table[*self_.node_atom_->identifier_]];
frame[symbol_table.at(*self_.node_atom_->identifier_)];
return old_node_value.Value<VertexAccessor>() == new_node;
} else {
// not doing a cycle, so put the new_edge into the frame and return true
frame[symbol_table[*self_.node_atom_->identifier_]] = new_node;
frame[symbol_table.at(*self_.node_atom_->identifier_)] = new_node;
return true;
}
}
NodeFilter::NodeFilter(std::shared_ptr<LogicalOperator> input,
Symbol input_symbol, NodeAtom *node_atom)
NodeFilter::NodeFilter(const std::shared_ptr<LogicalOperator> &input,
Symbol input_symbol, const NodeAtom *node_atom)
: input_(input), input_symbol_(input_symbol), node_atom_(node_atom) {}
void NodeFilter::Accept(LogicalOperatorVisitor &visitor) {
@ -342,12 +347,12 @@ std::unique_ptr<Cursor> NodeFilter::MakeCursor(GraphDbAccessor &db) {
return std::make_unique<NodeFilterCursor>(*this, db);
}
NodeFilter::NodeFilterCursor::NodeFilterCursor(NodeFilter &self,
NodeFilter::NodeFilterCursor::NodeFilterCursor(const NodeFilter &self,
GraphDbAccessor &db)
: self_(self), input_cursor_(self_.input_->MakeCursor(db)) {}
bool NodeFilter::NodeFilterCursor::Pull(Frame &frame,
SymbolTable &symbol_table) {
const SymbolTable &symbol_table) {
while (input_cursor_->Pull(frame, symbol_table)) {
auto &vertex = frame[self_.input_symbol_].Value<VertexAccessor>();
// Filter needs to use the old, unmodified vertex, even though we may change
@ -358,9 +363,9 @@ bool NodeFilter::NodeFilterCursor::Pull(Frame &frame,
return false;
}
bool NodeFilter::NodeFilterCursor::VertexPasses(const VertexAccessor &vertex,
Frame &frame,
SymbolTable &symbol_table) {
bool NodeFilter::NodeFilterCursor::VertexPasses(
const VertexAccessor &vertex, Frame &frame,
const SymbolTable &symbol_table) {
for (auto label : self_.node_atom_->labels_)
if (!vertex.has_label(label)) return false;
@ -378,8 +383,8 @@ bool NodeFilter::NodeFilterCursor::VertexPasses(const VertexAccessor &vertex,
return true;
}
EdgeFilter::EdgeFilter(std::shared_ptr<LogicalOperator> input,
Symbol input_symbol, EdgeAtom *edge_atom)
EdgeFilter::EdgeFilter(const std::shared_ptr<LogicalOperator> &input,
Symbol input_symbol, const EdgeAtom *edge_atom)
: input_(input), input_symbol_(input_symbol), edge_atom_(edge_atom) {}
void EdgeFilter::Accept(LogicalOperatorVisitor &visitor) {
@ -393,12 +398,12 @@ void EdgeFilter::Accept(LogicalOperatorVisitor &visitor) {
std::unique_ptr<Cursor> EdgeFilter::MakeCursor(GraphDbAccessor &db) {
return std::make_unique<EdgeFilterCursor>(*this, db);
}
EdgeFilter::EdgeFilterCursor::EdgeFilterCursor(EdgeFilter &self,
EdgeFilter::EdgeFilterCursor::EdgeFilterCursor(const EdgeFilter &self,
GraphDbAccessor &db)
: self_(self), input_cursor_(self_.input_->MakeCursor(db)) {}
bool EdgeFilter::EdgeFilterCursor::Pull(Frame &frame,
SymbolTable &symbol_table) {
const SymbolTable &symbol_table) {
while (input_cursor_->Pull(frame, symbol_table)) {
auto &edge = frame[self_.input_symbol_].Value<EdgeAccessor>();
// Filter needs to use the old, unmodified edge, even though we may change
@ -411,7 +416,7 @@ bool EdgeFilter::EdgeFilterCursor::Pull(Frame &frame,
bool EdgeFilter::EdgeFilterCursor::EdgePasses(const EdgeAccessor &edge,
Frame &frame,
SymbolTable &symbol_table) {
const SymbolTable &symbol_table) {
// edge type filtering - logical OR
const auto &types = self_.edge_atom_->edge_types_;
GraphDbTypes::EdgeType type = edge.edge_type();
@ -449,10 +454,10 @@ std::unique_ptr<Cursor> Filter::MakeCursor(GraphDbAccessor &db) {
return std::make_unique<FilterCursor>(*this, db);
}
Filter::FilterCursor::FilterCursor(Filter &self, GraphDbAccessor &db)
Filter::FilterCursor::FilterCursor(const Filter &self, GraphDbAccessor &db)
: self_(self), input_cursor_(self_.input_->MakeCursor(db)) {}
bool Filter::FilterCursor::Pull(Frame &frame, SymbolTable &symbol_table) {
bool Filter::FilterCursor::Pull(Frame &frame, const SymbolTable &symbol_table) {
ExpressionEvaluator evaluator(frame, symbol_table);
// Like all filters, newly set values should not affect filtering of old nodes
// and edges.
@ -467,8 +472,8 @@ bool Filter::FilterCursor::Pull(Frame &frame, SymbolTable &symbol_table) {
return false;
}
Produce::Produce(std::shared_ptr<LogicalOperator> input,
std::vector<NamedExpression *> named_expressions)
Produce::Produce(const std::shared_ptr<LogicalOperator> &input,
const std::vector<NamedExpression *> named_expressions)
: input_(input), named_expressions_(named_expressions) {}
void Produce::Accept(LogicalOperatorVisitor &visitor) {
@ -487,10 +492,11 @@ const std::vector<NamedExpression *> &Produce::named_expressions() {
return named_expressions_;
}
Produce::ProduceCursor::ProduceCursor(Produce &self, GraphDbAccessor &db)
Produce::ProduceCursor::ProduceCursor(const Produce &self, GraphDbAccessor &db)
: self_(self),
input_cursor_(self.input_ ? self_.input_->MakeCursor(db) : nullptr) {}
bool Produce::ProduceCursor::Pull(Frame &frame, SymbolTable &symbol_table) {
bool Produce::ProduceCursor::Pull(Frame &frame,
const SymbolTable &symbol_table) {
ExpressionEvaluator evaluator(frame, symbol_table);
// Produce should always yield the latest results.
evaluator.SwitchNew();
@ -526,10 +532,10 @@ std::unique_ptr<Cursor> Delete::MakeCursor(GraphDbAccessor &db) {
return std::make_unique<DeleteCursor>(*this, db);
}
Delete::DeleteCursor::DeleteCursor(Delete &self, GraphDbAccessor &db)
Delete::DeleteCursor::DeleteCursor(const Delete &self, GraphDbAccessor &db)
: self_(self), db_(db), input_cursor_(self_.input_->MakeCursor(db)) {}
bool Delete::DeleteCursor::Pull(Frame &frame, SymbolTable &symbol_table) {
bool Delete::DeleteCursor::Pull(Frame &frame, const SymbolTable &symbol_table) {
if (!input_cursor_->Pull(frame, symbol_table)) return false;
ExpressionEvaluator evaluator(frame, symbol_table);
@ -563,7 +569,7 @@ bool Delete::DeleteCursor::Pull(Frame &frame, SymbolTable &symbol_table) {
return true;
}
SetProperty::SetProperty(const std::shared_ptr<LogicalOperator> input,
SetProperty::SetProperty(const std::shared_ptr<LogicalOperator> &input,
PropertyLookup *lhs, Expression *rhs)
: input_(input), lhs_(lhs), rhs_(rhs) {}
@ -579,12 +585,12 @@ std::unique_ptr<Cursor> SetProperty::MakeCursor(GraphDbAccessor &db) {
return std::make_unique<SetPropertyCursor>(*this, db);
}
SetProperty::SetPropertyCursor::SetPropertyCursor(SetProperty &self,
SetProperty::SetPropertyCursor::SetPropertyCursor(const SetProperty &self,
GraphDbAccessor &db)
: self_(self), input_cursor_(self.input_->MakeCursor(db)) {}
bool SetProperty::SetPropertyCursor::Pull(Frame &frame,
SymbolTable &symbol_table) {
const SymbolTable &symbol_table) {
if (!input_cursor_->Pull(frame, symbol_table)) return false;
ExpressionEvaluator evaluator(frame, symbol_table);
@ -614,8 +620,8 @@ bool SetProperty::SetPropertyCursor::Pull(Frame &frame,
return true;
}
SetProperties::SetProperties(const std::shared_ptr<LogicalOperator> input,
const Symbol input_symbol, Expression *rhs, Op op)
SetProperties::SetProperties(const std::shared_ptr<LogicalOperator> &input,
Symbol input_symbol, Expression *rhs, Op op)
: input_(input), input_symbol_(input_symbol), rhs_(rhs), op_(op) {}
void SetProperties::Accept(LogicalOperatorVisitor &visitor) {
@ -630,12 +636,12 @@ std::unique_ptr<Cursor> SetProperties::MakeCursor(GraphDbAccessor &db) {
return std::make_unique<SetPropertiesCursor>(*this, db);
}
SetProperties::SetPropertiesCursor::SetPropertiesCursor(SetProperties &self,
GraphDbAccessor &db)
SetProperties::SetPropertiesCursor::SetPropertiesCursor(
const SetProperties &self, GraphDbAccessor &db)
: self_(self), db_(db), input_cursor_(self.input_->MakeCursor(db)) {}
bool SetProperties::SetPropertiesCursor::Pull(Frame &frame,
SymbolTable &symbol_table) {
const SymbolTable &symbol_table) {
if (!input_cursor_->Pull(frame, symbol_table)) return false;
TypedValue &lhs = frame[self_.input_symbol_];
@ -698,8 +704,8 @@ template void SetProperties::SetPropertiesCursor::Set(
template void SetProperties::SetPropertiesCursor::Set(
RecordAccessor<Edge> &record, const TypedValue &rhs);
SetLabels::SetLabels(const std::shared_ptr<LogicalOperator> input,
const Symbol input_symbol,
SetLabels::SetLabels(const std::shared_ptr<LogicalOperator> &input,
Symbol input_symbol,
const std::vector<GraphDbTypes::Label> &labels)
: input_(input), input_symbol_(input_symbol), labels_(labels) {}
@ -715,11 +721,12 @@ std::unique_ptr<Cursor> SetLabels::MakeCursor(GraphDbAccessor &db) {
return std::make_unique<SetLabelsCursor>(*this, db);
}
SetLabels::SetLabelsCursor::SetLabelsCursor(SetLabels &self,
SetLabels::SetLabelsCursor::SetLabelsCursor(const SetLabels &self,
GraphDbAccessor &db)
: self_(self), input_cursor_(self.input_->MakeCursor(db)) {}
bool SetLabels::SetLabelsCursor::Pull(Frame &frame, SymbolTable &symbol_table) {
bool SetLabels::SetLabelsCursor::Pull(Frame &frame,
const SymbolTable &symbol_table) {
if (!input_cursor_->Pull(frame, symbol_table)) return false;
TypedValue &vertex_value = frame[self_.input_symbol_];
@ -730,7 +737,7 @@ bool SetLabels::SetLabelsCursor::Pull(Frame &frame, SymbolTable &symbol_table) {
return true;
}
RemoveProperty::RemoveProperty(const std::shared_ptr<LogicalOperator> input,
RemoveProperty::RemoveProperty(const std::shared_ptr<LogicalOperator> &input,
PropertyLookup *lhs)
: input_(input), lhs_(lhs) {}
@ -746,12 +753,12 @@ std::unique_ptr<Cursor> RemoveProperty::MakeCursor(GraphDbAccessor &db) {
return std::make_unique<RemovePropertyCursor>(*this, db);
}
RemoveProperty::RemovePropertyCursor::RemovePropertyCursor(RemoveProperty &self,
GraphDbAccessor &db)
RemoveProperty::RemovePropertyCursor::RemovePropertyCursor(
const RemoveProperty &self, GraphDbAccessor &db)
: self_(self), input_cursor_(self.input_->MakeCursor(db)) {}
bool RemoveProperty::RemovePropertyCursor::Pull(Frame &frame,
SymbolTable &symbol_table) {
bool RemoveProperty::RemovePropertyCursor::Pull(
Frame &frame, const SymbolTable &symbol_table) {
if (!input_cursor_->Pull(frame, symbol_table)) return false;
ExpressionEvaluator evaluator(frame, symbol_table);
@ -776,8 +783,8 @@ bool RemoveProperty::RemovePropertyCursor::Pull(Frame &frame,
return true;
}
RemoveLabels::RemoveLabels(const std::shared_ptr<LogicalOperator> input,
const Symbol input_symbol,
RemoveLabels::RemoveLabels(const std::shared_ptr<LogicalOperator> &input,
Symbol input_symbol,
const std::vector<GraphDbTypes::Label> &labels)
: input_(input), input_symbol_(input_symbol), labels_(labels) {}
@ -793,12 +800,12 @@ std::unique_ptr<Cursor> RemoveLabels::MakeCursor(GraphDbAccessor &db) {
return std::make_unique<RemoveLabelsCursor>(*this, db);
}
RemoveLabels::RemoveLabelsCursor::RemoveLabelsCursor(RemoveLabels &self,
RemoveLabels::RemoveLabelsCursor::RemoveLabelsCursor(const RemoveLabels &self,
GraphDbAccessor &db)
: self_(self), input_cursor_(self.input_->MakeCursor(db)) {}
bool RemoveLabels::RemoveLabelsCursor::Pull(Frame &frame,
SymbolTable &symbol_table) {
const SymbolTable &symbol_table) {
if (!input_cursor_->Pull(frame, symbol_table)) return false;
TypedValue &vertex_value = frame[self_.input_symbol_];
@ -835,13 +842,13 @@ std::unique_ptr<Cursor> ExpandUniquenessFilter<TAccessor>::MakeCursor(
template <typename TAccessor>
ExpandUniquenessFilter<TAccessor>::ExpandUniquenessFilterCursor::
ExpandUniquenessFilterCursor(ExpandUniquenessFilter &self,
ExpandUniquenessFilterCursor(const ExpandUniquenessFilter &self,
GraphDbAccessor &db)
: self_(self), input_cursor_(self.input_->MakeCursor(db)) {}
template <typename TAccessor>
bool ExpandUniquenessFilter<TAccessor>::ExpandUniquenessFilterCursor::Pull(
Frame &frame, SymbolTable &symbol_table) {
Frame &frame, const SymbolTable &symbol_table) {
auto expansion_ok = [&]() {
TypedValue &expand_value = frame[self_.expand_symbol_];
TAccessor &expand_accessor = expand_value.Value<TAccessor>();
@ -892,7 +899,7 @@ void ReconstructTypedValue(TypedValue &value) {
}
}
Accumulate::Accumulate(std::shared_ptr<LogicalOperator> input,
Accumulate::Accumulate(const std::shared_ptr<LogicalOperator> &input,
const std::vector<Symbol> &symbols, bool advance_command)
: input_(input), symbols_(symbols), advance_command_(advance_command) {}
@ -907,12 +914,12 @@ std::unique_ptr<Cursor> Accumulate::MakeCursor(GraphDbAccessor &db) {
return std::make_unique<Accumulate::AccumulateCursor>(*this, db);
}
Accumulate::AccumulateCursor::AccumulateCursor(Accumulate &self,
Accumulate::AccumulateCursor::AccumulateCursor(const Accumulate &self,
GraphDbAccessor &db)
: self_(self), db_(db), input_cursor_(self.input_->MakeCursor(db)) {}
bool Accumulate::AccumulateCursor::Pull(Frame &frame,
SymbolTable &symbol_table) {
const SymbolTable &symbol_table) {
// cache all the input
if (!pulled_all_input_) {
while (input_cursor_->Pull(frame, symbol_table)) {
@ -939,7 +946,7 @@ bool Accumulate::AccumulateCursor::Pull(Frame &frame,
Aggregate::Aggregate(const std::shared_ptr<LogicalOperator> &input,
const std::vector<Aggregate::Element> &aggregations,
std::vector<NamedExpression *> group_by)
const std::vector<NamedExpression *> group_by)
: input_(input), aggregations_(aggregations), group_by_(group_by) {}
void Aggregate::Accept(LogicalOperatorVisitor &visitor) {

View File

@ -34,7 +34,7 @@ class Cursor {
* iteration.
* @param SymbolTable Used to get the position of symbols in frame.
*/
virtual bool Pull(Frame &, SymbolTable &) = 0;
virtual bool Pull(Frame &, const SymbolTable &) = 0;
virtual ~Cursor() {}
};
@ -101,32 +101,33 @@ class CreateNode : public LogicalOperator {
* If a valid input, then a node will be created for each
* successful pull from the given input.
*/
CreateNode(NodeAtom *node_atom, std::shared_ptr<LogicalOperator> input);
CreateNode(const NodeAtom *node_atom,
const std::shared_ptr<LogicalOperator> &input);
void Accept(LogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
NodeAtom *node_atom_ = nullptr;
std::shared_ptr<LogicalOperator> input_;
const NodeAtom *node_atom_ = nullptr;
const std::shared_ptr<LogicalOperator> input_;
class CreateNodeCursor : public Cursor {
public:
CreateNodeCursor(CreateNode &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
CreateNodeCursor(const CreateNode &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
CreateNode &self_;
const CreateNode &self_;
GraphDbAccessor &db_;
// optional, used in situations in which this create op
// pulls from an input (in MATCH CREATE, CREATE ... CREATE)
std::unique_ptr<Cursor> input_cursor_;
const std::unique_ptr<Cursor> input_cursor_;
// control switch when creating only one node (nullptr input)
bool did_create_{false};
/**
* Creates a single node and places it in the frame.
*/
void Create(Frame &frame, SymbolTable &symbol_table);
void Create(Frame &frame, const SymbolTable &symbol_table);
};
};
@ -157,41 +158,41 @@ class CreateExpand : public LogicalOperator {
* @param node_existing @c bool indicating whether the @c node_atom refers to
* an existing node. If @c false, the operator will also create the node.
*/
CreateExpand(NodeAtom *node_atom, EdgeAtom *edge_atom,
CreateExpand(const NodeAtom *node_atom, const EdgeAtom *edge_atom,
const std::shared_ptr<LogicalOperator> &input,
const Symbol &input_symbol, bool node_existing);
Symbol input_symbol, bool node_existing);
void Accept(LogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
// info on what's getting expanded
NodeAtom *node_atom_;
EdgeAtom *edge_atom_;
const NodeAtom *node_atom_;
const EdgeAtom *edge_atom_;
// the input op and the symbol under which the op's result
// can be found in the frame
std::shared_ptr<LogicalOperator> input_;
const std::shared_ptr<LogicalOperator> input_;
const Symbol input_symbol_;
// if the given node atom refers to an existing node
// (either matched or created)
bool node_existing_;
const bool node_existing_;
class CreateExpandCursor : public Cursor {
public:
CreateExpandCursor(CreateExpand &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
CreateExpandCursor(const CreateExpand &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
CreateExpand &self_;
const CreateExpand &self_;
GraphDbAccessor &db_;
std::unique_ptr<Cursor> input_cursor_;
const std::unique_ptr<Cursor> input_cursor_;
/**
* Helper function for getting an existing node or creating a new one.
* @return The newly created or already existing node.
*/
VertexAccessor &OtherVertex(Frame &frame, SymbolTable &symbol_table,
VertexAccessor &OtherVertex(Frame &frame, const SymbolTable &symbol_table,
ExpressionEvaluator &evaluator);
/**
@ -203,7 +204,8 @@ class CreateExpand : public LogicalOperator {
* @param evaluator Expression evaluator for property value eval.
*/
void CreateEdge(VertexAccessor &from, VertexAccessor &to, Frame &frame,
SymbolTable &symbol_table, ExpressionEvaluator &evaluator);
const SymbolTable &symbol_table,
ExpressionEvaluator &evaluator);
};
};
@ -217,23 +219,24 @@ class CreateExpand : public LogicalOperator {
*/
class ScanAll : public LogicalOperator {
public:
ScanAll(NodeAtom *node_atom);
ScanAll(NodeAtom *node_atom, std::shared_ptr<LogicalOperator> input);
ScanAll(const NodeAtom *node_atom);
ScanAll(const NodeAtom *node_atom,
const std::shared_ptr<LogicalOperator> &input);
void Accept(LogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
NodeAtom *node_atom_ = nullptr;
std::shared_ptr<LogicalOperator> input_;
const NodeAtom *node_atom_ = nullptr;
const std::shared_ptr<LogicalOperator> input_;
class ScanAllCursor : public Cursor {
public:
ScanAllCursor(ScanAll &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
ScanAllCursor(const ScanAll &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
ScanAll &self_;
std::unique_ptr<Cursor> input_cursor_;
const ScanAll &self_;
const std::unique_ptr<Cursor> input_cursor_;
decltype(std::declval<GraphDbAccessor>().vertices()) vertices_;
decltype(vertices_.begin()) vertices_it_;
// if this is the first pull from this cursor
@ -281,36 +284,36 @@ class Expand : public LogicalOperator {
* present in the Frame and should just be checked for equality.
* @param edge_cycle Same like 'node_cycle', but for edges.
*/
Expand(NodeAtom *node_atom, EdgeAtom *edge_atom,
const std::shared_ptr<LogicalOperator> &input,
const Symbol &input_symbol, bool node_cycle, bool edge_cycle);
Expand(const NodeAtom *node_atom, const EdgeAtom *edge_atom,
const std::shared_ptr<LogicalOperator> &input, Symbol input_symbol,
bool node_cycle, bool edge_cycle);
void Accept(LogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
// info on what's getting expanded
NodeAtom *node_atom_;
EdgeAtom *edge_atom_;
const NodeAtom *node_atom_;
const EdgeAtom *edge_atom_;
// the input op and the symbol under which the op's result
// can be found in the frame
std::shared_ptr<LogicalOperator> input_;
const std::shared_ptr<LogicalOperator> input_;
const Symbol input_symbol_;
// if the given node and edge atom refer to symbols
// (query identifiers) that have already been expanded
// and should be just validated in the frame
bool node_cycle_;
bool edge_cycle_;
const bool node_cycle_;
const bool edge_cycle_;
class ExpandCursor : public Cursor {
public:
ExpandCursor(Expand &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
ExpandCursor(const Expand &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
Expand &self_;
std::unique_ptr<Cursor> input_cursor_;
const Expand &self_;
const std::unique_ptr<Cursor> input_cursor_;
// the iterable over edges and the current edge iterator are referenced via
// unique pointers because they can not be initialized in the constructor of
@ -320,7 +323,7 @@ class Expand : public LogicalOperator {
std::unique_ptr<OutEdgeT> out_edges_;
std::unique_ptr<OutEdgeIteratorT> out_edges_it_;
bool InitEdges(Frame &frame, SymbolTable &symbol_table);
bool InitEdges(Frame &frame, const SymbolTable &symbol_table);
/**
* For a newly expanded edge handles cycle checking and frame insertion.
@ -329,8 +332,8 @@ class Expand : public LogicalOperator {
* valid only when doing an edge-cycle and the new_edge does not match the
* old.
*/
bool HandleEdgeCycle(EdgeAccessor &new_edge, Frame &frame,
SymbolTable &symbol_table);
bool HandleEdgeCycle(const EdgeAccessor &new_edge, Frame &frame,
const SymbolTable &symbol_table);
/**
* Expands a node for the given newly expanded edge.
@ -339,8 +342,8 @@ class Expand : public LogicalOperator {
* expanded. Returns false only when doing a node-cycle and the
* new node does not qualify.
*/
bool PullNode(EdgeAccessor &new_edge, EdgeAtom::Direction direction,
Frame &frame, SymbolTable &symbol_table);
bool PullNode(const EdgeAccessor &new_edge, EdgeAtom::Direction direction,
Frame &frame, const SymbolTable &symbol_table);
/**
* For a newly expanded node handles cycle checking and frame insertion.
@ -349,8 +352,8 @@ class Expand : public LogicalOperator {
* valid only when doing a node-cycle and the new_node does not match the
* old.
*/
bool HandleNodeCycle(VertexAccessor new_node, Frame &frame,
SymbolTable &symbol_table);
bool HandleNodeCycle(const VertexAccessor new_node, Frame &frame,
const SymbolTable &symbol_table);
};
};
@ -367,29 +370,29 @@ class NodeFilter : public LogicalOperator {
* @param input_symbol @c Symbol where the node to be filtered is stored.
* @param node_atom @c NodeAtom with labels and properties to filter by.
*/
NodeFilter(std::shared_ptr<LogicalOperator> input, Symbol input_symbol,
NodeAtom *node_atom);
NodeFilter(const std::shared_ptr<LogicalOperator> &input, Symbol input_symbol,
const NodeAtom *node_atom);
void Accept(LogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
std::shared_ptr<LogicalOperator> input_;
const std::shared_ptr<LogicalOperator> input_;
const Symbol input_symbol_;
NodeAtom *node_atom_;
const NodeAtom *node_atom_;
class NodeFilterCursor : public Cursor {
public:
NodeFilterCursor(NodeFilter &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
NodeFilterCursor(const NodeFilter &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
NodeFilter &self_;
std::unique_ptr<Cursor> input_cursor_;
const NodeFilter &self_;
const std::unique_ptr<Cursor> input_cursor_;
/** Helper function for checking if the given vertex
* passes this filter. */
bool VertexPasses(const VertexAccessor &vertex, Frame &frame,
SymbolTable &symbol_table);
const SymbolTable &symbol_table);
};
};
@ -406,29 +409,29 @@ class EdgeFilter : public LogicalOperator {
* @param input_symbol @c Symbol where the edge to be filtered is stored.
* @param edge_atom @c EdgeAtom with edge types and properties to filter by.
*/
EdgeFilter(std::shared_ptr<LogicalOperator> input, Symbol input_symbol,
EdgeAtom *edge_atom);
EdgeFilter(const std::shared_ptr<LogicalOperator> &input, Symbol input_symbol,
const EdgeAtom *edge_atom);
void Accept(LogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
std::shared_ptr<LogicalOperator> input_;
const std::shared_ptr<LogicalOperator> input_;
const Symbol input_symbol_;
EdgeAtom *edge_atom_;
const EdgeAtom *edge_atom_;
class EdgeFilterCursor : public Cursor {
public:
EdgeFilterCursor(EdgeFilter &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
EdgeFilterCursor(const EdgeFilter &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
EdgeFilter &self_;
const EdgeFilter &self_;
std::unique_ptr<Cursor> input_cursor_;
/** Helper function for checking if the given edge satisfied
* the criteria of this edge filter. */
bool EdgePasses(const EdgeAccessor &edge, Frame &frame,
SymbolTable &symbol_table);
const SymbolTable &symbol_table);
};
};
@ -447,17 +450,17 @@ class Filter : public LogicalOperator {
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
std::shared_ptr<LogicalOperator> input_;
const std::shared_ptr<LogicalOperator> input_;
Expression *expression_;
class FilterCursor : public Cursor {
public:
FilterCursor(Filter &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
FilterCursor(const Filter &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
Filter &self_;
std::unique_ptr<Cursor> input_cursor_;
const Filter &self_;
const std::unique_ptr<Cursor> input_cursor_;
};
};
@ -474,25 +477,25 @@ class Filter : public LogicalOperator {
*/
class Produce : public LogicalOperator {
public:
Produce(std::shared_ptr<LogicalOperator> input,
std::vector<NamedExpression *> named_expressions);
Produce(const std::shared_ptr<LogicalOperator> &input,
const std::vector<NamedExpression *> named_expressions);
void Accept(LogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
const std::vector<NamedExpression *> &named_expressions();
private:
std::shared_ptr<LogicalOperator> input_;
std::vector<NamedExpression *> named_expressions_;
const std::shared_ptr<LogicalOperator> input_;
const std::vector<NamedExpression *> named_expressions_;
class ProduceCursor : public Cursor {
public:
ProduceCursor(Produce &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
ProduceCursor(const Produce &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
Produce &self_;
const Produce &self_;
// optional, see class documentation
std::unique_ptr<Cursor> input_cursor_;
const std::unique_ptr<Cursor> input_cursor_;
// control switch when creating only one node (nullptr input)
bool did_produce_{false};
};
@ -512,20 +515,20 @@ class Delete : public LogicalOperator {
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
std::shared_ptr<LogicalOperator> input_;
std::vector<Expression *> expressions_;
const std::shared_ptr<LogicalOperator> input_;
const std::vector<Expression *> expressions_;
// if the vertex should be detached before deletion
// if not detached, and has connections, an error is raised
// ignored when deleting edges
bool detach_;
const bool detach_;
class DeleteCursor : public Cursor {
public:
DeleteCursor(Delete &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
DeleteCursor(const Delete &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
Delete &self_;
const Delete &self_;
GraphDbAccessor &db_;
std::unique_ptr<Cursor> input_cursor_;
};
@ -539,23 +542,23 @@ class Delete : public LogicalOperator {
*/
class SetProperty : public LogicalOperator {
public:
SetProperty(const std::shared_ptr<LogicalOperator> input, PropertyLookup *lhs,
Expression *rhs);
SetProperty(const std::shared_ptr<LogicalOperator> &input,
PropertyLookup *lhs, Expression *rhs);
void Accept(LogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
std::shared_ptr<LogicalOperator> input_;
const std::shared_ptr<LogicalOperator> input_;
PropertyLookup *lhs_;
Expression *rhs_;
class SetPropertyCursor : public Cursor {
public:
SetPropertyCursor(SetProperty &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
SetPropertyCursor(const SetProperty &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
SetProperty &self_;
const SetProperty &self_;
std::unique_ptr<Cursor> input_cursor_;
};
};
@ -581,26 +584,26 @@ class SetProperties : public LogicalOperator {
*/
enum class Op { UPDATE, REPLACE };
SetProperties(const std::shared_ptr<LogicalOperator> input,
const Symbol input_symbol, Expression *rhs, Op op);
SetProperties(const std::shared_ptr<LogicalOperator> &input,
Symbol input_symbol, Expression *rhs, Op op);
void Accept(LogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
std::shared_ptr<LogicalOperator> input_;
const std::shared_ptr<LogicalOperator> input_;
const Symbol input_symbol_;
Expression *rhs_;
Op op_;
class SetPropertiesCursor : public Cursor {
public:
SetPropertiesCursor(SetProperties &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
SetPropertiesCursor(const SetProperties &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
SetProperties &self_;
const SetProperties &self_;
GraphDbAccessor &db_;
std::unique_ptr<Cursor> input_cursor_;
const std::unique_ptr<Cursor> input_cursor_;
/** Helper function that sets the given values on either
* a VertexRecord or an EdgeRecord.
@ -620,24 +623,23 @@ class SetProperties : public LogicalOperator {
*/
class SetLabels : public LogicalOperator {
public:
SetLabels(const std::shared_ptr<LogicalOperator> input,
const Symbol input_symbol,
SetLabels(const std::shared_ptr<LogicalOperator> &input, Symbol input_symbol,
const std::vector<GraphDbTypes::Label> &labels);
void Accept(LogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
std::shared_ptr<LogicalOperator> input_;
const std::shared_ptr<LogicalOperator> input_;
const Symbol input_symbol_;
std::vector<GraphDbTypes::Label> labels_;
const std::vector<GraphDbTypes::Label> labels_;
class SetLabelsCursor : public Cursor {
public:
SetLabelsCursor(SetLabels &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
SetLabelsCursor(const SetLabels &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
SetLabels &self_;
const SetLabels &self_;
std::unique_ptr<Cursor> input_cursor_;
};
};
@ -648,22 +650,22 @@ class SetLabels : public LogicalOperator {
*/
class RemoveProperty : public LogicalOperator {
public:
RemoveProperty(const std::shared_ptr<LogicalOperator> input,
RemoveProperty(const std::shared_ptr<LogicalOperator> &input,
PropertyLookup *lhs);
void Accept(LogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
std::shared_ptr<LogicalOperator> input_;
const std::shared_ptr<LogicalOperator> input_;
PropertyLookup *lhs_;
class RemovePropertyCursor : public Cursor {
public:
RemovePropertyCursor(RemoveProperty &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
RemovePropertyCursor(const RemoveProperty &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
RemoveProperty &self_;
const RemoveProperty &self_;
std::unique_ptr<Cursor> input_cursor_;
};
};
@ -676,24 +678,24 @@ class RemoveProperty : public LogicalOperator {
*/
class RemoveLabels : public LogicalOperator {
public:
RemoveLabels(const std::shared_ptr<LogicalOperator> input,
const Symbol input_symbol,
RemoveLabels(const std::shared_ptr<LogicalOperator> &input,
Symbol input_symbol,
const std::vector<GraphDbTypes::Label> &labels);
void Accept(LogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
std::shared_ptr<LogicalOperator> input_;
const std::shared_ptr<LogicalOperator> input_;
const Symbol input_symbol_;
std::vector<GraphDbTypes::Label> labels_;
const std::vector<GraphDbTypes::Label> labels_;
class RemoveLabelsCursor : public Cursor {
public:
RemoveLabelsCursor(RemoveLabels &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
RemoveLabelsCursor(const RemoveLabels &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
RemoveLabels &self_;
const RemoveLabels &self_;
std::unique_ptr<Cursor> input_cursor_;
};
};
@ -729,18 +731,18 @@ class ExpandUniquenessFilter : public LogicalOperator {
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
std::shared_ptr<LogicalOperator> input_;
const std::shared_ptr<LogicalOperator> input_;
Symbol expand_symbol_;
std::vector<Symbol> previous_symbols_;
const std::vector<Symbol> previous_symbols_;
class ExpandUniquenessFilterCursor : public Cursor {
public:
ExpandUniquenessFilterCursor(ExpandUniquenessFilter &self,
ExpandUniquenessFilterCursor(const ExpandUniquenessFilter &self,
GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
ExpandUniquenessFilter &self_;
const ExpandUniquenessFilter &self_;
std::unique_ptr<Cursor> input_cursor_;
};
};
@ -774,25 +776,25 @@ class ExpandUniquenessFilter : public LogicalOperator {
*/
class Accumulate : public LogicalOperator {
public:
Accumulate(std::shared_ptr<LogicalOperator> input,
Accumulate(const std::shared_ptr<LogicalOperator> &input,
const std::vector<Symbol> &symbols, bool advance_command = false);
void Accept(LogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
std::shared_ptr<LogicalOperator> input_;
const std::shared_ptr<LogicalOperator> input_;
const std::vector<Symbol> symbols_;
bool advance_command_{false};
const bool advance_command_;
class AccumulateCursor : public Cursor {
public:
AccumulateCursor(Accumulate &self, GraphDbAccessor &db);
bool Pull(Frame &frame, SymbolTable &symbol_table) override;
AccumulateCursor(const Accumulate &self, GraphDbAccessor &db);
bool Pull(Frame &frame, const SymbolTable &symbol_table) override;
private:
Accumulate &self_;
const Accumulate &self_;
GraphDbAccessor &db_;
std::unique_ptr<Cursor> input_cursor_;
const std::unique_ptr<Cursor> input_cursor_;
std::list<std::list<TypedValue>> cache_;
decltype(cache_.begin()) cache_it_ = cache_.begin();
bool pulled_all_input_{false};
@ -822,14 +824,14 @@ class Aggregate : public LogicalOperator {
Aggregate(const std::shared_ptr<LogicalOperator> &input,
const std::vector<Element> &aggregations,
std::vector<NamedExpression *> group_by);
const std::vector<NamedExpression *> group_by);
void Accept(LogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
private:
std::shared_ptr<LogicalOperator> input_;
std::vector<Element> aggregations_;
std::vector<NamedExpression *> group_by_;
const std::shared_ptr<LogicalOperator> input_;
const std::vector<Element> aggregations_;
const std::vector<NamedExpression *> group_by_;
};
} // namespace plan

View File

@ -42,8 +42,8 @@ class SymbolTable {
auto &operator[](const Tree &tree) { return table_[tree.uid()]; }
auto &at(const Tree &tree) { return table_.at(tree.uid()); }
const auto &at(const Tree &tree) const { return table_.at(tree.uid()); }
Symbol &at(const Tree &tree) { return table_.at(tree.uid()); }
const Symbol &at(const Tree &tree) const { return table_.at(tree.uid()); }
int max_position() const { return position_; }

View File

@ -1151,7 +1151,8 @@ TEST(Interpreter, NodeFilterSet) {
std::make_shared<NodeFilter>(expand.op_, scan_all.sym_, scan_all.node_);
// SET n.prop = n.prop + 1
auto set_prop = PROPERTY_LOOKUP("n", prop);
auto add = ADD(PROPERTY_LOOKUP("n", prop), LITERAL(1));
symbol_table[*set_prop->expression_] = scan_all.sym_;
auto add = ADD(set_prop, LITERAL(1));
auto set = std::make_shared<plan::SetProperty>(node_filter, set_prop, add);
EXPECT_EQ(2, PullAll(set, *dba, symbol_table));
dba->advance_command();