From ea202dc52a8a7803b484532e2c7f91a560fc75c3 Mon Sep 17 00:00:00 2001 From: florijan Date: Wed, 12 Apr 2017 09:01:44 +0200 Subject: [PATCH] Query::Plan::EdgeFilter bugfix Summary: Resolved the bug where edge filters with no edge-types dont accept any edge. Illustrated with the following queries: CREATE ()-[]->() MATCH ()-[]->() (produces 0 results, expected 1) Reviewers: mislav.bradac Reviewed By: mislav.bradac Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D265 --- src/query/frontend/logical/operator.cpp | 4 ++-- tests/unit/query_plan_match_filter_return.cpp | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/query/frontend/logical/operator.cpp b/src/query/frontend/logical/operator.cpp index 0c088b223..b1e3666b9 100644 --- a/src/query/frontend/logical/operator.cpp +++ b/src/query/frontend/logical/operator.cpp @@ -427,8 +427,8 @@ bool EdgeFilter::EdgeFilterCursor::EdgePasses(const EdgeAccessor &edge, // edge type filtering - logical OR const auto &types = self_.edge_atom_->edge_types_; GraphDbTypes::EdgeType type = edge.edge_type(); - if (!std::any_of(types.begin(), types.end(), - [type](auto t) { return t == type; })) + if (types.size() && std::none_of(types.begin(), types.end(), + [type](auto t) { return t == type; })) return false; ExpressionEvaluator expression_evaluator(frame, symbol_table); diff --git a/tests/unit/query_plan_match_filter_return.cpp b/tests/unit/query_plan_match_filter_return.cpp index 696307e8c..09ba73614 100644 --- a/tests/unit/query_plan_match_filter_return.cpp +++ b/tests/unit/query_plan_match_filter_return.cpp @@ -388,6 +388,26 @@ TEST(QueryPlan, EdgeFilter) { EXPECT_EQ(result.GetResults().size(), 1); } +TEST(QueryPlan, EdgeFilterEmpty) { + Dbms dbms; + auto dba = dbms.active(); + + auto v1 = dba->insert_vertex(); + auto v2 = dba->insert_vertex(); + dba->insert_edge(v1, v2, dba->edge_type("type")); + dba->advance_command(); + + AstTreeStorage storage; + SymbolTable symbol_table; + + auto n = MakeScanAll(storage, symbol_table, "n"); + auto r_m = MakeExpand(storage, symbol_table, n.op_, n.sym_, "r", + EdgeAtom::Direction::RIGHT, false, "m", false); + auto edge_filter = + std::make_shared(r_m.op_, r_m.edge_sym_, r_m.edge_); + EXPECT_EQ(1, PullAll(edge_filter, *dba, symbol_table)); +} + TEST(QueryPlan, EdgeFilterMultipleTypes) { Dbms dbms; auto dba = dbms.active();