Skip to content

Commit

Permalink
add test for edge deletions
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmurariu committed Jul 4, 2024
1 parent 3444ef7 commit e211d72
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 17 deletions.
68 changes: 61 additions & 7 deletions raphtory/src/db/api/view/serialise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use crate::{
db::{
api::{
mutation::internal::{
DelegatePropertyAdditionOps, InternalAdditionOps, InternalPropertyAdditionOps,
DelegatePropertyAdditionOps, InternalAdditionOps, InternalDeletionOps,
InternalPropertyAdditionOps,
},
storage::nodes::node_storage_ops::NodeStorageOps,
},
Expand All @@ -27,7 +28,7 @@ use crate::{
self,
graph::{
properties_meta::{self, PropName},
AddEdge, AddNode, GraphConstProps, Node, PropPair, UpdateEdgeConstProps,
AddEdge, AddNode, DelEdge, GraphConstProps, Node, PropPair, UpdateEdgeConstProps,
},
lifespan, prop, Dict, NdTime,
},
Expand Down Expand Up @@ -205,13 +206,14 @@ impl<'graph, G: GraphViewOps<'graph>> StableEncoder for G {
ref mut const_edges_props,
ref mut nodes,
ref mut edges,
ref mut del_edges,
..
} = graph;

*nodes = self
.nodes()
.into_iter()
.map(|n| {
.map(|n: crate::db::graph::node::NodeView<G>| {
let gid = n.id();
let vid = n.node;
let node = self.core_node_entry(vid);
Expand Down Expand Up @@ -312,6 +314,15 @@ impl<'graph, G: GraphViewOps<'graph>> StableEncoder for G {
});
}
}

for time in ee.deletions() {
del_edges.push(DelEdge {
src,
dst,
time,
layer_id: Some(layer_id as u64),
});
}
}
}
}
Expand All @@ -320,8 +331,13 @@ impl<'graph, G: GraphViewOps<'graph>> StableEncoder for G {
}
}

impl<'graph, G: InternalAdditionOps + GraphViewOps<'graph> + DelegatePropertyAdditionOps>
StableDecode for G
impl<
'graph,
G: InternalAdditionOps
+ GraphViewOps<'graph>
+ DelegatePropertyAdditionOps
+ InternalDeletionOps,
> StableDecode for G
{
fn decode_from_bytes(buf: &[u8], graph: &Self) -> Result<(), GraphError> {
let g = serialise::Graph::decode(&buf[..]).expect("Failed to decode graph");
Expand Down Expand Up @@ -453,6 +469,23 @@ impl<'graph, G: InternalAdditionOps + GraphViewOps<'graph> + DelegatePropertyAdd
)?;
}

for DelEdge {
src,
dst,
time,
layer_id,
} in &g.del_edges
{
let src = VID(*src as usize);
let dst = VID(*dst as usize);
graph.internal_delete_edge(
TimeIndexEntry::from(*time),
src,
dst,
layer_id.map(|id| id as usize).unwrap(),
)?;
}

for UpdateEdgeConstProps {
src,
dst,
Expand Down Expand Up @@ -645,9 +678,13 @@ fn as_proto_prop(prop: &Prop) -> Result<serialise::Prop, GraphError> {

#[cfg(test)]
mod proto_test {
use chrono::{DateTime, Datelike, NaiveDate, NaiveDateTime, NaiveTime, Timelike};
use chrono::{DateTime, NaiveDateTime};

use crate::{core::DocumentInput, db::api::properties::internal::ConstPropertiesOps};
use crate::{
core::DocumentInput,
db::api::{mutation::DeletionOps, properties::internal::ConstPropertiesOps},
prelude::*,
};

use super::*;

Expand Down Expand Up @@ -706,6 +743,23 @@ mod proto_test {
assert_eq!(&g1, &g2);
}

#[test]
fn edge_no_props_delete() {
let temp_file = tempfile::NamedTempFile::new().unwrap();
let g1 = Graph::new().persistent_graph();
g1.add_edge(3, "Alice", "Bob", NO_PROPS, None).unwrap();
g1.delete_edge(19, "Alice", "Bob", None).unwrap();
g1.stable_serialise(&temp_file).unwrap();
let g2 = PersistentGraph::new();
PersistentGraph::decode(&temp_file, &g2).unwrap();
assert_eq!(&g1, &g2);

let edge = g2.edge("Alice", "Bob").expect("Failed to get edge");

let deletions = edge.deletions().iter().copied().collect::<Vec<_>>();
assert_eq!(deletions, vec![19]);
}

#[test]
fn edge_t_props() {
let temp_file = tempfile::NamedTempFile::new().unwrap();
Expand Down
28 changes: 18 additions & 10 deletions raphtory/src/graph.proto
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ message Lifespan {
}

message Graph {
repeated AddNode add_nodes = 1;
repeated AddEdge edges = 2;
repeated UpdateNodeConstProps constNodesProps = 3;
repeated UpdateEdgeConstProps constEdgesProps = 4;
GraphConstProps constProperties = 5;
GraphTempProps tempProperties = 6;
PropertiesMeta meta = 7;
repeated string layers = 8;
repeated string node_types = 9;
repeated Node nodes = 10;
GraphConstProps constProperties = 1;
GraphTempProps tempProperties = 2;
PropertiesMeta meta = 3;
repeated AddNode add_nodes = 4;
repeated AddEdge edges = 5;
repeated DelEdge del_edges = 6;
repeated UpdateNodeConstProps constNodesProps = 7;
repeated UpdateEdgeConstProps constEdgesProps = 8;
repeated string layers = 9;
repeated string node_types = 10;
repeated Node nodes = 11;

message Node{
uint64 gid = 1;
Expand Down Expand Up @@ -126,6 +127,13 @@ message Graph {
optional uint64 layer_id = 5;
}

message DelEdge{
uint64 src = 1;
uint64 dst = 2;
int64 time = 3;
optional uint64 layer_id = 4;
}

message AddNode {
uint64 id = 1;
optional PropPair properties = 3;
Expand Down

0 comments on commit e211d72

Please sign in to comment.