Skip to content

Commit

Permalink
fix(interactive): fix bug when concating simple path in GIE Runtime (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
BingqingLyu authored Aug 13, 2024
1 parent 3b49437 commit ce93b02
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,31 @@ impl GraphPath {
}

// append another path to the current path, and return the flag of whether the path has been appended or not.
// notice that, if the path is a simple path, we simply concatenate the two paths, without checking the duplication (this may not be as expected)
// e.g., [1,2,3] + [4,5] = [1,2,3,4,5]
// notice that, if the path is a simple path, we further check the duplication
// e.g., [1,2,3] + [3,4,5] will return false
pub fn append_path(&mut self, other: GraphPath) -> bool {
match self {
GraphPath::AllPath(ref mut p) | GraphPath::SimpleAllPath(ref mut p) => {
GraphPath::AllPath(ref mut p) => {
if let Some(other_path) = other.take_path() {
p.extend(other_path);
true
} else {
false
}
}
GraphPath::SimpleAllPath(_) => {
if let Some(other_path) = other.take_path() {
for e in other_path {
if !self.append(e) {
return false;
}
}
true
} else {
false
}
}
GraphPath::EndV(_) | GraphPath::SimpleEndV(_) => false,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ fn exec_projector(input: &Record, projector: &Projector) -> FnExecResult<DynEntr
"Concat vertices are not the same in PathConcat"
)))?
} else if !concat_success {
Err(FnExecError::unexpected_data_error(&format!("Failed to concat paths in PathConcat")))?
return Ok(Object::None.into());
} else {
DynEntry::new(left_path)
}
Expand Down Expand Up @@ -1577,6 +1577,19 @@ mod tests {
path
}

fn build_simple_path(vids: Vec<i64>) -> GraphPath {
let details = DynDetails::default();
let mut path = GraphPath::new(
Vertex::new(vids[0], None, details.clone()),
pb::path_expand::PathOpt::Simple,
pb::path_expand::ResultOpt::AllV,
);
for i in 1..vids.len() {
path.append(Vertex::new(vids[i], None, details.clone()));
}
path
}

fn build_project_path_concat(
left_endpoint: common_pb::path_concat::Endpoint, right_endpoint: common_pb::path_concat::Endpoint,
) -> pb::Project {
Expand Down Expand Up @@ -1739,6 +1752,40 @@ mod tests {
assert_eq!(results, vec![concat_path]);
}

#[test]
fn project_concat_simple_path_test_01() {
// sub_path1: [1,2]
let sub_path1 = build_simple_path(vec![1, 2]);
// sub_path2: [3,2]
let sub_path2 = build_simple_path(vec![3, 2]);
// concat project
let project_opr_pb = build_project_path_concat(
common_pb::path_concat::Endpoint::End,
common_pb::path_concat::Endpoint::End,
);
// concat path: [1,2,3]
let concat_path = build_path(vec![1, 2, 3]);
project_concat_allv_path_test(sub_path1, sub_path2, project_opr_pb, concat_path);
}

#[test]
fn project_concat_simple_path_test_02() {
// sub_path1: [1,4,2]
let sub_path1 = build_simple_path(vec![1, 4, 2]);
// sub_path2: [3,4,2]
let sub_path2 = build_simple_path(vec![3, 4, 2]);
// concat project
let project_opr_pb = build_project_path_concat(
common_pb::path_concat::Endpoint::End,
common_pb::path_concat::Endpoint::End,
);
// concat path: None
let mut r1 = Record::new(sub_path1, Some(TAG_A.into()));
r1.append(sub_path2, Some(TAG_B.into()));
let mut result = project_test(vec![r1], project_opr_pb);
assert!(result.next().is_none());
}

// a fail test case
#[test]
fn project_concat_allv_path_error_test() {
Expand Down

0 comments on commit ce93b02

Please sign in to comment.