From c270a31926aaf1a713c313c1b576bf74e3e48e18 Mon Sep 17 00:00:00 2001 From: Shivam Kapoor <4599890+iamsmkr@users.noreply.github.com> Date: Tue, 14 May 2024 11:50:26 +0100 Subject: [PATCH 1/8] fix node type filter --- raphtory/src/db/api/view/node.rs | 2 +- raphtory/src/db/graph/graph.rs | 24 +++++++++++++++++++++++- raphtory/src/db/graph/nodes.rs | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/raphtory/src/db/api/view/node.rs b/raphtory/src/db/api/view/node.rs index ce3f829522..b9810112fc 100644 --- a/raphtory/src/db/api/view/node.rs +++ b/raphtory/src/db/api/view/node.rs @@ -11,7 +11,7 @@ use crate::{ storage::locked::LockedGraph, view::{ internal::{CoreGraphOps, TimeSemantics}, - TimeOps, + Base, TimeOps, }, }, prelude::{EdgeViewOps, GraphViewOps, LayerOps}, diff --git a/raphtory/src/db/graph/graph.rs b/raphtory/src/db/graph/graph.rs index 25066b4c31..bd36b8588c 100644 --- a/raphtory/src/db/graph/graph.rs +++ b/raphtory/src/db/graph/graph.rs @@ -217,7 +217,9 @@ mod db_tests { EdgeViewOps, Layer, LayerOps, NodeViewOps, TimeOps, }, }, - graph::{edge::EdgeView, edges::Edges, node::NodeView, path::PathFromNode}, + graph::{ + edge::EdgeView, edges::Edges, node::NodeView, nodes::Nodes, path::PathFromNode, + }, }, graphgen::random_attachment::random_attachment, prelude::{AdditionOps, PropertyAdditionOps}, @@ -2154,6 +2156,26 @@ mod db_tests { ); } + #[test] + fn test_node_type() { + let g = Graph::new(); + g.add_node(1, 1, NO_PROPS, Some("a")).unwrap(); + g.add_node(2, 2, NO_PROPS, Some("b")).unwrap(); + g.add_node(2, 3, NO_PROPS, Some("b")).unwrap(); + g.add_edge(3, 1, 2, NO_PROPS, None).unwrap(); + g.add_edge(3, 3, 2, NO_PROPS, None).unwrap(); + + for node in g.nodes().filter_by_type(vec!["a"]) { + assert_eq!(node.degree(), 1); + } + + for node in g.nodes() { + if node.node_type() == Some(ArcStr::from("a")) { + assert_eq!(node.degree(), 1); + } + } + } + #[test] fn test_persistent_graph() { let g = Graph::new(); diff --git a/raphtory/src/db/graph/nodes.rs b/raphtory/src/db/graph/nodes.rs index 76a30f2186..0f9a7944d0 100644 --- a/raphtory/src/db/graph/nodes.rs +++ b/raphtory/src/db/graph/nodes.rs @@ -14,10 +14,15 @@ use crate::{ prelude::*, }; -use crate::db::api::storage::locked::LockedGraph; +use crate::{core::ArcStr, db::api::storage::locked::LockedGraph}; use itertools::Itertools; use rayon::iter::ParallelIterator; -use std::{marker::PhantomData, sync::Arc}; +use std::{ + borrow::Borrow, + iter::{FilterMap, FlatMap, Map}, + marker::PhantomData, + sync::Arc, +}; #[derive(Clone)] pub struct Nodes<'graph, G, GH = G> { @@ -96,6 +101,29 @@ impl<'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph>> Nodes<'graph, G, )) } + pub fn filter_by_type, V: AsRef>( + &self, + node_types: I, + ) -> BoxedLIter<'graph, NodeView> + where + I::IntoIter: Send + Sync + 'graph, + V: Send + Sync + 'graph, + { + let base_graph = self.base_graph.clone(); + node_types + .into_iter() + .flat_map(move |nt| { + base_graph.nodes().into_iter().filter_map(move |node| { + if nt.as_ref() == node.node_type()?.as_ref() { + Some(node) + } else { + None + } + }) + }) + .into_dyn_boxed() + } + pub fn collect(&self) -> Vec> { self.iter().collect() } From 36e76cdc1bc0f8081aebe22db356125a661b2f16 Mon Sep 17 00:00:00 2001 From: Shivam Kapoor <4599890+iamsmkr@users.noreply.github.com> Date: Thu, 16 May 2024 16:48:59 +0100 Subject: [PATCH 2/8] rid type_filter --- raphtory-graphql/src/model/graph/nodes.rs | 4 ---- raphtory/src/db/api/view/mod.rs | 2 -- raphtory/src/db/api/view/node_types_filter.rs | 19 ------------------- raphtory/src/db/graph/graph.rs | 2 +- raphtory/src/db/graph/nodes.rs | 9 ++------- raphtory/src/db/graph/path.rs | 10 ---------- raphtory/src/db/task/node/eval_node.rs | 13 +------------ raphtory/src/lib.rs | 2 +- 8 files changed, 5 insertions(+), 56 deletions(-) delete mode 100644 raphtory/src/db/api/view/node_types_filter.rs diff --git a/raphtory-graphql/src/model/graph/nodes.rs b/raphtory-graphql/src/model/graph/nodes.rs index 22be80665f..68c8295f5c 100644 --- a/raphtory-graphql/src/model/graph/nodes.rs +++ b/raphtory-graphql/src/model/graph/nodes.rs @@ -122,8 +122,4 @@ impl GqlNodes { async fn ids(&self) -> Vec { self.nn.name().collect() } - - async fn type_filter(&self, node_types: Vec) -> Self { - self.update(self.nn.type_filter(node_types)) - } } diff --git a/raphtory/src/db/api/view/mod.rs b/raphtory/src/db/api/view/mod.rs index bae339df9b..6812721110 100644 --- a/raphtory/src/db/api/view/mod.rs +++ b/raphtory/src/db/api/view/mod.rs @@ -5,7 +5,6 @@ mod graph; pub(crate) mod internal; mod layer; pub(crate) mod node; -mod node_types_filter; pub(crate) mod time; pub(crate) use edge::BaseEdgeViewOps; @@ -18,7 +17,6 @@ pub use internal::{ pub use layer::*; pub(crate) use node::BaseNodeViewOps; pub use node::NodeViewOps; -pub use node_types_filter::*; pub use time::*; pub type BoxedIter = Box + Send>; diff --git a/raphtory/src/db/api/view/node_types_filter.rs b/raphtory/src/db/api/view/node_types_filter.rs deleted file mode 100644 index 3c8901672c..0000000000 --- a/raphtory/src/db/api/view/node_types_filter.rs +++ /dev/null @@ -1,19 +0,0 @@ -use crate::db::{ - api::view::internal::{CoreGraphOps, OneHopFilter}, - graph::views::node_type_filtered_subgraph::TypeFilteredSubgraph, -}; -use std::borrow::Borrow; - -pub trait NodeTypesFilter<'graph>: OneHopFilter<'graph> { - fn type_filter, V: Borrow>( - &self, - node_types: I, - ) -> Self::Filtered> { - let meta = self.current_filter().node_meta().node_type_meta(); - let r = node_types - .into_iter() - .flat_map(|nt| meta.get_id(nt.borrow())) - .collect(); - self.one_hop_filtered(TypeFilteredSubgraph::new(self.current_filter().clone(), r)) - } -} diff --git a/raphtory/src/db/graph/graph.rs b/raphtory/src/db/graph/graph.rs index 18927937ff..dd009c5b62 100644 --- a/raphtory/src/db/graph/graph.rs +++ b/raphtory/src/db/graph/graph.rs @@ -2165,7 +2165,7 @@ mod db_tests { g.add_edge(3, 1, 2, NO_PROPS, None).unwrap(); g.add_edge(3, 3, 2, NO_PROPS, None).unwrap(); - for node in g.nodes().filter_by_type(vec!["a"]) { + for node in g.nodes().type_filter(vec!["a"]) { assert_eq!(node.degree(), 1); } diff --git a/raphtory/src/db/graph/nodes.rs b/raphtory/src/db/graph/nodes.rs index 0f9a7944d0..f4302e7a39 100644 --- a/raphtory/src/db/graph/nodes.rs +++ b/raphtory/src/db/graph/nodes.rs @@ -6,7 +6,6 @@ use crate::{ view::{ internal::{OneHopFilter, Static}, BaseNodeViewOps, BoxedLIter, DynamicGraph, IntoDynBoxed, IntoDynamic, - NodeTypesFilter, }, }, graph::{edges::NestedEdges, node::NodeView, path::PathFromGraph}, @@ -23,6 +22,7 @@ use std::{ marker::PhantomData, sync::Arc, }; +use crate::db::graph::path::PathFromNode; #[derive(Clone)] pub struct Nodes<'graph, G, GH = G> { @@ -101,7 +101,7 @@ impl<'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph>> Nodes<'graph, G, )) } - pub fn filter_by_type, V: AsRef>( + pub fn type_filter, V: AsRef>( &self, node_types: I, ) -> BoxedLIter<'graph, NodeView> @@ -221,11 +221,6 @@ impl<'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph>> OneHopFilter<'gr } } -impl<'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph>> NodeTypesFilter<'graph> - for Nodes<'graph, G, GH> -{ -} - impl<'graph, G: GraphViewOps<'graph> + 'graph, GH: GraphViewOps<'graph> + 'graph> IntoIterator for Nodes<'graph, G, GH> { diff --git a/raphtory/src/db/graph/path.rs b/raphtory/src/db/graph/path.rs index b23addc917..95f31d8a60 100644 --- a/raphtory/src/db/graph/path.rs +++ b/raphtory/src/db/graph/path.rs @@ -375,16 +375,6 @@ impl<'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph>> OneHopFilter<'gr } } -impl<'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph>> NodeTypesFilter<'graph> - for PathFromGraph<'graph, G, GH> -{ -} - -impl<'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph>> NodeTypesFilter<'graph> - for PathFromNode<'graph, G, GH> -{ -} - #[cfg(test)] mod test { use crate::prelude::*; diff --git a/raphtory/src/db/task/node/eval_node.rs b/raphtory/src/db/task/node/eval_node.rs index 0d113c5e39..84e3c29303 100644 --- a/raphtory/src/db/task/node/eval_node.rs +++ b/raphtory/src/db/task/node/eval_node.rs @@ -16,7 +16,7 @@ use crate::{ graph::{node::NodeView, path::PathFromNode}, task::{node::eval_node_state::EVState, task_state::Local2}, }, - prelude::{GraphViewOps, NodeTypesFilter}, + prelude::{GraphViewOps}, }; use crate::db::{api::storage::locked::LockedGraph, task::edge::eval_edges::EvalEdges}; @@ -532,17 +532,6 @@ impl< } } -impl< - 'graph, - 'a: 'graph, - G: GraphViewOps<'graph>, - S, - CS: ComputeState + 'a, - GH: GraphViewOps<'graph>, - > NodeTypesFilter<'graph> for EvalPathFromNode<'graph, 'a, G, GH, CS, S> -{ -} - /// Represents an entry in the shuffle table. /// /// The entry contains a reference to a `ShuffleComputeState` and an `AccId` representing the accumulator diff --git a/raphtory/src/lib.rs b/raphtory/src/lib.rs index 0236f5965f..3eea2c7095 100644 --- a/raphtory/src/lib.rs +++ b/raphtory/src/lib.rs @@ -109,7 +109,7 @@ pub mod prelude { api::{ mutation::{AdditionOps, DeletionOps, ImportOps, PropertyAdditionOps}, view::{ - EdgeViewOps, GraphViewOps, Layer, LayerOps, NodeTypesFilter, NodeViewOps, + EdgeViewOps, GraphViewOps, Layer, LayerOps, NodeViewOps, TimeOps, }, }, From 755e497d71834a2a5500371e1e5deb88823a7bd6 Mon Sep 17 00:00:00 2001 From: Shivam Kapoor <4599890+iamsmkr@users.noreply.github.com> Date: Fri, 17 May 2024 13:47:29 +0100 Subject: [PATCH 3/8] rid nodetypefilter python --- raphtory/src/python/graph/node.rs | 21 ------------------- .../src/python/types/macros/trait_impl/mod.rs | 3 --- .../macros/trait_impl/nodetypesfilter.rs | 17 --------------- 3 files changed, 41 deletions(-) delete mode 100644 raphtory/src/python/types/macros/trait_impl/nodetypesfilter.rs diff --git a/raphtory/src/python/graph/node.rs b/raphtory/src/python/graph/node.rs index 95a1759326..90768de4c0 100644 --- a/raphtory/src/python/graph/node.rs +++ b/raphtory/src/python/graph/node.rs @@ -419,13 +419,6 @@ pub struct PyNodes { pub(crate) nodes: Nodes<'static, DynamicGraph, DynamicGraph>, } -impl_nodetypesfilter!( - PyNodes, - nodes, - Nodes<'static, DynamicGraph, DynamicGraph>, - "Nodes" -); - impl_nodeviewops!( PyNodes, nodes, @@ -682,13 +675,6 @@ pub struct PyPathFromGraph { path: PathFromGraph<'static, DynamicGraph, DynamicGraph>, } -impl_nodetypesfilter!( - PyPathFromGraph, - path, - PathFromGraph<'static, DynamicGraph, DynamicGraph>, - "PathFromGraph" -); - impl_nodeviewops!( PyPathFromGraph, path, @@ -819,13 +805,6 @@ pub struct PyPathFromNode { path: PathFromNode<'static, DynamicGraph, DynamicGraph>, } -impl_nodetypesfilter!( - PyPathFromNode, - path, - PathFromNode<'static, DynamicGraph, DynamicGraph>, - "PathFromNode" -); - impl_nodeviewops!( PyPathFromNode, path, diff --git a/raphtory/src/python/types/macros/trait_impl/mod.rs b/raphtory/src/python/types/macros/trait_impl/mod.rs index 7293215748..abc9d14852 100644 --- a/raphtory/src/python/types/macros/trait_impl/mod.rs +++ b/raphtory/src/python/types/macros/trait_impl/mod.rs @@ -14,6 +14,3 @@ mod nodeviewops; mod repr; #[macro_use] mod iterable_mixin; - -#[macro_use] -mod nodetypesfilter; diff --git a/raphtory/src/python/types/macros/trait_impl/nodetypesfilter.rs b/raphtory/src/python/types/macros/trait_impl/nodetypesfilter.rs deleted file mode 100644 index 07a2accc5c..0000000000 --- a/raphtory/src/python/types/macros/trait_impl/nodetypesfilter.rs +++ /dev/null @@ -1,17 +0,0 @@ -macro_rules! impl_nodetypesfilter { - ($obj:ty, $field:ident, $base_type:ty, $name:literal) => { - - #[pyo3::pymethods] - impl $obj { - - /// Filter nodes by node types - /// - /// Arguments: - /// node_types (list[str]): list of node types - /// - fn type_filter(&self, node_types: Vec<&str>) -> <$base_type as $crate::db::api::view::internal::OneHopFilter<'static>>::Filtered<$crate::db::graph::views::node_type_filtered_subgraph::TypeFilteredSubgraph<<$base_type as $crate::db::api::view::internal::OneHopFilter<'static>>::FilteredGraph>> { - self.$field.type_filter(node_types) - } - } - }; -} From c59d823b7352b50fc71aaf1c1e64739fba27e89b Mon Sep 17 00:00:00 2001 From: Shivam Kapoor <4599890+iamsmkr@users.noreply.github.com> Date: Fri, 17 May 2024 15:35:20 +0100 Subject: [PATCH 4/8] impl python type filter --- python/tests/test_graphdb.py | 4 ++-- raphtory/src/python/graph/node.rs | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/python/tests/test_graphdb.py b/python/tests/test_graphdb.py index a882ed9f2e..04d8aa22ef 100644 --- a/python/tests/test_graphdb.py +++ b/python/tests/test_graphdb.py @@ -1968,14 +1968,14 @@ def test_one_hop_filter_reset(): assert len(out_out_2) == 0 -def test_node_types(): +def test_node_types_filter(): g = Graph() g.add_node(1, 1, node_type="wallet") g.add_node(1, 2, node_type="timer") g.add_node(1, 3, node_type="timer") g.add_node(1, 4, node_type="wallet") - assert g.nodes.type_filter(["wallet"]).node_type.collect() == ['1', '4'] + assert [node.name for node in g.nodes.type_filter(["wallet"])] == ['1', '4'] assert g.subgraph_node_types(["timer"]).nodes.name.collect() == ['2', '3'] diff --git a/raphtory/src/python/graph/node.rs b/raphtory/src/python/graph/node.rs index 90768de4c0..b4b5500904 100644 --- a/raphtory/src/python/graph/node.rs +++ b/raphtory/src/python/graph/node.rs @@ -42,6 +42,7 @@ use python::{ }; use rayon::{iter::IntoParallelIterator, prelude::*}; use std::collections::HashMap; +use itertools::Itertools; /// A node (or node) in the graph. #[pyclass(name = "Node", subclass)] @@ -662,6 +663,10 @@ impl PyNodes { Ok(df_data.to_object(py)) }) } + + pub fn type_filter(&self, node_types: Vec) -> Vec> { + self.nodes.type_filter(node_types).collect_vec() + } } impl<'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph>> Repr for Nodes<'static, G, GH> { From 1bba94bab5490abad538a2179b3d9c5b9117ad1d Mon Sep 17 00:00:00 2001 From: Shivam Kapoor <4599890+iamsmkr@users.noreply.github.com> Date: Fri, 17 May 2024 15:37:42 +0100 Subject: [PATCH 5/8] fmt --- raphtory/src/db/graph/nodes.rs | 11 ++--------- raphtory/src/db/task/node/eval_node.rs | 2 +- raphtory/src/lib.rs | 5 +---- raphtory/src/python/graph/node.rs | 2 +- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/raphtory/src/db/graph/nodes.rs b/raphtory/src/db/graph/nodes.rs index f4302e7a39..90d51523f5 100644 --- a/raphtory/src/db/graph/nodes.rs +++ b/raphtory/src/db/graph/nodes.rs @@ -13,16 +13,9 @@ use crate::{ prelude::*, }; -use crate::{core::ArcStr, db::api::storage::locked::LockedGraph}; -use itertools::Itertools; +use crate::db::api::storage::locked::LockedGraph; use rayon::iter::ParallelIterator; -use std::{ - borrow::Borrow, - iter::{FilterMap, FlatMap, Map}, - marker::PhantomData, - sync::Arc, -}; -use crate::db::graph::path::PathFromNode; +use std::{borrow::Borrow, marker::PhantomData, sync::Arc}; #[derive(Clone)] pub struct Nodes<'graph, G, GH = G> { diff --git a/raphtory/src/db/task/node/eval_node.rs b/raphtory/src/db/task/node/eval_node.rs index 84e3c29303..f5cfe1ce44 100644 --- a/raphtory/src/db/task/node/eval_node.rs +++ b/raphtory/src/db/task/node/eval_node.rs @@ -16,7 +16,7 @@ use crate::{ graph::{node::NodeView, path::PathFromNode}, task::{node::eval_node_state::EVState, task_state::Local2}, }, - prelude::{GraphViewOps}, + prelude::GraphViewOps, }; use crate::db::{api::storage::locked::LockedGraph, task::edge::eval_edges::EvalEdges}; diff --git a/raphtory/src/lib.rs b/raphtory/src/lib.rs index 3eea2c7095..e7b9e07536 100644 --- a/raphtory/src/lib.rs +++ b/raphtory/src/lib.rs @@ -108,10 +108,7 @@ pub mod prelude { db::{ api::{ mutation::{AdditionOps, DeletionOps, ImportOps, PropertyAdditionOps}, - view::{ - EdgeViewOps, GraphViewOps, Layer, LayerOps, NodeViewOps, - TimeOps, - }, + view::{EdgeViewOps, GraphViewOps, Layer, LayerOps, NodeViewOps, TimeOps}, }, graph::graph::Graph, }, diff --git a/raphtory/src/python/graph/node.rs b/raphtory/src/python/graph/node.rs index b4b5500904..a223b67b0c 100644 --- a/raphtory/src/python/graph/node.rs +++ b/raphtory/src/python/graph/node.rs @@ -27,6 +27,7 @@ use crate::{ *, }; use chrono::{DateTime, Utc}; +use itertools::Itertools; use pyo3::{ exceptions::{PyIndexError, PyKeyError}, prelude::*, @@ -42,7 +43,6 @@ use python::{ }; use rayon::{iter::IntoParallelIterator, prelude::*}; use std::collections::HashMap; -use itertools::Itertools; /// A node (or node) in the graph. #[pyclass(name = "Node", subclass)] From c71ea06e3d7e6c71d538cbb74ed0ead9eb8137e6 Mon Sep 17 00:00:00 2001 From: Shivam Kapoor <4599890+iamsmkr@users.noreply.github.com> Date: Fri, 17 May 2024 15:49:20 +0100 Subject: [PATCH 6/8] fix graphql type filter --- raphtory-graphql/src/model/graph/nodes.rs | 6 ++++-- raphtory-graphql/src/model/graph/path_from_node.rs | 4 ---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/raphtory-graphql/src/model/graph/nodes.rs b/raphtory-graphql/src/model/graph/nodes.rs index 33e4dfad44..341f6a90e8 100644 --- a/raphtory-graphql/src/model/graph/nodes.rs +++ b/raphtory-graphql/src/model/graph/nodes.rs @@ -1,9 +1,11 @@ use crate::model::graph::node::Node; use dynamic_graphql::{ResolvedObject, ResolvedObjectFields}; +use itertools::Itertools; use raphtory::{ db::{api::view::DynamicGraph, graph::nodes::Nodes}, prelude::*, }; +use raphtory::db::graph::node::NodeView; #[derive(ResolvedObject)] pub(crate) struct GqlNodes { @@ -77,8 +79,8 @@ impl GqlNodes { self.update(self.nn.shrink_end(end)) } - async fn type_filter(&self, node_types: Vec) -> Self { - self.update(self.nn.type_filter(node_types)) + async fn type_filter(&self, node_types: Vec) -> Vec { + self.nn.type_filter(node_types).into_iter().map(Node::from).collect_vec() } //////////////////////// diff --git a/raphtory-graphql/src/model/graph/path_from_node.rs b/raphtory-graphql/src/model/graph/path_from_node.rs index 80509414b3..f9ab931efb 100644 --- a/raphtory-graphql/src/model/graph/path_from_node.rs +++ b/raphtory-graphql/src/model/graph/path_from_node.rs @@ -78,10 +78,6 @@ impl GqlPathFromNode { self.update(self.nn.shrink_end(end)) } - async fn type_filter(&self, node_types: Vec) -> Self { - self.update(self.nn.type_filter(node_types)) - } - //////////////////////// //// TIME QUERIES ////// //////////////////////// From 278eaef4c92506add2974de6a5400a47e8a428e9 Mon Sep 17 00:00:00 2001 From: Shivam Kapoor <4599890+iamsmkr@users.noreply.github.com> Date: Fri, 17 May 2024 15:50:12 +0100 Subject: [PATCH 7/8] fmt --- raphtory-graphql/src/model/graph/nodes.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/raphtory-graphql/src/model/graph/nodes.rs b/raphtory-graphql/src/model/graph/nodes.rs index 341f6a90e8..69e2b95098 100644 --- a/raphtory-graphql/src/model/graph/nodes.rs +++ b/raphtory-graphql/src/model/graph/nodes.rs @@ -2,10 +2,12 @@ use crate::model::graph::node::Node; use dynamic_graphql::{ResolvedObject, ResolvedObjectFields}; use itertools::Itertools; use raphtory::{ - db::{api::view::DynamicGraph, graph::nodes::Nodes}, + db::{ + api::view::DynamicGraph, + graph::{node::NodeView, nodes::Nodes}, + }, prelude::*, }; -use raphtory::db::graph::node::NodeView; #[derive(ResolvedObject)] pub(crate) struct GqlNodes { @@ -80,7 +82,11 @@ impl GqlNodes { } async fn type_filter(&self, node_types: Vec) -> Vec { - self.nn.type_filter(node_types).into_iter().map(Node::from).collect_vec() + self.nn + .type_filter(node_types) + .into_iter() + .map(Node::from) + .collect_vec() } //////////////////////// From 8dd8d12264d186bb96c76fb8a9eaaff3592d28a8 Mon Sep 17 00:00:00 2001 From: Shivam Kapoor <4599890+iamsmkr@users.noreply.github.com> Date: Fri, 17 May 2024 16:00:35 +0100 Subject: [PATCH 8/8] more tests --- python/tests/test_graphdb.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/python/tests/test_graphdb.py b/python/tests/test_graphdb.py index 3dd6ea96ea..4209d3864d 100644 --- a/python/tests/test_graphdb.py +++ b/python/tests/test_graphdb.py @@ -1989,6 +1989,35 @@ def test_node_types_filter(): assert [node.name for node in g.nodes.type_filter(["wallet"])] == ['1', '4'] assert g.subgraph_node_types(["timer"]).nodes.name.collect() == ['2', '3'] + g = PersistentGraph() + g.add_node(1, 1, node_type="wallet") + g.add_node(2, 2, node_type="timer") + g.add_node(3, 3, node_type="timer") + g.add_node(4, 4, node_type="wallet") + + assert [node.name for node in g.nodes.type_filter(["wallet"])] == ['1', '4'] + assert g.subgraph_node_types(["timer"]).nodes.name.collect() == ['2', '3'] + + subgraph = g.subgraph([1, 2, 3]) + assert [node.name for node in subgraph.nodes.type_filter(["wallet"])] == ['1'] + assert subgraph.subgraph_node_types(["timer"]).nodes.name.collect() == ['2', '3'] + + w = g.window(1, 3) + assert [node.name for node in w.nodes.type_filter(["wallet"])] == ['1'] + assert w.subgraph_node_types(["timer"]).nodes.name.collect() == ['2', '3'] + + g = Graph() + g.add_node(1, 1, node_type="wallet") + g.add_node(2, 2, node_type="timer") + g.add_node(3, 3, node_type="timer") + g.add_node(4, 4, node_type="counter") + g.add_edge(1, 1, 2, layer="layer1") + g.add_edge(2, 2, 3, layer="layer1") + g.add_edge(3, 2, 4, layer="layer2") + layer = g.layers(["layer1"]) + assert [node.name for node in layer.nodes.type_filter(["wallet"])] == ['1'] + assert layer.subgraph_node_types(["timer"]).nodes.name.collect() == ['2', '3'] + def test_time_exploded_edges(): g = Graph()