Skip to content

Commit

Permalink
fix graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmurariu committed Jul 22, 2024
1 parent a672642 commit d67043a
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 68 deletions.
2 changes: 1 addition & 1 deletion js-raphtory/src/graph/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl From<NodeView<TGraph>> 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)]
Expand Down
2 changes: 1 addition & 1 deletion pometry-storage-private
2 changes: 1 addition & 1 deletion raphtory-api/src/core/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<'source> FromPyObject<'source> for GID {
.map(GID::I64)
.or_else(|_| id.extract::<u64>().map(GID::U64))
})
.map_err(|err| {
.map_err(|_| {
let msg = "IDs need to be strings or an unsigned integers";
PyTypeError::new_err(msg)
})
Expand Down
9 changes: 7 additions & 2 deletions raphtory-benchmark/benches/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ pub fn run_analysis_benchmarks<F, G>(
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
Expand All @@ -285,7 +285,12 @@ pub fn run_analysis_benchmarks<F, G>(
.map(|e| (e.src().id(), e.dst().id(), e.time().expect("need time")))
.collect::<Vec<_>>();

let nodes: HashSet<u64> = graph.nodes().id().into_iter().collect();
let nodes: HashSet<u64> = 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())
Expand Down
4 changes: 2 additions & 2 deletions raphtory-benchmark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
Expand Down
2 changes: 1 addition & 1 deletion raphtory-graphql/src/model/graph/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl GqlNodes {
}

fn iter(&self) -> Box<dyn Iterator<Item = Node> + '_> {
let iter = self.nn.iter().map(Node::from);
let iter = self.nn.iter_owned().map(Node::from);
Box::new(iter)
}
}
Expand Down
2 changes: 1 addition & 1 deletion raphtory-graphql/src/model/schema/node_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion raphtory/src/db/graph/views/window_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
2 changes: 1 addition & 1 deletion raphtory/src/disk_graph/graph_impl/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use raphtory_api::core::{
};

impl GraphLike<TimeIndexEntry> for Graph {
fn external_ids(&self) -> Vec<u64> {
fn external_ids(&self) -> Vec<GID> {
self.nodes().id().collect()
}

Expand Down
50 changes: 1 addition & 49 deletions raphtory/src/disk_graph/graph_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -660,51 +657,6 @@ mod test {
}
}

fn connected_components_check(vs: Vec<u64>) {
let vs = vs.into_iter().unique().collect::<Vec<u64>>();

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::<Vec<(u64, u64, i64, f64)>>();

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::<Vec<u64>>(size_range(1..=100).lift())){ connected_components_check(vs) }
}

#[test]
fn test_par_nodes() {
let test_dir = TempDir::new().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion raphtory/src/disk_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();

assert_eq!(expected_inbound, actual_inbound);
Expand Down
13 changes: 6 additions & 7 deletions raphtory/src/disk_graph/storage_interface/node.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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};

Expand Down Expand Up @@ -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()),
}
}

Expand Down Expand Up @@ -526,7 +525,7 @@ impl<'a> NodeStorageOps<'a> for &'a DiskOwnedNode {
}

#[inline]
fn id(self) -> u64 {
fn id(self) -> GID {
self.as_ref().id()
}

Expand Down
1 change: 1 addition & 0 deletions raphtory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d67043a

Please sign in to comment.