Query::Plan - switch from 'cycle' to 'existing' naming where appropriate
Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D312
This commit is contained in:
parent
e53e232e49
commit
774029cfcf
@ -83,12 +83,12 @@ void CreateNode::CreateNodeCursor::Create(Frame &frame,
|
||||
|
||||
CreateExpand::CreateExpand(const NodeAtom *node_atom, const EdgeAtom *edge_atom,
|
||||
const std::shared_ptr<LogicalOperator> &input,
|
||||
Symbol input_symbol, bool node_existing)
|
||||
Symbol input_symbol, bool existing_node)
|
||||
: node_atom_(node_atom),
|
||||
edge_atom_(edge_atom),
|
||||
input_(input),
|
||||
input_symbol_(input_symbol),
|
||||
node_existing_(node_existing) {}
|
||||
existing_node_(existing_node) {}
|
||||
|
||||
ACCEPT_WITH_INPUT(CreateExpand)
|
||||
|
||||
@ -139,7 +139,7 @@ void CreateExpand::CreateExpandCursor::Reset() { input_cursor_->Reset(); }
|
||||
VertexAccessor &CreateExpand::CreateExpandCursor::OtherVertex(
|
||||
Frame &frame, const SymbolTable &symbol_table,
|
||||
ExpressionEvaluator &evaluator) {
|
||||
if (self_.node_existing_) {
|
||||
if (self_.existing_node_) {
|
||||
TypedValue &dest_node_value =
|
||||
frame[symbol_table.at(*self_.node_atom_->identifier_)];
|
||||
return dest_node_value.Value<VertexAccessor>();
|
||||
@ -207,13 +207,13 @@ void ScanAll::ScanAllCursor::Reset() {
|
||||
|
||||
Expand::Expand(const NodeAtom *node_atom, const EdgeAtom *edge_atom,
|
||||
const std::shared_ptr<LogicalOperator> &input,
|
||||
Symbol input_symbol, bool node_cycle, bool edge_cycle)
|
||||
Symbol input_symbol, bool existing_node, bool existing_edge)
|
||||
: node_atom_(node_atom),
|
||||
edge_atom_(edge_atom),
|
||||
input_(input),
|
||||
input_symbol_(input_symbol),
|
||||
node_cycle_(node_cycle),
|
||||
edge_cycle_(edge_cycle) {}
|
||||
existing_node_(existing_node),
|
||||
existing_edge_(existing_edge) {}
|
||||
|
||||
ACCEPT_WITH_INPUT(Expand)
|
||||
|
||||
@ -229,7 +229,7 @@ bool Expand::ExpandCursor::Pull(Frame &frame, const SymbolTable &symbol_table) {
|
||||
// attempt to get a value from the incoming edges
|
||||
if (in_edges_ && *in_edges_it_ != in_edges_->end()) {
|
||||
EdgeAccessor edge = *(*in_edges_it_)++;
|
||||
if (HandleEdgeCycle(edge, frame, symbol_table) &&
|
||||
if (HandleExistingEdge(edge, frame, symbol_table) &&
|
||||
PullNode(edge, EdgeAtom::Direction::LEFT, frame, symbol_table))
|
||||
return true;
|
||||
else
|
||||
@ -245,7 +245,7 @@ bool Expand::ExpandCursor::Pull(Frame &frame, const SymbolTable &symbol_table) {
|
||||
if (self_.edge_atom_->direction_ == EdgeAtom::Direction::BOTH &&
|
||||
edge.is_cycle())
|
||||
continue;
|
||||
if (HandleEdgeCycle(edge, frame, symbol_table) &&
|
||||
if (HandleExistingEdge(edge, frame, symbol_table) &&
|
||||
PullNode(edge, EdgeAtom::Direction::RIGHT, frame, symbol_table))
|
||||
return true;
|
||||
else
|
||||
@ -302,15 +302,15 @@ bool Expand::ExpandCursor::InitEdges(Frame &frame,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Expand::ExpandCursor::HandleEdgeCycle(const EdgeAccessor &new_edge,
|
||||
Frame &frame,
|
||||
const SymbolTable &symbol_table) {
|
||||
if (self_.edge_cycle_) {
|
||||
bool Expand::ExpandCursor::HandleExistingEdge(const EdgeAccessor &new_edge,
|
||||
Frame &frame,
|
||||
const SymbolTable &symbol_table) {
|
||||
if (self_.existing_edge_) {
|
||||
TypedValue &old_edge_value =
|
||||
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
|
||||
// not matching existing, so put the new_edge into the frame and return true
|
||||
frame[symbol_table.at(*self_.edge_atom_->identifier_)] = new_edge;
|
||||
return true;
|
||||
}
|
||||
@ -321,23 +321,23 @@ bool Expand::ExpandCursor::PullNode(const EdgeAccessor &new_edge,
|
||||
const SymbolTable &symbol_table) {
|
||||
switch (direction) {
|
||||
case EdgeAtom::Direction::LEFT:
|
||||
return HandleNodeCycle(new_edge.from(), frame, symbol_table);
|
||||
return HandleExistingNode(new_edge.from(), frame, symbol_table);
|
||||
case EdgeAtom::Direction::RIGHT:
|
||||
return HandleNodeCycle(new_edge.to(), frame, symbol_table);
|
||||
return HandleExistingNode(new_edge.to(), frame, symbol_table);
|
||||
case EdgeAtom::Direction::BOTH:
|
||||
permanent_fail("Must indicate exact expansion direction here");
|
||||
}
|
||||
}
|
||||
|
||||
bool Expand::ExpandCursor::HandleNodeCycle(const VertexAccessor new_node,
|
||||
Frame &frame,
|
||||
const SymbolTable &symbol_table) {
|
||||
if (self_.node_cycle_) {
|
||||
bool Expand::ExpandCursor::HandleExistingNode(const VertexAccessor new_node,
|
||||
Frame &frame,
|
||||
const SymbolTable &symbol_table) {
|
||||
if (self_.existing_node_) {
|
||||
TypedValue &old_node_value =
|
||||
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
|
||||
// not matching existing, so put the new_edge into the frame and return true
|
||||
frame[symbol_table.at(*self_.node_atom_->identifier_)] = new_node;
|
||||
return true;
|
||||
}
|
||||
|
@ -187,12 +187,12 @@ class CreateExpand : public LogicalOperator {
|
||||
* For each successful @c Cursor::Pull, this operator will create an
|
||||
* expansion.
|
||||
* @param input_symbol @c Symbol for the node at the start of the edge.
|
||||
* @param node_existing @c bool indicating whether the @c node_atom refers to
|
||||
* @param existing_node @c bool indicating whether the @c node_atom refers to
|
||||
* an existing node. If @c false, the operator will also create the node.
|
||||
*/
|
||||
CreateExpand(const NodeAtom *node_atom, const EdgeAtom *edge_atom,
|
||||
const std::shared_ptr<LogicalOperator> &input,
|
||||
Symbol input_symbol, bool node_existing);
|
||||
Symbol input_symbol, bool existing_node);
|
||||
void Accept(LogicalOperatorVisitor &visitor) override;
|
||||
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
|
||||
|
||||
@ -208,7 +208,7 @@ class CreateExpand : public LogicalOperator {
|
||||
|
||||
// if the given node atom refers to an existing node
|
||||
// (either matched or created)
|
||||
const bool node_existing_;
|
||||
const bool existing_node_;
|
||||
|
||||
class CreateExpandCursor : public Cursor {
|
||||
public:
|
||||
@ -281,10 +281,11 @@ class ScanAll : public LogicalOperator {
|
||||
*
|
||||
* This class does not handle node/edge filtering based on
|
||||
* properties, labels and edge types. However, it does handle
|
||||
* cycle filtering.
|
||||
* filtering on existing node / edge.
|
||||
*
|
||||
* Cycle filtering means that for a pattern that references
|
||||
* the same node or edge in two places (for example `(n)-->(n)`),
|
||||
* Filtering on existing means that for a pattern that references
|
||||
* an already declared node or edge (for example in
|
||||
* MATCH (a) MATCH (a)--(b)),
|
||||
* only expansions that match defined equalities are succesfully
|
||||
* pulled.
|
||||
*/
|
||||
@ -299,7 +300,7 @@ class Expand : public LogicalOperator {
|
||||
/**
|
||||
* @brief Creates an expansion.
|
||||
*
|
||||
* Cycle-checking is controlled via booleans. A true value
|
||||
* Edge/Node existence is controlled via booleans. A true value
|
||||
* simply denotes that this expansion references an already
|
||||
* Pulled node/edge, and should only be checked for equalities
|
||||
* during expansion.
|
||||
@ -311,13 +312,13 @@ class Expand : public LogicalOperator {
|
||||
* @param input LogicalOperation that preceeds this one.
|
||||
* @param input_symbol Symbol that points to a VertexAccessor
|
||||
* in the Frame that expansion should emanate from.
|
||||
* @param node_cycle If or not the node to be expanded is already
|
||||
* @param existing_node If or not the node to be expanded is already
|
||||
* present in the Frame and should just be checked for equality.
|
||||
* @param edge_cycle Same like 'node_cycle', but for edges.
|
||||
* @param existing_edge Same like 'existing_node', but for edges.
|
||||
*/
|
||||
Expand(const NodeAtom *node_atom, const EdgeAtom *edge_atom,
|
||||
const std::shared_ptr<LogicalOperator> &input, Symbol input_symbol,
|
||||
bool node_cycle, bool edge_cycle);
|
||||
bool existing_node, bool existing_edge);
|
||||
void Accept(LogicalOperatorVisitor &visitor) override;
|
||||
std::unique_ptr<Cursor> MakeCursor(GraphDbAccessor &db) override;
|
||||
|
||||
@ -334,8 +335,8 @@ class Expand : public LogicalOperator {
|
||||
// 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
|
||||
const bool node_cycle_;
|
||||
const bool edge_cycle_;
|
||||
const bool existing_node_;
|
||||
const bool existing_edge_;
|
||||
|
||||
class ExpandCursor : public Cursor {
|
||||
public:
|
||||
@ -349,7 +350,7 @@ class Expand : public LogicalOperator {
|
||||
|
||||
// the iterable over edges and the current edge iterator are referenced via
|
||||
// unique pointers because they can not be initialized in the constructor of
|
||||
// this class. they are initialized once for each pull from the input
|
||||
// this class. They are initialized once for each pull from the input
|
||||
std::unique_ptr<InEdgeT> in_edges_;
|
||||
std::unique_ptr<InEdgeIteratorT> in_edges_it_;
|
||||
std::unique_ptr<OutEdgeT> out_edges_;
|
||||
@ -358,34 +359,36 @@ class Expand : public LogicalOperator {
|
||||
bool InitEdges(Frame &frame, const SymbolTable &symbol_table);
|
||||
|
||||
/**
|
||||
* For a newly expanded edge handles cycle checking and frame insertion.
|
||||
* For a newly expanded edge handles existence checking and frame insertion.
|
||||
*
|
||||
* @return If or not the given new_edge is a valid expansion. It is not
|
||||
* valid only when doing an edge-cycle and the new_edge does not match the
|
||||
* valid only when matching and existing edge and new_edge does not match
|
||||
* the
|
||||
* old.
|
||||
*/
|
||||
bool HandleEdgeCycle(const EdgeAccessor &new_edge, Frame &frame,
|
||||
const SymbolTable &symbol_table);
|
||||
bool HandleExistingEdge(const EdgeAccessor &new_edge, Frame &frame,
|
||||
const SymbolTable &symbol_table);
|
||||
|
||||
/**
|
||||
* Expands a node for the given newly expanded edge.
|
||||
*
|
||||
* @return True if after this call a new node has been successfully
|
||||
* expanded. Returns false only when doing a node-cycle and the
|
||||
* expanded. Returns false only when matching an existing node and the
|
||||
* new node does not qualify.
|
||||
*/
|
||||
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.
|
||||
* For a newly expanded node handles existence checking and frame insertion.
|
||||
*
|
||||
* @return If or not the given new_node is a valid expansion. It is not
|
||||
* valid only when doing a node-cycle and the new_node does not match the
|
||||
* valid only when matching and existing node and new_node does not match
|
||||
* the
|
||||
* old.
|
||||
*/
|
||||
bool HandleNodeCycle(const VertexAccessor new_node, Frame &frame,
|
||||
const SymbolTable &symbol_table);
|
||||
bool HandleExistingNode(const VertexAccessor new_node, Frame &frame,
|
||||
const SymbolTable &symbol_table);
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user