From c7c7cd25ddb89e96b59fa8e02783cec785048cce Mon Sep 17 00:00:00 2001 From: BingqingLyu Date: Mon, 21 Oct 2024 11:07:11 +0800 Subject: [PATCH] [GIE Runtime] do not throw error for shortest path --- .../graph_proxy/src/apis/graph/element/path.rs | 16 +++++++++++++--- .../src/process/operator/map/path_start.rs | 3 ++- .../src/process/operator/map/project.rs | 18 ++++++++++++------ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/interactive_engine/executor/ir/graph_proxy/src/apis/graph/element/path.rs b/interactive_engine/executor/ir/graph_proxy/src/apis/graph/element/path.rs index bb1c1a0d30f6..be33e6d1b88b 100644 --- a/interactive_engine/executor/ir/graph_proxy/src/apis/graph/element/path.rs +++ b/interactive_engine/executor/ir/graph_proxy/src/apis/graph/element/path.rs @@ -96,8 +96,11 @@ pub enum GraphPath { impl GraphPath { pub fn new>( entry: E, path_opt: pb::path_expand::PathOpt, result_opt: pb::path_expand::ResultOpt, - ) -> Self { - match result_opt { + ) -> Result { + if let pb::path_expand::PathOpt::AnyShortest | pb::path_expand::PathOpt::AllShortest = path_opt { + return Err(ParsePbError::Unsupported("unsupported path type of shortest path".to_string())); + } + let path = match result_opt { pb::path_expand::ResultOpt::EndV => match path_opt { pb::path_expand::PathOpt::Arbitrary => GraphPath::EndV((entry.into(), 1)), pb::path_expand::PathOpt::Simple => { @@ -106,13 +109,20 @@ impl GraphPath { GraphPath::SimpleEndV((entry, vec![id], 1)) } pb::path_expand::PathOpt::Trail => GraphPath::TrailAllPath(vec![entry.into()]), + pb::path_expand::PathOpt::AnyShortest | pb::path_expand::PathOpt::AllShortest => { + unreachable!() + } }, pb::path_expand::ResultOpt::AllV | pb::path_expand::ResultOpt::AllVE => match path_opt { pb::path_expand::PathOpt::Arbitrary => GraphPath::AllPath(vec![entry.into()]), pb::path_expand::PathOpt::Simple => GraphPath::SimpleAllPath(vec![entry.into()]), pb::path_expand::PathOpt::Trail => GraphPath::TrailAllPath(vec![entry.into()]), + pb::path_expand::PathOpt::AnyShortest | pb::path_expand::PathOpt::AllShortest => { + unreachable!() + } }, - } + }; + Ok(path) } // append an entry and return the flag of whether the entry has been appended or not. diff --git a/interactive_engine/executor/ir/runtime/src/process/operator/map/path_start.rs b/interactive_engine/executor/ir/runtime/src/process/operator/map/path_start.rs index 551cb21c3e59..31221aff3a11 100644 --- a/interactive_engine/executor/ir/runtime/src/process/operator/map/path_start.rs +++ b/interactive_engine/executor/ir/runtime/src/process/operator/map/path_start.rs @@ -41,7 +41,8 @@ impl FilterMapFunction for PathStartOperator { self.start_tag, input )) })?; - let graph_path = GraphPath::new(v.clone(), self.path_opt, self.result_opt); + let graph_path = GraphPath::new(v.clone(), self.path_opt, self.result_opt) + .map_or_else(|e| Err(FnExecError::unsupported_error(&format!("{}", e))), |p| Ok(p))?; input.append(graph_path, None); Ok(Some(input)) } else { diff --git a/interactive_engine/executor/ir/runtime/src/process/operator/map/project.rs b/interactive_engine/executor/ir/runtime/src/process/operator/map/project.rs index 0bf37fd2b18f..8f5d918d13bc 100644 --- a/interactive_engine/executor/ir/runtime/src/process/operator/map/project.rs +++ b/interactive_engine/executor/ir/runtime/src/process/operator/map/project.rs @@ -1570,7 +1570,8 @@ mod tests { Vertex::new(vids[0], None, details.clone()), pb::path_expand::PathOpt::Arbitrary, pb::path_expand::ResultOpt::AllV, - ); + ) + .unwrap(); for i in 1..vids.len() { path.append(Vertex::new(vids[i], None, details.clone())); } @@ -1583,7 +1584,8 @@ mod tests { Vertex::new(vids[0], None, details.clone()), pb::path_expand::PathOpt::Simple, pb::path_expand::ResultOpt::AllV, - ); + ) + .unwrap(); for i in 1..vids.len() { path.append(Vertex::new(vids[i], None, details.clone())); } @@ -1708,7 +1710,8 @@ mod tests { Vertex::new(1, None, details.clone()), pb::path_expand::PathOpt::Arbitrary, pb::path_expand::ResultOpt::AllVE, - ); + ) + .unwrap(); sub_path1.append(Edge::new(12, None, 1, 2, details.clone())); sub_path1.append(Vertex::new(2, None, details.clone())); // sub_path2: [3 <- 2] @@ -1716,7 +1719,8 @@ mod tests { Vertex::new(3, None, details.clone()), pb::path_expand::PathOpt::Arbitrary, pb::path_expand::ResultOpt::AllVE, - ); + ) + .unwrap(); sub_path2.append(Edge::new(23, None, 2, 3, details.clone())); sub_path2.append(Vertex::new(2, None, details.clone())); // concat path: [1 -> 2 <- 3] @@ -1724,7 +1728,8 @@ mod tests { Vertex::new(1, None, details.clone()), pb::path_expand::PathOpt::Arbitrary, pb::path_expand::ResultOpt::AllVE, - ); + ) + .unwrap(); concat_path.append(Edge::new(12, None, 1, 2, details.clone())); concat_path.append(Vertex::new(2, None, details.clone())); concat_path.append(Edge::new(23, None, 2, 3, details.clone())); @@ -1811,7 +1816,8 @@ mod tests { let vertex1 = init_vertex1(); let vertex2 = init_vertex2(); let mut path = - GraphPath::new(vertex1, pb::path_expand::PathOpt::Arbitrary, pb::path_expand::ResultOpt::AllV); + GraphPath::new(vertex1, pb::path_expand::PathOpt::Arbitrary, pb::path_expand::ResultOpt::AllV) + .unwrap(); path.append(vertex2); Record::new(path, None) }