diff --git a/python/tests/test_graphdb/test_graphdb.py b/python/tests/test_graphdb/test_graphdb.py index 071803ab9..41921c73b 100644 --- a/python/tests/test_graphdb/test_graphdb.py +++ b/python/tests/test_graphdb/test_graphdb.py @@ -457,10 +457,10 @@ def test_graph_properties(): assert g.properties["prop 5"] == {"x": 1, "y": "ok"} props = {"prop 4": 11, "prop 5": "world", "prop 6": False} - g.add_property(1, props) + g.add_properties(1, props) props = {"prop 6": True} - g.add_property(2, props) + g.add_properties(2, props) def history_test(key, value): if value is None: @@ -2054,7 +2054,7 @@ def check(g): assert mg.nodes.collect()[0].name == "1" props = {"prop 4": 11, "prop 5": "world", "prop 6": False} - mg.add_property(1, props) + mg.add_properties(1, props) props = {"prop 1": 1, "prop 2": "hi", "prop 3": True} mg.add_constant_properties(props) @@ -2755,10 +2755,10 @@ def check(g): def test_unique_temporal_properties(): g = Graph() - g.add_property(1, {"name": "tarzan"}) - g.add_property(2, {"name": "tarzan2"}) - g.add_property(3, {"name": "tarzan2"}) - g.add_property(2, {"salary": "1000"}) + g.add_properties(1, {"name": "tarzan"}) + g.add_properties(2, {"name": "tarzan2"}) + g.add_properties(3, {"name": "tarzan2"}) + g.add_properties(2, {"salary": "1000"}) g.add_constant_properties({"type": "character"}) g.add_edge(1, 1, 2, properties={"status": "open"}) g.add_edge(2, 1, 2, properties={"status": "open"}) @@ -3057,6 +3057,162 @@ def test_edge_layer_properties(): assert g.edge("A", "B").properties == {"greeting": "namaste"} +def test_add_node_properties_ordered_by_secondary_index(): + g = Graph() + g.add_node(1, "A", properties={"prop": 1}, secondary_index=3) + g.add_node(1, "A", properties={"prop": 2}, secondary_index=2) + g.add_node(1, "A", properties={"prop": 3}, secondary_index=1) + + assert g.node("A").properties.temporal.get("prop").items() == [(1, 3), (1, 2), (1, 1)] + + +def test_add_node_properties_overwritten_for_same_secondary_index(): + g = Graph() + g.add_node(1, "A", properties={"prop": 1}, secondary_index=1) + g.add_node(1, "A", properties={"prop": 2}, secondary_index=1) + g.add_node(1, "A", properties={"prop": 3}, secondary_index=1) + + assert g.node("A").properties.temporal.get("prop").items() == [(1, 3)] + + g = Graph() + g.add_node(1, "A", properties={"prop": 1}, secondary_index=1) + g.add_node(1, "A", properties={"prop": 2}, secondary_index=2) + g.add_node(1, "A", properties={"prop": 3}, secondary_index=2) + + assert g.node("A").properties.temporal.get("prop").items() == [(1, 1), (1, 3)] + + +def test_create_node_properties_ordered_by_secondary_index(): + g = Graph() + g.create_node(1, "A", properties={"prop": 1}, secondary_index=3) + g.add_node(1, "A", properties={"prop": 2}, secondary_index=2) + g.add_node(1, "A", properties={"prop": 3}, secondary_index=1) + + assert g.node("A").properties.temporal.get("prop").items() == [(1, 3), (1, 2), (1, 1)] + + +def test_create_node_properties_overwritten_for_same_secondary_index(): + g = Graph() + g.create_node(1, "A", properties={"prop": 1}, secondary_index=1) + g.add_node(1, "A", properties={"prop": 2}, secondary_index=1) + g.add_node(1, "A", properties={"prop": 3}, secondary_index=1) + + assert g.node("A").properties.temporal.get("prop").items() == [(1, 3)] + + g = Graph() + g.create_node(1, "A", properties={"prop": 1}, secondary_index=1) + g.add_node(1, "A", properties={"prop": 2}, secondary_index=2) + g.add_node(1, "A", properties={"prop": 3}, secondary_index=2) + + assert g.node("A").properties.temporal.get("prop").items() == [(1, 1), (1, 3)] + + +def test_add_edge_properties_ordered_by_secondary_index(): + g = Graph() + g.add_edge(1, "A", "B", properties={"prop": 1}, secondary_index=3) + g.add_edge(1, "A", "B", properties={"prop": 2}, secondary_index=2) + g.add_edge(1, "A", "B", properties={"prop": 3}, secondary_index=1) + + assert g.edge("A", "B").properties.temporal.get("prop").items() == [(1, 3), (1, 2), (1, 1)] + + +def test_add_edge_properties_overwritten_for_same_secondary_index(): + g = Graph() + g.add_edge(1, "A", "B", properties={"prop": 1}, secondary_index=1) + g.add_edge(1, "A", "B", properties={"prop": 2}, secondary_index=1) + g.add_edge(1, "A", "B", properties={"prop": 3}, secondary_index=1) + + assert g.edge("A", "B").properties.temporal.get("prop").items() == [(1, 3)] + + g = Graph() + g.add_edge(1, "A", "B", properties={"prop": 1}, secondary_index=1) + g.add_edge(1, "A", "B", properties={"prop": 2}, secondary_index=2) + g.add_edge(1, "A", "B", properties={"prop": 3}, secondary_index=2) + + assert g.edge("A", "B").properties.temporal.get("prop").items() == [(1, 1), (1, 3)] + + +def test_add_properties_properties_ordered_by_secondary_index(): + g = Graph() + g.add_properties(1, properties={"prop": 1}, secondary_index=3) + g.add_properties(1, properties={"prop": 2}, secondary_index=2) + g.add_properties(1, properties={"prop": 3}, secondary_index=1) + + assert g.properties.temporal.get("prop").items() == [(1, 3), (1, 2), (1, 1)] + + +def test_add_properties_properties_overwritten_for_same_secondary_index(): + g = Graph() + g.add_properties(1, properties={"prop": 1}, secondary_index=1) + g.add_properties(1, properties={"prop": 2}, secondary_index=1) + g.add_properties(1, properties={"prop": 3}, secondary_index=1) + + assert g.properties.temporal.get("prop").items() == [(1, 3)] + + g = Graph() + g.add_properties(1, properties={"prop": 1}, secondary_index=1) + g.add_properties(1, properties={"prop": 2}, secondary_index=2) + g.add_properties(1, properties={"prop": 3}, secondary_index=2) + + assert g.properties.temporal.get("prop").items() == [(1, 1), (1, 3)] + + +def test_node_add_updates_properties_ordered_by_secondary_index(): + g = Graph() + g.add_node(1, "A") + g.node("A").add_updates(1, properties={"prop": 1}, secondary_index=3) + g.node("A").add_updates(1, properties={"prop": 2}, secondary_index=2) + g.node("A").add_updates(1, properties={"prop": 3}, secondary_index=1) + + assert g.node("A").properties.temporal.get("prop").items() == [(1, 3), (1, 2), (1, 1)] + + +def test_node_add_updates_properties_overwritten_for_same_secondary_index(): + g = Graph() + g.add_node(1, "A") + g.node("A").add_updates(1, properties={"prop": 1}, secondary_index=1) + g.node("A").add_updates(1, properties={"prop": 2}, secondary_index=1) + g.node("A").add_updates(1, properties={"prop": 3}, secondary_index=1) + + assert g.node("A").properties.temporal.get("prop").items() == [(1, 3)] + + g = Graph() + g.add_node(1, "A") + g.node("A").add_updates(1, properties={"prop": 1}, secondary_index=1) + g.node("A").add_updates(1, properties={"prop": 2}, secondary_index=2) + g.node("A").add_updates(1, properties={"prop": 3}, secondary_index=2) + + assert g.node("A").properties.temporal.get("prop").items() == [(1, 1), (1, 3)] + + +def test_edge_add_updates_properties_ordered_by_secondary_index(): + g = Graph() + g.add_edge(1, "A", "B") + g.edge("A", "B").add_updates(1, properties={"prop": 1}, secondary_index=3) + g.edge("A", "B").add_updates(1, properties={"prop": 2}, secondary_index=2) + g.edge("A", "B").add_updates(1, properties={"prop": 3}, secondary_index=1) + + assert g.edge("A", "B").properties.temporal.get("prop").items() == [(1, 3), (1, 2), (1, 1)] + + +def test_edge_add_updates_properties_overwritten_for_same_secondary_index(): + g = Graph() + g.add_edge(1, "A", "B") + g.edge("A", "B").add_updates(1, properties={"prop": 1}, secondary_index=1) + g.edge("A", "B").add_updates(1, properties={"prop": 2}, secondary_index=1) + g.edge("A", "B").add_updates(1, properties={"prop": 3}, secondary_index=1) + + assert g.edge("A", "B").properties.temporal.get("prop").items() == [(1, 3)] + + g = Graph() + g.add_edge(1, "A", "B") + g.edge("A", "B").add_updates(1, properties={"prop": 1}, secondary_index=1) + g.edge("A", "B").add_updates(1, properties={"prop": 2}, secondary_index=2) + g.edge("A", "B").add_updates(1, properties={"prop": 3}, secondary_index=2) + + assert g.edge("A", "B").properties.temporal.get("prop").items() == [(1, 1), (1, 3)] + + @fixture def datadir(tmpdir, request): filename = request.module.__file__ diff --git a/raphtory/src/core/entities/properties/tcell.rs b/raphtory/src/core/entities/properties/tcell.rs index bee6200d0..1945e6ce9 100644 --- a/raphtory/src/core/entities/properties/tcell.rs +++ b/raphtory/src/core/entities/properties/tcell.rs @@ -185,7 +185,10 @@ mod tcell_tests { let mut tcell = TCell::new(TimeIndexEntry::start(1), "Pometry"); tcell.set(TimeIndexEntry::start(1), "Pometry Inc."); - assert_eq!(tcell.iter_t().collect::>(), vec![(1, &"Pometry")]); + assert_eq!( + tcell.iter_t().collect::>(), + vec![(1, &"Pometry Inc.")] + ); } #[test] diff --git a/raphtory/src/core/entities/properties/tprop.rs b/raphtory/src/core/entities/properties/tprop.rs index 5e732027d..39b993f7b 100644 --- a/raphtory/src/core/entities/properties/tprop.rs +++ b/raphtory/src/core/entities/properties/tprop.rs @@ -430,7 +430,7 @@ mod tprop_tests { assert_eq!( tprop.iter_t().collect::>(), - vec![(1, "Pometry".into())] + vec![(1, "Pometry Inc.".into())] ); } diff --git a/raphtory/src/db/api/view/graph.rs b/raphtory/src/db/api/view/graph.rs index 48c867f41..377ab5d40 100644 --- a/raphtory/src/db/api/view/graph.rs +++ b/raphtory/src/db/api/view/graph.rs @@ -817,10 +817,6 @@ mod test_exploded_edges { #[test] fn test_add_properties_properties_ordered_by_secondary_index() { let graph: Graph = Graph::new(); - graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap(); - graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap(); - graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap(); - graph.add_properties((0, 3), [("prop", "1")]).unwrap(); graph.add_properties((0, 2), [("prop", "2")]).unwrap(); graph.add_properties((0, 1), [("prop", "3")]).unwrap(); @@ -843,10 +839,6 @@ mod test_exploded_edges { #[test] fn test_add_properties_properties_overwritten_for_same_secondary_index() { let graph: Graph = Graph::new(); - graph.add_edge((0, 1), 0, 1, NO_PROPS, None).unwrap(); - graph.add_edge((0, 1), 0, 1, NO_PROPS, None).unwrap(); - graph.add_edge((0, 1), 0, 1, NO_PROPS, None).unwrap(); - graph.add_properties((0, 1), [("prop", "1")]).unwrap(); graph.add_properties((0, 1), [("prop", "2")]).unwrap(); graph.add_properties((0, 1), [("prop", "3")]).unwrap(); @@ -887,8 +879,6 @@ mod test_exploded_edges { fn test_node_add_updates_properties_ordered_by_secondary_index() { let graph: Graph = Graph::new(); graph.add_node(0, 0, NO_PROPS, None).unwrap(); - graph.add_node(0, 0, NO_PROPS, None).unwrap(); - graph.add_node(0, 0, NO_PROPS, None).unwrap(); graph .node(0) @@ -1008,8 +998,6 @@ mod test_exploded_edges { fn test_edge_add_updates_properties_ordered_by_secondary_index() { let graph: Graph = Graph::new(); graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap(); - graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap(); - graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap(); graph .edge(0, 1) @@ -1050,8 +1038,6 @@ mod test_exploded_edges { fn test_edge_add_updates_properties_overwritten_for_same_secondary_index() { let graph: Graph = Graph::new(); graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap(); - graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap(); - graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap(); graph .edge(0, 1) diff --git a/raphtory/src/python/graph/graph.rs b/raphtory/src/python/graph/graph.rs index 9f0de6f68..defa39cd6 100644 --- a/raphtory/src/python/graph/graph.rs +++ b/raphtory/src/python/graph/graph.rs @@ -258,7 +258,7 @@ impl PyGraph { /// Raises: /// GraphError: If the operation fails. #[pyo3(signature = (timestamp, properties, secondary_index = None))] - pub fn add_property( + pub fn add_properties( &self, timestamp: PyTime, properties: HashMap,