Add Cartesian operator stub

Reviewers: florijan, msantl

Reviewed By: msantl

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1199
This commit is contained in:
Teon Banek 2018-02-15 10:13:53 +01:00
parent 9eb01f363f
commit b8acefb1e3
2 changed files with 64 additions and 8 deletions

View File

@ -328,10 +328,10 @@ std::unique_ptr<Cursor> ScanAllByLabelPropertyRange::MakeCursor(
context.symbol_table_, db, graph_view_);
auto convert = [&evaluator](const auto &bound)
-> std::experimental::optional<utils::Bound<PropertyValue>> {
if (!bound) return std::experimental::nullopt;
return std::experimental::make_optional(utils::Bound<PropertyValue>(
bound.value().value()->Accept(evaluator), bound.value().type()));
};
if (!bound) return std::experimental::nullopt;
return std::experimental::make_optional(utils::Bound<PropertyValue>(
bound.value().value()->Accept(evaluator), bound.value().type()));
};
return db.Vertices(label_, property_, convert(lower_bound()),
convert(upper_bound()), graph_view_ == GraphView::NEW);
};
@ -1058,8 +1058,9 @@ class ExpandWeightedShortestPathCursor : public query::plan::Cursor {
self_.graph_view_);
// For the given (vertex, edge, vertex) tuple checks if they satisfy the
// "where" condition. if so, places them in the priority queue.
auto expand_pair = [this, &evaluator, &frame](
VertexAccessor from, EdgeAccessor edge, VertexAccessor vertex) {
auto expand_pair = [this, &evaluator, &frame](VertexAccessor from,
EdgeAccessor edge,
VertexAccessor vertex) {
SwitchAccessor(edge, self_.graph_view_);
SwitchAccessor(vertex, self_.graph_view_);
@ -3025,13 +3026,26 @@ class SynchronizeCursor : public Cursor {
}
}
};
}
} // namespace
std::unique_ptr<Cursor> Synchronize::MakeCursor(
database::GraphDbAccessor &db) const {
return std::make_unique<SynchronizeCursor>(*this, db);
}
bool Cartesian::Accept(HierarchicalLogicalOperatorVisitor &visitor) {
if (visitor.PreVisit(*this)) {
left_op_->Accept(visitor) && right_op_->Accept(visitor);
}
return visitor.PostVisit(*this);
}
std::unique_ptr<Cursor> Cartesian::MakeCursor(
database::GraphDbAccessor &db) const {
// TODO: Implement cursor.
return nullptr;
}
} // namespace query::plan
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Once);
@ -3068,3 +3082,4 @@ BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::CreateIndex);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Union);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::PullRemote);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Synchronize);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Cartesian);

View File

@ -101,6 +101,7 @@ class CreateIndex;
class Union;
class PullRemote;
class Synchronize;
class Cartesian;
using LogicalOperatorCompositeVisitor = ::utils::CompositeVisitor<
Once, CreateNode, CreateExpand, ScanAll, ScanAllByLabel,
@ -109,7 +110,8 @@ using LogicalOperatorCompositeVisitor = ::utils::CompositeVisitor<
SetProperties, SetLabels, RemoveProperty, RemoveLabels,
ExpandUniquenessFilter<VertexAccessor>,
ExpandUniquenessFilter<EdgeAccessor>, Accumulate, Aggregate, Skip, Limit,
OrderBy, Merge, Optional, Unwind, Distinct, Union, PullRemote, Synchronize>;
OrderBy, Merge, Optional, Unwind, Distinct, Union, PullRemote, Synchronize,
Cartesian>;
using LogicalOperatorLeafVisitor = ::utils::LeafVisitor<Once, CreateIndex>;
@ -2382,6 +2384,44 @@ class Synchronize : public LogicalOperator {
}
};
/** Operator for producing a Cartesian product from 2 input branches */
class Cartesian : public LogicalOperator {
public:
/** Construct the operator with left input branch and right input branch. */
Cartesian(const std::shared_ptr<LogicalOperator> &left_op,
const std::vector<Symbol> &left_symbols,
const std::shared_ptr<LogicalOperator> &right_op,
const std::vector<Symbol> &right_symbols)
: left_op_(left_op),
left_symbols_(left_symbols),
right_op_(right_op),
right_symbols_(right_symbols) {}
bool Accept(HierarchicalLogicalOperatorVisitor &visitor) override;
std::unique_ptr<Cursor> MakeCursor(
database::GraphDbAccessor &db) const override;
auto left_op() const { return left_op_; }
auto right_op() const { return right_op_; }
private:
std::shared_ptr<LogicalOperator> left_op_;
std::vector<Symbol> left_symbols_;
std::shared_ptr<LogicalOperator> right_op_;
std::vector<Symbol> right_symbols_;
Cartesian() {}
friend class boost::serialization::access;
template <class TArchive>
void serialize(TArchive &ar, const unsigned int) {
ar &left_op_;
ar &left_symbols_;
ar &right_op_;
ar &right_symbols_;
}
};
} // namespace plan
} // namespace query
@ -2418,3 +2458,4 @@ BOOST_CLASS_EXPORT_KEY(query::plan::CreateIndex);
BOOST_CLASS_EXPORT_KEY(query::plan::Union);
BOOST_CLASS_EXPORT_KEY(query::plan::PullRemote);
BOOST_CLASS_EXPORT_KEY(query::plan::Synchronize);
BOOST_CLASS_EXPORT_KEY(query::plan::Cartesian);