Skip to content

Commit f5b8763

Browse files
committed
edges const prop iter do not aligh keys with values
1 parent e4663e3 commit f5b8763

File tree

5 files changed

+73
-9
lines changed

5 files changed

+73
-9
lines changed

raphtory/src/core/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ impl PartialOrd for Prop {
163163
}
164164

165165
impl Prop {
166+
pub fn map(vals: impl IntoIterator<Item = (impl Into<ArcStr>, Prop)>) -> Self {
167+
let h_map: HashMap<_, _> = vals.into_iter().map(|(k, v)| (k.into(), v)).collect();
168+
Prop::Map(h_map.into())
169+
}
170+
166171
pub fn from_arr<TT: ArrowPrimitiveType>(vals: Vec<TT::Native>) -> Self
167172
where
168173
arrow_array::PrimitiveArray<TT>: From<Vec<TT::Native>>,

raphtory/src/db/api/properties/constant_props.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl<'a, P: ConstPropertiesOps + Sync> ConstantProperties<'a, P> {
2121
self.props.const_prop_keys()
2222
}
2323

24-
pub fn values(&self) -> BoxedLIter<Prop> {
24+
pub fn values(&self) -> BoxedLIter<Option<Prop>> {
2525
self.props.const_prop_values()
2626
}
2727

@@ -55,7 +55,11 @@ impl<'a, P: ConstPropertiesOps + Sync + 'a> IntoIterator for ConstantProperties<
5555
Box::new(GenLockedIter::from(self, |const_prop| {
5656
let keys = const_prop.keys();
5757
let vals = const_prop.values();
58-
Box::new(keys.into_iter().zip(vals))
58+
Box::new(
59+
keys.into_iter()
60+
.zip(vals)
61+
.filter_map(|(k, v)| Some((k, v?))),
62+
)
5963
}))
6064
}
6165
}
@@ -67,7 +71,11 @@ impl<'a, P: ConstPropertiesOps + Sync> IntoIterator for &'a ConstantProperties<'
6771
fn into_iter(self) -> Self::IntoIter {
6872
let keys = self.keys();
6973
let vals = self.values();
70-
Box::new(keys.into_iter().zip(vals))
74+
Box::new(
75+
keys.into_iter()
76+
.zip(vals)
77+
.filter_map(|(k, v)| Some((k, v?))),
78+
)
7179
}
7280
}
7381

raphtory/src/db/api/properties/internal.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ pub trait ConstPropertiesOps: Send + Sync {
5353
fn const_prop_keys(&self) -> BoxedLIter<ArcStr> {
5454
Box::new(self.const_prop_ids().map(|id| self.get_const_prop_name(id)))
5555
}
56-
fn const_prop_values(&self) -> BoxedLIter<Prop> {
57-
Box::new(self.const_prop_ids().filter_map(|k| self.get_const_prop(k)))
56+
fn const_prop_values(&self) -> BoxedLIter<Option<Prop>> {
57+
Box::new(self.const_prop_ids().map(|k| self.get_const_prop(k)))
5858
}
5959
fn get_const_prop(&self, id: usize) -> Option<Prop>;
6060
}
@@ -173,7 +173,7 @@ where
173173
}
174174

175175
#[inline]
176-
fn const_prop_values(&self) -> BoxedLIter<Prop> {
176+
fn const_prop_values(&self) -> BoxedLIter<Option<Prop>> {
177177
self.base().const_prop_values()
178178
}
179179

raphtory/src/db/graph/graph.rs

+53-2
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ mod db_tests {
425425
db::{
426426
api::{
427427
properties::internal::{ConstPropertiesOps, TemporalPropertiesRowView},
428+
storage::graph::edges::edge_storage_ops::EdgeStorageOps,
428429
view::{
429430
internal::{CoreGraphOps, EdgeFilterOps, TimeSemantics},
430431
time::internal::InternalTimeOps,
@@ -442,7 +443,7 @@ mod db_tests {
442443
use itertools::Itertools;
443444
use quickcheck_macros::quickcheck;
444445
use raphtory_api::core::{
445-
entities::{GID, VID},
446+
entities::{EID, GID, VID},
446447
storage::{
447448
arc_str::{ArcStr, OptionAsStr},
448449
timeindex::TimeIndexEntry,
@@ -457,6 +458,56 @@ mod db_tests {
457458
use tempfile::TempDir;
458459
use tracing::{error, info};
459460

461+
#[test]
462+
fn edge_const_props() {
463+
let g = Graph::new();
464+
465+
g.add_edge(0, 0, 0, NO_PROPS, None);
466+
g.add_edge(0, 0, 1, NO_PROPS, None);
467+
468+
g.edge(0, 0)
469+
.unwrap()
470+
.update_constant_properties(
471+
vec![("x".to_string(), Prop::map([("n", Prop::U64(23))]))],
472+
None,
473+
)
474+
.unwrap();
475+
g.edge(0, 1)
476+
.unwrap()
477+
.update_constant_properties(
478+
vec![(
479+
"a".to_string(),
480+
Prop::map([("a", Prop::U8(1)), ("b", Prop::str("baa"))]),
481+
)],
482+
None,
483+
)
484+
.unwrap();
485+
486+
let e1 = g.edge(0, 0).unwrap();
487+
let actual = e1
488+
.properties()
489+
.constant()
490+
.iter()
491+
.map(|(k, v)| (k.to_string(), v))
492+
.collect::<Vec<_>>();
493+
assert!(actual.contains(&("x".to_string(), Prop::map([("n", Prop::U64(23))]))));
494+
495+
let e2 = g.edge(0, 1).unwrap();
496+
let actual = e2
497+
.properties()
498+
.constant()
499+
.iter()
500+
.map(|(k, v)| (k.to_string(), v))
501+
.collect::<Vec<_>>();
502+
assert_eq!(
503+
actual,
504+
vec![(
505+
"a".to_string(),
506+
Prop::map([("b", Prop::str("baa")), ("a", Prop::U8(1))])
507+
)]
508+
);
509+
}
510+
460511
#[test]
461512
fn test_empty_graph() {
462513
let graph = Graph::new();
@@ -486,7 +537,7 @@ mod db_tests {
486537
);
487538
assert_eq!(
488539
graph.const_prop_values().collect::<Vec<_>>(),
489-
Vec::<Prop>::new()
540+
Vec::<Option<Prop>>::new()
490541
);
491542
assert!(graph.constant_prop(1).is_none());
492543
assert!(graph.get_const_prop_id("1").is_none());

raphtory/src/python/graph/properties/constant_props.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl PyConstantProperties {
6060
///
6161
/// Returns:
6262
/// list | Array: the property values
63-
pub fn values(&self) -> Vec<Prop> {
63+
pub fn values(&self) -> Vec<Option<Prop>> {
6464
self.props.values().collect()
6565
}
6666

0 commit comments

Comments
 (0)