Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[main < T- degree] Implement node in out degree #369

Merged
merged 42 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
de3e42b
add initial structure
Aug 2, 2023
8a0816a
implement date.parse
Aug 3, 2023
bc74ca0
remove cpp date module
Aug 3, 2023
1f3de7e
rename python date module
Aug 3, 2023
d3bae6b
remove cpp date module
Aug 3, 2023
7653423
add date.format draft
Aug 3, 2023
92360ea
add e2e date.format tests
Aug 4, 2023
f322d38
implement label.exists and e2e tests for it
Aug 5, 2023
39bec4e
add missing endline
Aug 5, 2023
5b41866
edit wrong procedure call
Aug 5, 2023
eb487ab
edit by review comments
Aug 7, 2023
84464b4
edit typing error
Aug 8, 2023
5a863a3
format files with black
Aug 9, 2023
71c6435
Merge branch 'main' into T585-T586-MAGE-implement-date
antoniofilipovic Aug 10, 2023
995fe4d
Merge branch 'main' into T585-T586-MAGE-implement-date
imilinovic Aug 11, 2023
cdd5071
Merge branch 'main' into T585-T586-MAGE-implement-date
antoniofilipovic Aug 11, 2023
07ed16d
Merge branch 'main' into T510-MAGE-implement-label
ind1xa Aug 11, 2023
158919a
Merge pull request #304 from memgraph/T510-MAGE-implement-label
antepusic Aug 16, 2023
456a7ba
Merge branch 'main' into T585-T586-MAGE-implement-date
ind1xa Aug 16, 2023
e59093a
Merge pull request #291 from memgraph/T585-T586-MAGE-implement-date
antepusic Aug 17, 2023
c39f0cd
merge
mpintaric55334 Aug 23, 2023
2aca436
Merge branch 'main' of https://github.com/memgraph/mage
mpintaric55334 Aug 28, 2023
731774f
Pull
mpintaric55334 Aug 31, 2023
fa5f222
Merge branch 'main' of https://github.com/memgraph/mage
mpintaric55334 Aug 31, 2023
0cc8e82
Merge branch 'main' of https://github.com/memgraph/mage
mpintaric55334 Sep 1, 2023
7b334da
Merge branch 'main' of https://github.com/memgraph/mage
mpintaric55334 Sep 4, 2023
6174dbf
Merge branch 'main' of https://github.com/memgraph/mage
mpintaric55334 Sep 4, 2023
c4277cc
Merge branch 'main' of https://github.com/memgraph/mage
mpintaric55334 Sep 5, 2023
128a7b9
Merge branch 'main' of https://github.com/memgraph/mage
mpintaric55334 Sep 6, 2023
991c1c4
Merge branch 'main' of https://github.com/memgraph/mage
mpintaric55334 Sep 10, 2023
4cb41e3
Merge branch 'main' of https://github.com/memgraph/mage
mpintaric55334 Sep 12, 2023
c11a96a
Merge branch 'main' of https://github.com/memgraph/mage
mpintaric55334 Sep 15, 2023
453a2ef
Merge branch 'main' of https://github.com/memgraph/mage
mpintaric55334 Sep 25, 2023
4420226
Implement node in out degree
mpintaric55334 Sep 25, 2023
0b54b4e
Write tests
mpintaric55334 Oct 11, 2023
2027516
Format
mpintaric55334 Oct 11, 2023
76558a2
PR changes
mpintaric55334 Oct 22, 2023
b25d092
Naming fix
mpintaric55334 Oct 22, 2023
36d520b
Naming fix
mpintaric55334 Oct 22, 2023
a78b3e3
Merge branch 'main' into T-node-in-out-degree
mpintaric55334 Oct 23, 2023
a2fcdc4
Merge branch 'main' into T-node-in-out-degree
imilinovic Oct 23, 2023
6bd8bde
Merge branch 'main' into T-node-in-out-degree
mpintaric55334 Oct 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions cpp/node_module/algorithm/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,55 @@ void Node::RelationshipTypes(mgp_list *args, mgp_graph *memgraph_graph, mgp_resu
return;
}
}

void Node::DegreeIn(mgp_list *args, mgp_func_context *ctx, mgp_func_result *res, mgp_memory *memory) {
mgp::MemoryDispatcherGuard guard{memory};
const auto arguments = mgp::List(args);
auto result = mgp::Result(res);
try {
const auto node = arguments[0].ValueNode();
const auto type = arguments[1].ValueString();
if (type.size() == 0) {
result.SetValue((int64_t)node.InDegree());
antoniofilipovic marked this conversation as resolved.
Show resolved Hide resolved
return;
}
int64_t degree = 0;
for (const auto rel : node.InRelationships()) {
if (rel.Type() == type) {
degree += 1;
}
}
result.SetValue(degree);


} catch (const std::exception &e) {
result.SetErrorMessage(e.what());
return;
}
}

void Node::DegreeOut(mgp_list *args, mgp_func_context *ctx, mgp_func_result *res, mgp_memory *memory) {
mgp::MemoryDispatcherGuard guard{memory};
const auto arguments = mgp::List(args);
auto result = mgp::Result(res);
try {
const auto node = arguments[0].ValueNode();
const auto type = arguments[1].ValueString();
if (type.size() == 0) {
result.SetValue((int64_t)node.OutDegree());
return;
}
int64_t degree = 0;
for (const auto rel : node.OutRelationships()) {
if (rel.Type() == type) {
degree += 1;
}
}
result.SetValue(degree);


} catch (const std::exception &e) {
result.SetErrorMessage(e.what());
return;
}
}
14 changes: 14 additions & 0 deletions cpp/node_module/algorithm/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ constexpr std::string_view kRelationshipTypesArg1 = "node";
constexpr std::string_view kRelationshipTypesArg2 = "types";
constexpr std::string_view kResultRelationshipTypes = "relationship_types";

/* degree_in constants */
constexpr std::string_view kFunctionDegreeIn = "degree_in";
constexpr std::string_view kDegreeInArg1 = "node";
constexpr std::string_view kDegreeInArg2 = "type";

/* degree_out constants */
constexpr std::string_view kFunctionDegreeOut = "degree_out";
constexpr std::string_view kDegreeOutArg1 = "node";
constexpr std::string_view kDegreeOutArg2 = "type";

void RelationshipsExist(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_memory *memory);

bool RelationshipExist(const mgp::Node &node, std::string &rel_type);
Expand All @@ -35,4 +45,8 @@ void RelationshipExists(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *r

void RelationshipTypes(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_memory *memory);

void DegreeIn(mgp_list *args, mgp_func_context *ctx, mgp_func_result *res, mgp_memory *memory);

void DegreeOut(mgp_list *args, mgp_func_context *ctx, mgp_func_result *res, mgp_memory *memory);

} // namespace Node
14 changes: 13 additions & 1 deletion cpp/node_module/node_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

extern "C" int mgp_init_module(struct mgp_module *module, struct mgp_memory *memory) {
try {
mgp::MemoryDispatcherGuard guard{memory};;

mgp::MemoryDispatcherGuard guard{memory};

AddProcedure(Node::RelationshipsExist, std::string(Node::kProcedureRelationshipsExist).c_str(),
mgp::ProcedureType::Read,
{mgp::Parameter(std::string(Node::kArgumentNodesRelationshipsExist).c_str(), mgp::Type::Node),
Expand All @@ -25,6 +27,16 @@ extern "C" int mgp_init_module(struct mgp_module *module, struct mgp_memory *mem
mgp::Parameter(Node::kRelationshipTypesArg2, {mgp::Type::List, mgp::Type::String}, mgp::Value(mgp::List{}))},
{mgp::Return(Node::kResultRelationshipTypes, {mgp::Type::List, mgp::Type::String})}, module, memory);

mgp::AddFunction(Node::DegreeIn, Node::kFunctionDegreeIn,
{mgp::Parameter(Node::kDegreeInArg1, mgp::Type::Node),
mgp::Parameter(Node::kDegreeInArg2, mgp::Type::String, "")},
module, memory);

mgp::AddFunction(Node::DegreeOut, Node::kFunctionDegreeOut,
{mgp::Parameter(Node::kDegreeOutArg1, mgp::Type::Node),
mgp::Parameter(Node::kDegreeOutArg2, mgp::Type::String, "")},
module, memory);

} catch (const std::exception &e) {
return 1;
}
Expand Down
1 change: 1 addition & 0 deletions e2e/node_test/test_degree_in1/input.cyp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE (d:Dog),(h:Human),(d)-[l:LOVES]->(h),(d)-[o:OWNED_BY]->(h);
5 changes: 5 additions & 0 deletions e2e/node_test/test_degree_in1/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query: >
MATCH (h:Human) RETURN node.degree_in(h, "LOVES") AS result;

output:
- result: 1
1 change: 1 addition & 0 deletions e2e/node_test/test_degree_in2/input.cyp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE (d:Dog),(h:Human),(d)-[l:LOVES]->(h),(d)-[o:OWNED_BY]->(h);
5 changes: 5 additions & 0 deletions e2e/node_test/test_degree_in2/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query: >
MATCH (h:Human) RETURN node.degree_in(h) AS result;

output:
- result: 2
1 change: 1 addition & 0 deletions e2e/node_test/test_degree_in3/input.cyp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MERGE (d:Dog {name: "Rex"}) WITH d UNWIND range(0, 1000) AS id MERGE (h:Human {name: "Humie" + id}) MERGE (h)-[l:LOVES]->(d);
5 changes: 5 additions & 0 deletions e2e/node_test/test_degree_in3/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query: >
MATCH (d:Dog) RETURN node.degree_in(d) AS result;

output:
- result: 1001
1 change: 1 addition & 0 deletions e2e/node_test/test_degree_out1/input.cyp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE (d:Dog),(h:Human),(d)-[l:LOVES]->(h),(d)-[o:OWNED_BY]->(h);
5 changes: 5 additions & 0 deletions e2e/node_test/test_degree_out1/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query: >
MATCH (d:Dog) RETURN node.degree_out(d, "LOVES") AS result;

output:
- result: 1
1 change: 1 addition & 0 deletions e2e/node_test/test_degree_out2/input.cyp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE (d:Dog),(h:Human),(d)-[l:LOVES]->(h),(d)-[o:OWNED_BY]->(h);
5 changes: 5 additions & 0 deletions e2e/node_test/test_degree_out2/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query: >
MATCH (d:Dog) RETURN node.degree_out(d) AS result;

output:
- result: 2
1 change: 1 addition & 0 deletions e2e/node_test/test_degree_out3/input.cyp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MERGE (d:Dog {name: "Rex"}) WITH d UNWIND range(0, 1000) AS id MERGE (h:Human {name: "Humie" + id}) MERGE (d)-[l:LOVES]->(h);
5 changes: 5 additions & 0 deletions e2e/node_test/test_degree_out3/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query: >
MATCH (d:Dog) RETURN node.degree_out(d) AS result;

output:
- result: 1001
Loading