Skip to content

Commit

Permalink
fix node property issues and remove has_property
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmurariu committed Dec 16, 2024
1 parent aee968a commit 3100d43
Show file tree
Hide file tree
Showing 31 changed files with 1,418 additions and 563 deletions.
1,422 changes: 1,341 additions & 81 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[workspace]
members = [
"raphtory",
# "raphtory-cypher",
# "raphtory-benchmark",
# "pometry-storage",
# "examples/rust",
# "examples/netflow",
# "examples/custom-gql-apis",
# "python",
# "js-raphtory",
"raphtory-cypher",
"raphtory-benchmark",
"pometry-storage",
"examples/rust",
"examples/netflow",
"examples/custom-gql-apis",
"python",
"js-raphtory",
"raphtory-graphql",
"raphtory-api",
]
Expand Down
9 changes: 4 additions & 5 deletions python/tests/test_graphdb/test_graphdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ def no_static_property_test(key, value):
== expected_names_no_static
)

expected_names_no_static_at_1 = sorted(["prop 4", "prop 1", "prop 3"])
expected_names_no_static_at_1 = ["prop 1", "prop 2", "prop 3", "prop 4"]
assert (
sorted(g.at(1).node(1).properties.temporal.keys())
== expected_names_no_static_at_1
Expand Down Expand Up @@ -945,9 +945,8 @@ def check_temporal_properties(g):
["prop 4", "prop 1", "prop 2", "prop 3"]
)

assert sorted(g.at(1).edge(1, 2).properties.temporal.keys()) == sorted(
["prop 4", "prop 1", "prop 3"]
)
assert sorted(g.at(1).edge(1, 2).properties.temporal.keys()) == ["prop 1", "prop 2", "prop 3", "prop 4"]

# find all edges that match properties
[e] = g.at(1).find_edges({"prop 1": 1, "prop 3": "hi"})
assert e == g.edge(1, 2)
Expand Down Expand Up @@ -2766,7 +2765,7 @@ def test_NaN_NaT_as_properties():
@with_disk_graph
def check(g):
assert g.node(103).properties.temporal.get("floats").items() == [(30, 2.4)]
assert g.node(101).properties.temporal.get("floats") == None
assert g.node(101).properties.temporal.get("floats") == []

check(g)

Expand Down
18 changes: 1 addition & 17 deletions raphtory-graphql/src/model/schema/node_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use dynamic_graphql::{ResolvedObject, ResolvedObjectFields};
use itertools::Itertools;
use raphtory::{
db::{
api::view::{
internal::{CoreGraphOps, OneHopFilter},
DynamicGraph,
},
api::view::{internal::CoreGraphOps, DynamicGraph},
graph::node::NodeView,
},
prelude::{GraphViewOps, NodeViewOps},
Expand Down Expand Up @@ -54,9 +51,6 @@ impl NodeSchema {

let schema: SchemaAggregate = filtered_nodes
.map(collect_node_schema)
.inspect(|schema| {
println!("{:?}", schema);
})
.reduce(merge_schemas)
.unwrap_or_else(|| FxHashMap::default());

Expand Down Expand Up @@ -150,18 +144,8 @@ mod test {
let node = g.node(1).unwrap();
node.add_constant_properties([("lol", Prop::str("smile"))])?;

println!("{:?}", g.latest_time());

// let n1 = g.node(1).unwrap();
// let n3 = g.node(3).unwrap();
// let n4 = g.node(4).unwrap();

check_schema(&g);

// let g: raphtory::db::api::view::MaterializedGraph = g.materialize()?;

// check_schema(&g.into_events().unwrap());

Ok(())
}

Expand Down
10 changes: 6 additions & 4 deletions raphtory/src/algorithms/bipartite/max_weight_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
use crate::{
core::{entities::nodes::node_ref::AsNodeRef, utils::iter::GenLockedIter},
db::{
api::{
storage::graph::edges::edge_storage_ops::EdgeStorageOps,
view::{DynamicGraph, IntoDynBoxed, IntoDynamic, StaticGraphViewOps},
},
api::{storage::graph::edges::edge_storage_ops::EdgeStorageOps, view::IntoDynBoxed},
graph::{edge::EdgeView, edges::Edges, node::NodeView},
},
prelude::{EdgeViewOps, GraphViewOps, Prop, PropUnwrap},
};

#[cfg(feature = "python")]
use crate::db::api::view::{DynamicGraph, IntoDynamic, StaticGraphViewOps};

use hashbrown::HashMap;
use raphtory_api::core::entities::{EID, VID};
use std::{
Expand Down Expand Up @@ -1389,6 +1390,7 @@ pub struct Matching<G> {
reverse_map: Arc<HashMap<VID, (VID, EID)>>,
}

#[cfg(feature = "python")]
impl<G: StaticGraphViewOps + IntoDynamic> Matching<G> {
pub(crate) fn into_dyn(self) -> Matching<DynamicGraph> {
Matching {
Expand Down
76 changes: 4 additions & 72 deletions raphtory/src/core/entities/graph/tgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::logical_to_physical::Mapping;
use crate::{
core::{
entities::{
edges::edge_store::{EdgeDataLike, EdgeStore},
edges::edge_store::EdgeStore,
graph::{
tgraph_storage::GraphStorage,
timer::{MaxCounter, MinCounter, TimeCounterTrait},
Expand All @@ -16,17 +16,13 @@ use crate::{
timeindex::{AsTime, TimeIndexEntry},
PairEntryMut,
},
utils::{errors::GraphError, iter::GenLockedIter},
utils::errors::GraphError,
Direction, Prop,
},
db::api::{
storage::graph::edges::edge_storage_ops::EdgeStorageOps,
view::{BoxedLIter, IntoDynBoxed, Layer},
},
db::api::{storage::graph::edges::edge_storage_ops::EdgeStorageOps, view::Layer},
};
use dashmap::DashSet;
use either::Either;
use itertools::Itertools;
use raphtory_api::core::{
entities::{edges::edge_ref::EdgeRef, GidRef},
input::input_node::InputNode,
Expand All @@ -35,7 +31,7 @@ use raphtory_api::core::{
use rustc_hash::FxHasher;
use serde::{Deserialize, Serialize};
use std::{
borrow::Borrow, collections::HashMap, fmt::Debug, hash::BuildHasherDefault, iter, ops::Deref,
borrow::Borrow, collections::HashMap, fmt::Debug, hash::BuildHasherDefault,
sync::atomic::AtomicUsize,
};

Expand Down Expand Up @@ -202,73 +198,9 @@ impl TemporalGraph {

#[inline]
pub(crate) fn graph_latest_time(&self) -> Option<i64> {
for (shard_id, nv) in self.storage.nodes.data.iter().enumerate() {
let ns = nv.read();

println!("{shard_id} {:?}", ns.t_props_log());

for n in ns.deref().deref() {
println!("{shard_id} Node: {:?}", n.timestamps());
}
}
Some(self.latest_time.get()).filter(|t| *t != i64::MIN)
}

pub(crate) fn core_temporal_edge_prop_ids(
&self,
e: EdgeRef,
layer_ids: LayerIds,
) -> BoxedLIter<usize> {
let entry = self.storage.edge_entry(e.pid());
let layer_ids = layer_ids.constrain_from_edge(e);
GenLockedIter::from(entry, |entry| {
let iter: BoxedLIter<usize> = match layer_ids.as_ref() {
LayerIds::None => Box::new(iter::empty()),
LayerIds::All => entry.temp_prop_ids(None),
LayerIds::One(id) => entry.temp_prop_ids(Some(*id)),
LayerIds::Multiple(ids) => Box::new(
ids.into_iter()
.map(|id| entry.temp_prop_ids(Some(id)))
.kmerge()
.dedup(),
),
};
iter
})
.into_dyn_boxed()
}

pub(crate) fn core_const_edge_prop_ids(
&self,
e: EdgeRef,
layer_ids: LayerIds,
) -> BoxedLIter<usize> {
let entry = self.storage.edge_entry(e.pid());
GenLockedIter::from(entry, |entry| {
let layer_ids = layer_ids.constrain_from_edge(e);
match layer_ids.as_ref() {
LayerIds::None => Box::new(iter::empty()),
LayerIds::All => entry
.layer_iter()
.map(|(_, data)| data.const_prop_ids())
.kmerge()
.dedup()
.into_dyn_boxed(),
LayerIds::One(id) => match entry.layer(*id) {
Some(l) => l.const_prop_ids().into_dyn_boxed(),
None => Box::new(iter::empty()),
},
LayerIds::Multiple(ids) => ids
.into_iter()
.flat_map(|id| entry.layer(id).map(|l| l.const_prop_ids()))
.kmerge()
.dedup()
.into_dyn_boxed(),
}
})
.into_dyn_boxed()
}

pub(crate) fn core_get_const_edge_prop(
&self,
e: EdgeRef,
Expand Down
48 changes: 22 additions & 26 deletions raphtory/src/core/entities/properties/tprop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ impl<'a> TPropOps<'a> for TPropCell<'a> {
fn at(self, ti: &TimeIndexEntry) -> Option<Prop> {
self.t_cell?.at(ti).and_then(|&id| self.log?.get(id?))
}

fn len(self) -> usize {
self.log.map(|log| log.len()).unwrap_or(0)
}
}

impl TProp {
Expand Down Expand Up @@ -425,28 +421,28 @@ impl<'a> TPropOps<'a> for &'a TProp {
}
}

fn len(self) -> usize {
match self {
TProp::Empty => 0,
TProp::Str(v) => v.len(),
TProp::U8(v) => v.len(),
TProp::U16(v) => v.len(),
TProp::I32(v) => v.len(),
TProp::I64(v) => v.len(),
TProp::U32(v) => v.len(),
TProp::U64(v) => v.len(),
TProp::F32(v) => v.len(),
TProp::F64(v) => v.len(),
TProp::Bool(v) => v.len(),
TProp::DTime(v) => v.len(),
TProp::NDTime(v) => v.len(),
TProp::Graph(v) => v.len(),
TProp::PersistentGraph(v) => v.len(),
TProp::Document(v) => v.len(),
TProp::List(v) => v.len(),
TProp::Map(v) => v.len(),
}
}
// fn len(self) -> usize {
// match self {
// TProp::Empty => 0,
// TProp::Str(v) => v.len(),
// TProp::U8(v) => v.len(),
// TProp::U16(v) => v.len(),
// TProp::I32(v) => v.len(),
// TProp::I64(v) => v.len(),
// TProp::U32(v) => v.len(),
// TProp::U64(v) => v.len(),
// TProp::F32(v) => v.len(),
// TProp::F64(v) => v.len(),
// TProp::Bool(v) => v.len(),
// TProp::DTime(v) => v.len(),
// TProp::NDTime(v) => v.len(),
// TProp::Graph(v) => v.len(),
// TProp::PersistentGraph(v) => v.len(),
// TProp::Document(v) => v.len(),
// TProp::List(v) => v.len(),
// TProp::Map(v) => v.len(),
// }
// }
}

#[cfg(test)]
Expand Down
27 changes: 2 additions & 25 deletions raphtory/src/core/storage/raw_edges.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
use super::{resolve, timeindex::TimeIndex};
use crate::{
core::entities::{
edges::edge_store::{EdgeDataLike, EdgeLayer, EdgeStore},
edges::edge_store::{EdgeLayer, EdgeStore},
LayerIds,
},
db::api::storage::graph::edges::edge_storage_ops::{EdgeStorageOps, MemEdge},
};
use itertools::Itertools;
use lock_api::ArcRwLockReadGuard;
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
use raphtory_api::{
core::{entities::EID, storage::timeindex::TimeIndexEntry},
iter::BoxedLIter,
};
use raphtory_api::core::{entities::EID, storage::timeindex::TimeIndexEntry};
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use std::{
Expand Down Expand Up @@ -281,25 +277,6 @@ impl<'a> EdgeRGuard<'a> {
self.guard.props_iter(self.offset)
}

pub(crate) fn temp_prop_ids(&self, layer_id: Option<usize>) -> BoxedLIter<usize> {
if let Some(layer_id) = layer_id {
Box::new(
self.guard
.props(self.offset, layer_id)
.into_iter()
.flat_map(|layer| layer.temporal_prop_ids()),
)
} else {
Box::new(
self.guard
.props_iter(self.offset)
.map(|(_, layer)| layer.temporal_prop_ids())
.kmerge()
.dedup(),
)
}
}

pub(crate) fn layer(&self, layer_id: usize) -> Option<impl Deref<Target = EdgeLayer> + '_> {
self.guard.props(self.offset, layer_id)
}
Expand Down
5 changes: 1 addition & 4 deletions raphtory/src/db/api/properties/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ pub trait ConstPropertiesOps: Send + Sync {
Box::new(self.const_prop_ids().map(|id| self.get_const_prop_name(id)))
}
fn const_prop_values(&self) -> BoxedLIter<Prop> {
Box::new(self.const_prop_ids().map(|k| {
self.get_const_prop(k)
.expect("ids that come from the internal iterator should exist")
}))
Box::new(self.const_prop_ids().filter_map(|k| self.get_const_prop(k)))
}
fn get_const_prop(&self, id: usize) -> Option<Prop>;
}
Expand Down
4 changes: 0 additions & 4 deletions raphtory/src/db/api/storage/graph/edges/edge_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ impl<'a, 'b: 'a> EdgeStorageOps<'a> for &'a EdgeStorageEntry<'b> {
self.as_ref().deletions(layer_id)
}

fn has_temporal_prop(self, layer_ids: &LayerIds, prop_id: usize) -> bool {
self.as_ref().has_temporal_prop(layer_ids, prop_id)
}

fn temporal_prop_layer(self, layer_id: usize, prop_id: usize) -> impl TPropOps<'a> + Sync + 'a {
self.as_ref().temporal_prop_layer(layer_id, prop_id)
}
Expand Down
4 changes: 0 additions & 4 deletions raphtory/src/db/api/storage/graph/edges/edge_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ impl<'a> EdgeStorageOps<'a> for EdgeStorageRef<'a> {
for_all!(self, edge => EdgeStorageOps::deletions(edge, layer_id))
}

fn has_temporal_prop(self, layer_ids: &LayerIds, prop_id: usize) -> bool {
for_all!(self, edge => EdgeStorageOps::has_temporal_prop(edge, layer_ids, prop_id))
}

fn temporal_prop_layer(self, layer_id: usize, prop_id: usize) -> impl TPropOps<'a> + Sync + 'a {
for_all_iter!(self, edge => edge.temporal_prop_layer(layer_id, prop_id))
}
Expand Down
5 changes: 0 additions & 5 deletions raphtory/src/db/api/storage/graph/edges/edge_storage_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,6 @@ pub trait EdgeStorageOps<'a>: Copy + Sized + Send + Sync + 'a {
fn additions(self, layer_id: usize) -> TimeIndexRef<'a>;
fn deletions(self, layer_id: usize) -> TimeIndexRef<'a>;

fn has_temporal_prop(self, layer_ids: &LayerIds, prop_id: usize) -> bool {
self.layer_ids_par_iter(layer_ids)
.any(move |id| !self.temporal_prop_layer(id, prop_id).is_empty())
}

fn temporal_prop_layer(self, layer_id: usize, prop_id: usize) -> impl TPropOps<'a> + Sync + 'a;

fn temporal_prop_iter(
Expand Down
Loading

0 comments on commit 3100d43

Please sign in to comment.