-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from memgraph/T510-MAGE-implement-label
[main < T510] Implement label.exists
- Loading branch information
Showing
11 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
set(label_module_src | ||
label_module.cpp | ||
algorithm/label.cpp) | ||
|
||
add_query_module(label 1 "${label_module_src}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "label.hpp" | ||
|
||
void Label::Exists(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_memory *memory) { | ||
mgp::memory = memory; | ||
const auto arguments = mgp::List(args); | ||
const auto record_factory = mgp::RecordFactory(result); | ||
try { | ||
bool exists = false; | ||
|
||
const auto label = arguments[1].ValueString(); | ||
if (arguments[0].IsNode()) { | ||
const auto node = arguments[0].ValueNode(); | ||
exists = node.HasLabel(label); | ||
} | ||
|
||
auto record = record_factory.NewRecord(); | ||
record.Insert(std::string(kResultExists).c_str(), std::move(exists)); | ||
|
||
} catch (const std::exception &e) { | ||
record_factory.SetErrorMessage(e.what()); | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include <mgp.hpp> | ||
|
||
namespace Label { | ||
|
||
/* exists constants */ | ||
constexpr std::string_view kReturnExists = "exists"; | ||
constexpr std::string_view kProcedureExists = "exists"; | ||
constexpr std::string_view kArgumentsNode = "node"; | ||
constexpr std::string_view kArgumentsLabel = "label"; | ||
constexpr std::string_view kResultExists = "exists"; | ||
|
||
void Exists(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_memory *memory); | ||
|
||
} // namespace Label |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <mgp.hpp> | ||
|
||
#include "algorithm/label.hpp" | ||
|
||
extern "C" int mgp_init_module(struct mgp_module *module, struct mgp_memory *memory) { | ||
try { | ||
mgp::memory = memory; | ||
AddProcedure(Label::Exists, Label::kProcedureExists, mgp::ProcedureType::Read, | ||
{mgp::Parameter(Label::kArgumentsNode, mgp::Type::Any), | ||
mgp::Parameter(Label::kArgumentsLabel, mgp::Type::String)}, | ||
{mgp::Return(Label::kReturnExists, mgp::Type::Bool)}, module, memory); | ||
|
||
} catch (const std::exception &e) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
extern "C" int mgp_shutdown_module() { return 0; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE (s1:Student {name: 'Ana'}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
query: > | ||
MATCH (s1:Student {name: 'Ana'}) | ||
CALL label.exists(s1, "Teacher") YIELD exists | ||
RETURN exists | ||
output: | ||
- exists: False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
MERGE (s1:Student {name: 'Ana'}) MERGE (s2:Student {name: 'Marija'}) CREATE (s1)-[k:KNOWS]->(s2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
query: > | ||
MATCH (:Student)-[k:KNOWS]->(:Student) | ||
CALL label.exists(k, "Knows") YIELD exists | ||
RETURN exists | ||
output: | ||
- exists: False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE (s1:Student {name: 'Ana'}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
query: > | ||
MATCH (s1:Student {name: 'Ana'}) | ||
CALL label.exists(s1, "Student") YIELD exists | ||
RETURN exists | ||
output: | ||
- exists: True |