From d67043a8161d74962de1e621ef2fa123aa07ae4a Mon Sep 17 00:00:00 2001 From: Fabian Murariu Date: Mon, 22 Jul 2024 14:08:57 +0100 Subject: [PATCH] fix graphql --- js-raphtory/src/graph/node.rs | 2 +- pometry-storage-private | 2 +- raphtory-api/src/core/entities/mod.rs | 2 +- raphtory-benchmark/benches/common/mod.rs | 9 +++- raphtory-benchmark/src/main.rs | 4 +- raphtory-graphql/src/model/graph/nodes.rs | 2 +- .../src/model/schema/node_schema.rs | 2 +- raphtory/src/db/graph/views/window_graph.rs | 2 +- raphtory/src/disk_graph/graph_impl/interop.rs | 2 +- raphtory/src/disk_graph/graph_impl/mod.rs | 50 +------------------ raphtory/src/disk_graph/mod.rs | 2 +- .../src/disk_graph/storage_interface/node.rs | 13 +++-- raphtory/src/lib.rs | 1 + 13 files changed, 25 insertions(+), 68 deletions(-) diff --git a/js-raphtory/src/graph/node.rs b/js-raphtory/src/graph/node.rs index 3c4cf70dd6..8d4e2b808c 100644 --- a/js-raphtory/src/graph/node.rs +++ b/js-raphtory/src/graph/node.rs @@ -26,7 +26,7 @@ impl From> for Node { impl Node { #[wasm_bindgen(js_name = id)] pub fn id(&self) -> u64 { - self.0.id() + self.0.id().as_u64().expect("only u64 supported in js") } #[wasm_bindgen(js_name = name)] diff --git a/pometry-storage-private b/pometry-storage-private index e1b4ddbc7b..c33dd4cf9f 160000 --- a/pometry-storage-private +++ b/pometry-storage-private @@ -1 +1 @@ -Subproject commit e1b4ddbc7b3779d8233f8e4a4a39e1a2265e651d +Subproject commit c33dd4cf9fbe843338c8bda1abf0fda6ae2c4bca diff --git a/raphtory-api/src/core/entities/mod.rs b/raphtory-api/src/core/entities/mod.rs index a31da26bfd..3fd4d9bb18 100644 --- a/raphtory-api/src/core/entities/mod.rs +++ b/raphtory-api/src/core/entities/mod.rs @@ -153,7 +153,7 @@ impl<'source> FromPyObject<'source> for GID { .map(GID::I64) .or_else(|_| id.extract::().map(GID::U64)) }) - .map_err(|err| { + .map_err(|_| { let msg = "IDs need to be strings or an unsigned integers"; PyTypeError::new_err(msg) }) diff --git a/raphtory-benchmark/benches/common/mod.rs b/raphtory-benchmark/benches/common/mod.rs index 0c98d4045b..5b03482f38 100644 --- a/raphtory-benchmark/benches/common/mod.rs +++ b/raphtory-benchmark/benches/common/mod.rs @@ -275,7 +275,7 @@ pub fn run_analysis_benchmarks( let edges: HashSet<(u64, u64)> = graph .edges() .into_iter() - .map(|e| (e.src().id(), e.dst().id())) + .filter_map(|e| e.src().id().as_u64().zip(e.dst().id().as_u64())) .collect(); let edges_t = graph @@ -285,7 +285,12 @@ pub fn run_analysis_benchmarks( .map(|e| (e.src().id(), e.dst().id(), e.time().expect("need time"))) .collect::>(); - let nodes: HashSet = graph.nodes().id().into_iter().collect(); + let nodes: HashSet = graph + .nodes() + .id() + .into_iter() + .filter_map(|n| n.as_u64()) + .collect(); bench(group, "num_edges", parameter, |b: &mut Bencher| { b.iter(|| graph.count_edges()) diff --git a/raphtory-benchmark/src/main.rs b/raphtory-benchmark/src/main.rs index df489da776..c90abab41f 100644 --- a/raphtory-benchmark/src/main.rs +++ b/raphtory-benchmark/src/main.rs @@ -190,8 +190,8 @@ fn main() { // Out neighbours of all nodes with time now = Instant::now(); - let _out_neighbours = g - .nodes() + let nodes = &g.nodes(); + let _out_neighbours = nodes .iter() .map(|v| v.out_neighbours()) .collect::>(); diff --git a/raphtory-graphql/src/model/graph/nodes.rs b/raphtory-graphql/src/model/graph/nodes.rs index ee7e8c51b5..255b063eb3 100644 --- a/raphtory-graphql/src/model/graph/nodes.rs +++ b/raphtory-graphql/src/model/graph/nodes.rs @@ -22,7 +22,7 @@ impl GqlNodes { } fn iter(&self) -> Box + '_> { - let iter = self.nn.iter().map(Node::from); + let iter = self.nn.iter_owned().map(Node::from); Box::new(iter) } } diff --git a/raphtory-graphql/src/model/schema/node_schema.rs b/raphtory-graphql/src/model/schema/node_schema.rs index 37171576a2..88693bbea9 100644 --- a/raphtory-graphql/src/model/schema/node_schema.rs +++ b/raphtory-graphql/src/model/schema/node_schema.rs @@ -35,7 +35,7 @@ impl NodeSchema { None => false, }; - let filtered_nodes = self.graph.nodes().iter().filter(filter_type); + let filtered_nodes = self.graph.nodes().iter_owned().filter(filter_type); let schema: SchemaAggregate = filtered_nodes .map(collect_node_schema) diff --git a/raphtory/src/db/graph/views/window_graph.rs b/raphtory/src/db/graph/views/window_graph.rs index 3bc3f9cb0b..2b863cbf45 100644 --- a/raphtory/src/db/graph/views/window_graph.rs +++ b/raphtory/src/db/graph/views/window_graph.rs @@ -34,7 +34,7 @@ //! graph.add_edge(2, 2, 3, NO_PROPS, None).unwrap(); //! //! let wg = graph.window(0, 1); -//! assert_eq!(wg.edge(1, 2).unwrap().src().id(), 1); +//! assert_eq!(wg.edge(1, 2).unwrap().src().id(), GID::U64(1)); //! ``` use crate::{ diff --git a/raphtory/src/disk_graph/graph_impl/interop.rs b/raphtory/src/disk_graph/graph_impl/interop.rs index 0b8814d556..86be7390a1 100644 --- a/raphtory/src/disk_graph/graph_impl/interop.rs +++ b/raphtory/src/disk_graph/graph_impl/interop.rs @@ -23,7 +23,7 @@ use raphtory_api::core::{ }; impl GraphLike for Graph { - fn external_ids(&self) -> Vec { + fn external_ids(&self) -> Vec { self.nodes().id().collect() } diff --git a/raphtory/src/disk_graph/graph_impl/mod.rs b/raphtory/src/disk_graph/graph_impl/mod.rs index 12fcbb082b..f0f5f5f246 100644 --- a/raphtory/src/disk_graph/graph_impl/mod.rs +++ b/raphtory/src/disk_graph/graph_impl/mod.rs @@ -429,18 +429,15 @@ impl DiskGraphStorage { mod test { use super::{DiskGraphStorage, ParquetLayerCols}; use crate::{ - algorithms::components::weakly_connected_components, db::api::{storage::storage_ops::GraphStorage, view::StaticGraphViewOps}, disk_graph::Time, prelude::*, }; - use itertools::{chain, Itertools}; + use itertools::Itertools; use pometry_storage::{graph::TemporalGraph, properties::Properties}; use proptest::{prelude::*, sample::size_range}; use rayon::prelude::*; use std::{ - cmp::Reverse, - iter::once, path::{Path, PathBuf}, sync::Arc, }; @@ -660,51 +657,6 @@ mod test { } } - fn connected_components_check(vs: Vec) { - let vs = vs.into_iter().unique().collect::>(); - - let smallest = vs.iter().min().unwrap(); - - let first = vs[0]; - - // pairs of nodes from vs one after the next - let mut edges = vs - .iter() - .zip(chain!(vs.iter().skip(1), once(&first))) - .enumerate() - .map(|(t, (a, b))| (*a, *b, t as i64, 1f64)) - .collect::>(); - - edges.sort_by_key(|(src, dst, t, _)| (*src, *dst, *t)); - - let test_dir = tempfile::tempdir().unwrap(); - let graph = make_simple_graph(test_dir, &edges); - - let res = weakly_connected_components(&graph, usize::MAX, None).group_by(); - - let actual = res - .into_iter() - .map(|(cc, group)| (cc, Reverse(group.len()))) - .sorted_by(|l, r| l.1.cmp(&r.1)) - .map(|(cc, count)| (cc, count.0)) - .take(1) - .next() - .unwrap(); - - assert_eq!(actual, (*smallest, edges.len())); - } - - #[test] - fn cc_smallest_in_2_edges() { - let vs = vec![9616798649147808099, 0]; - connected_components_check(vs); - } - - proptest! { - #[test] - fn connected_components_smallest_values(vs in any_with::>(size_range(1..=100).lift())){ connected_components_check(vs) } - } - #[test] fn test_par_nodes() { let test_dir = TempDir::new().unwrap(); diff --git a/raphtory/src/disk_graph/mod.rs b/raphtory/src/disk_graph/mod.rs index 1b19a426bb..23f714e49c 100644 --- a/raphtory/src/disk_graph/mod.rs +++ b/raphtory/src/disk_graph/mod.rs @@ -160,7 +160,7 @@ mod test { let actual_inbound = graph .edges(VID(v_id), Direction::IN) - .map(|(_, v)| nodes[v.0]) + .map(|(_, v)| GID::U64(nodes[v.0])) .collect::>(); assert_eq!(expected_inbound, actual_inbound); diff --git a/raphtory/src/disk_graph/storage_interface/node.rs b/raphtory/src/disk_graph/storage_interface/node.rs index 347f931a1a..d04eb0207f 100644 --- a/raphtory/src/disk_graph/storage_interface/node.rs +++ b/raphtory/src/disk_graph/storage_interface/node.rs @@ -1,6 +1,6 @@ use crate::{ core::{ - entities::{edges::edge_ref::EdgeRef, LayerIds, EID, VID}, + entities::{edges::edge_ref::EdgeRef, LayerIds, EID, GID, VID}, Direction, }, db::api::{ @@ -16,7 +16,6 @@ use crate::{ use itertools::Itertools; use polars_arrow::datatypes::ArrowDataType; use pometry_storage::{graph::TemporalGraph, timestamps::TimeStamps, GidRef}; -use raphtory_api::core::input::input_node::InputNode; use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator}; use std::{borrow::Cow, iter, sync::Arc}; @@ -279,11 +278,11 @@ impl<'a> NodeStorageOps<'a> for DiskNode<'a> { self.vid } - fn id(self) -> u64 { + fn id(self) -> GID { match self.graph.node_gid(self.vid).unwrap() { - GidRef::U64(v) => v, - GidRef::I64(v) => v as u64, - GidRef::Str(v) => v.id(), + GidRef::U64(v) => GID::U64(v), + GidRef::I64(v) => GID::I64(v), + GidRef::Str(v) => GID::Str(v.to_string()), } } @@ -526,7 +525,7 @@ impl<'a> NodeStorageOps<'a> for &'a DiskOwnedNode { } #[inline] - fn id(self) -> u64 { + fn id(self) -> GID { self.as_ref().id() } diff --git a/raphtory/src/lib.rs b/raphtory/src/lib.rs index 54470efc9f..331182b80b 100644 --- a/raphtory/src/lib.rs +++ b/raphtory/src/lib.rs @@ -123,6 +123,7 @@ pub mod prelude { }, }; pub use raphtory_api::core::input::input_node::InputNode; + pub use raphtory_api::core::entities::GID; } pub const BINCODE_VERSION: u32 = 2u32;