From 60afe1d1ce8a74434fb207a5f465d84f1806b19a Mon Sep 17 00:00:00 2001 From: Shivam Kapoor <4599890+iamsmkr@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:26:59 +0000 Subject: [PATCH] fix issue with edge repr multiple layer --- python/tests/test_graphdb/test_graphdb.py | 10 ++++++++++ raphtory/src/core/storage/raw_edges.rs | 5 ++++- raphtory/src/db/api/view/graph.rs | 13 +++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/python/tests/test_graphdb/test_graphdb.py b/python/tests/test_graphdb/test_graphdb.py index bed24790c..071803ab9 100644 --- a/python/tests/test_graphdb/test_graphdb.py +++ b/python/tests/test_graphdb/test_graphdb.py @@ -3047,6 +3047,16 @@ def test_create_node_graph_with_deletion(): assert "Node already exists" in str(excinfo.value) +def test_edge_layer_properties(): + g = Graph() + g.add_edge(1, "A", "B", properties={"greeting": "howdy"}, layer="layer 1") + g.add_edge(2, "A", "B", properties={"greeting": "hello"}, layer="layer 2") + g.add_edge(3, "A", "B", properties={"greeting": "ola"}, layer="layer 2") + g.add_edge(3, "A", "B", properties={"greeting": "namaste"}, layer="layer 3") + + assert g.edge("A", "B").properties == {"greeting": "namaste"} + + @fixture def datadir(tmpdir, request): filename = request.module.__file__ diff --git a/raphtory/src/core/storage/raw_edges.rs b/raphtory/src/core/storage/raw_edges.rs index 84dbbc7c8..19a505504 100644 --- a/raphtory/src/core/storage/raw_edges.rs +++ b/raphtory/src/core/storage/raw_edges.rs @@ -18,6 +18,7 @@ use std::{ Arc, }, }; +use itertools::Itertools; #[derive(Debug, Serialize, Deserialize, PartialEq)] pub struct EdgeShard { @@ -292,7 +293,9 @@ impl<'a> EdgeRGuard<'a> { Box::new( self.guard .props_iter(self.offset) - .flat_map(|(_, layer)| layer.temporal_prop_ids()), + .map(|(_, layer)| layer.temporal_prop_ids()) + .kmerge() + .dedup(), ) } } diff --git a/raphtory/src/db/api/view/graph.rs b/raphtory/src/db/api/view/graph.rs index 65dbc2d75..ac79232f4 100644 --- a/raphtory/src/db/api/view/graph.rs +++ b/raphtory/src/db/api/view/graph.rs @@ -780,4 +780,17 @@ mod test_materialize { g.add_edge(0, 1, 2, props_0.clone(), None).unwrap(); assert!(g.add_edge(1, 1, 2, props_1.clone(), None).is_err()); } + + #[test] + fn test_my_graph() { + let g = Graph::new(); + g.add_edge(1, "A", "B", [("greeting", "howdy")], Some("layer 1")).unwrap(); + g.add_edge(2, "A", "B", [("greeting", "ola")], Some("layer 2")).unwrap(); + g.add_edge(2, "A", "B", [("greeting", "hello")], Some("layer 2")).unwrap(); + g.add_edge(3, "A", "B", [("greeting", "namaste")], Some("layer 3")).unwrap(); + + let edge_ab = g.edge("A", "B").unwrap(); + let props = edge_ab.properties().iter().map(|(k, v)| (k.to_string(), v.to_string())).collect::>(); + assert_eq!(props, vec![("greeting".to_string(), "namaste".to_string())]); + } }