Add ScanAllByLabel operator.

Summary:
Replace NodeAtom with Symbol inside ScanAll. Move ScanAllCursor outside of
ScanAll class and make it generic with regards to vertices it produces.

Reviewers: mislav.bradac, florijan

Reviewed By: mislav.bradac, florijan

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D387
This commit is contained in:
Teon Banek
2017-05-19 15:37:28 +02:00
parent 839d63284b
commit d016472c3a
5 changed files with 135 additions and 54 deletions

View File

@@ -85,17 +85,35 @@ struct ScanAllTuple {
* Creates and returns a tuple of stuff for a scan-all starting
* from the node with the given name.
*
* Returns (node_atom, scan_all_logical_op, symbol).
* Returns ScanAllTuple(node_atom, scan_all_logical_op, symbol).
*/
ScanAllTuple MakeScanAll(AstTreeStorage &storage, SymbolTable &symbol_table,
const std::string &identifier,
std::shared_ptr<LogicalOperator> input = {nullptr},
GraphView graph_view = GraphView::OLD) {
auto node = NODE(identifier);
auto logical_op = std::make_shared<ScanAll>(node, input, graph_view);
auto symbol = symbol_table.CreateSymbol(identifier, true);
symbol_table[*node->identifier_] = symbol;
// return std::make_tuple(node, logical_op, symbol);
auto logical_op = std::make_shared<ScanAll>(input, symbol, graph_view);
return ScanAllTuple{node, logical_op, symbol};
}
/**
* Creates and returns a tuple of stuff for a scan-all starting
* from the node with the given name and label.
*
* Returns ScanAllTuple(node_atom, scan_all_logical_op, symbol).
*/
ScanAllTuple MakeScanAllByLabel(
AstTreeStorage &storage, SymbolTable &symbol_table,
const std::string &identifier, const GraphDbTypes::Label &label,
std::shared_ptr<LogicalOperator> input = {nullptr},
GraphView graph_view = GraphView::OLD) {
auto node = NODE(identifier);
auto symbol = symbol_table.CreateSymbol(identifier, true);
symbol_table[*node->identifier_] = symbol;
auto logical_op =
std::make_shared<ScanAllByLabel>(input, symbol, label, graph_view);
return ScanAllTuple{node, logical_op, symbol};
}

View File

@@ -44,11 +44,10 @@ TEST(QueryPlan, MatchReturn) {
return PullAll(produce, *dba, symbol_table);
};
// TODO uncomment once the functionality is implemented
// EXPECT_EQ(2, test_pull_count(GraphView::NEW));
EXPECT_EQ(2, test_pull_count(GraphView::NEW));
EXPECT_EQ(2, test_pull_count(GraphView::OLD));
dba->insert_vertex();
// EXPECT_EQ(3, test_pull_count(GraphView::NEW));
EXPECT_EQ(3, test_pull_count(GraphView::NEW));
EXPECT_EQ(2, test_pull_count(GraphView::OLD));
dba->advance_command();
EXPECT_EQ(3, test_pull_count(GraphView::OLD));
@@ -804,3 +803,31 @@ TEST(QueryPlan, Distinct) {
{3, "two", TypedValue::Null, 3, true, false, "TWO", TypedValue::Null},
{3, "two", TypedValue::Null, true, false, "TWO"}, false);
}
TEST(QueryPlan, ScanAllByLabel) {
Dbms dbms;
auto dba = dbms.active();
// Add a vertex with a label and one without.
auto label = dba->label("label");
auto labeled_vertex = dba->insert_vertex();
labeled_vertex.add_label(label);
dba->insert_vertex();
dba->advance_command();
EXPECT_EQ(2, CountIterable(dba->vertices()));
// MATCH (n :label)
AstTreeStorage storage;
SymbolTable symbol_table;
auto scan_all_by_label =
MakeScanAllByLabel(storage, symbol_table, "n", label);
// RETURN n
auto output = NEXPR("n", IDENT("n"));
auto produce = MakeProduce(scan_all_by_label.op_, output);
symbol_table[*output->expression_] = scan_all_by_label.sym_;
symbol_table[*output] = symbol_table.CreateSymbol("n", true);
auto result_stream = CollectProduce(produce, symbol_table, *dba);
auto results = result_stream.GetResults();
ASSERT_EQ(results.size(), 1);
auto result_row = results[0];
ASSERT_EQ(result_row.size(), 1);
EXPECT_EQ(result_row[0].Value<VertexAccessor>(), labeled_vertex);
}