Skip to content

Commit

Permalink
[GIE] Support PathExpand with OPT=ALL_V_E in GIE (#2841)
Browse files Browse the repository at this point in the history
<!--
Thanks for your contribution! please review
https://github.com/alibaba/GraphScope/blob/main/CONTRIBUTING.md before
opening an issue.
-->

## What do these changes do?

<!-- Please give a short brief about these changes. -->

As titled.

You can query a path expand with both vertices and edges preserved by
specify the `ResultOpt` as `ALL_V_E`.


## Related issue number

<!-- Are there any issues opened that will be resolved by merging this
change? -->

Fixes #2776

---------

Co-authored-by: shirly121 <yihe.zxl@alibaba-inc.com>
  • Loading branch information
BingqingLyu and shirly121 authored Jun 13, 2023
1 parent 3773889 commit e9af91a
Show file tree
Hide file tree
Showing 27 changed files with 583 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ public static final PathOpt ffiPathOpt(GraphOpt.PathExpandPath opt) {

public static final ResultOpt ffiResultOpt(GraphOpt.PathExpandResult opt) {
switch (opt) {
case EndV:
case END_V:
return ResultOpt.EndV;
case AllV:
default:
case ALL_V:
return ResultOpt.AllV;
case ALL_V_E:
default:
return ResultOpt.AllVE;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public enum PathExpandPath {
}

public enum PathExpandResult {
EndV,
AllV
END_V,
ALL_V,
ALL_V_E
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected Builder(GraphBuilder innerBuilder) {
(GraphOptCluster) innerBuilder.getCluster(),
innerBuilder.getRelOptSchema());
this.pathOpt = GraphOpt.PathExpandPath.ARBITRARY;
this.resultOpt = GraphOpt.PathExpandResult.EndV;
this.resultOpt = GraphOpt.PathExpandResult.END_V;
}

public Builder expand(ExpandConfig config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

public enum ResultOpt implements IntEnum<ResultOpt> {
EndV,
AllV;
AllV,
AllVE;

@Override
public int getInt() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ public void configure(final Object... keyValues) {
+ " insensitive)");
}
} else if (key.equals("ResultOpt")) {
if (value.equals("AllV") || value.equals("EndV")) {
if (value.equals("AllV") || value.equals("EndV") || value.equals("AllVE")) {
this.resultOpt = ResultOpt.valueOf(value);
} else {
throw new ExtendGremlinStepException(
"value "
+ originalVal
+ " is invalid, use ALL_V or END_V instead (case insensitive)");
+ " is invalid, use ALL_V, END_V, ALL_VE instead (case"
+ " insensitive)");
}
} else if (key.equals("Until")) {
this.untilCondition = ObjectUtils.requireNonEmpty(originalVal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void expand_3_test() {
pxdBuilder.literal(10)))
.range(1, 3)
.pathOpt(GraphOpt.PathExpandPath.SIMPLE)
.resultOpt(GraphOpt.PathExpandResult.AllV)
.resultOpt(GraphOpt.PathExpandResult.ALL_V)
.build();
RelNode pathExpand =
builder.source(
Expand All @@ -108,7 +108,7 @@ public void expand_3_test() {
+ " tables=[knows]}], alias=[DEFAULT], opt=[OUT])\n"
+ "], getV=[GraphLogicalGetV(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[DEFAULT], fusedFilter=[[=(DEFAULT.age, 10)]], opt=[END])\n"
+ "], offset=[1], fetch=[3], path_opt=[SIMPLE], result_opt=[AllV],"
+ "], offset=[1], fetch=[3], path_opt=[SIMPLE], result_opt=[ALL_V],"
+ " alias=[DEFAULT])\n"
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[DEFAULT], opt=[VERTEX])",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void push_filter_2_test() {
.getV(getVConfig)
.range(1, 3)
.pathOpt(GraphOpt.PathExpandPath.SIMPLE)
.resultOpt(GraphOpt.PathExpandResult.AllV)
.resultOpt(GraphOpt.PathExpandResult.ALL_V)
.build();
RelNode sentence =
builder.source(
Expand Down Expand Up @@ -96,7 +96,7 @@ public void push_filter_2_test() {
+ " tables=[knows]}], alias=[DEFAULT], opt=[OUT])\n"
+ "], getV=[GraphLogicalGetV(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[DEFAULT], opt=[END])\n"
+ "], offset=[1], fetch=[3], path_opt=[SIMPLE], result_opt=[AllV],"
+ "], offset=[1], fetch=[3], path_opt=[SIMPLE], result_opt=[ALL_V],"
+ " alias=[DEFAULT])\n"
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[x], opt=[VERTEX])\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void logical_plan_test() throws Exception {
.getV(getVConfig)
.range(1, 3)
.pathOpt(GraphOpt.PathExpandPath.SIMPLE)
.resultOpt(GraphOpt.PathExpandResult.AllV)
.resultOpt(GraphOpt.PathExpandResult.ALL_V)
.build();
RelNode node =
builder.source(
Expand Down Expand Up @@ -77,7 +77,7 @@ public void logical_plan_test() throws Exception {
+ " tables=[knows]}], alias=[DEFAULT], opt=[OUT])\n"
+ "], getV=[GraphLogicalGetV(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[DEFAULT], opt=[END])\n"
+ "], offset=[1], fetch=[3], path_opt=[SIMPLE], result_opt=[AllV],"
+ "], offset=[1], fetch=[3], path_opt=[SIMPLE], result_opt=[ALL_V],"
+ " alias=[DEFAULT])\n"
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[x], opt=[VERTEX])\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void match_4_test() {
+ " 1.0E0)]], opt=[OUT])\n"
+ "], getV=[GraphLogicalGetV(tableConfig=[{isAll=true, tables=[software,"
+ " person]}], alias=[DEFAULT], opt=[END])\n"
+ "], offset=[1], fetch=[2], path_opt=[ARBITRARY], result_opt=[EndV],"
+ "], offset=[1], fetch=[2], path_opt=[ARBITRARY], result_opt=[END_V],"
+ " alias=[b])\n"
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[a], opt=[VERTEX])\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void g_V_path_expand_label_test() {
Assert.assertEquals("knows", label.name);
}

// g.V().out("1..2").with("Path_Opt", "Simple").with("Result_Opt", "AllV")
// g.V().out("1..2").with("Path_Opt", "Simple").with("Result_Opt", "ALL_V")
@Test
public void g_V_path_expand_with_test() {
Traversal traversal =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ public void g_V_has_notEndingWith_test() {
eval("g.V().has(\"name\", TextP.notEndingWith(\"marko\"))"));
}

// g.V().as("a").select("a").by(out("1..2").with("Result_Opt", AllV).count())
// g.V().as("a").select("a").by(out("1..2").with("Result_Opt", ALL_V).count())
@Test
public void g_V_as_select_a_by_out_1_2_endV_count_test() {
Assert.assertEquals(
Expand Down
1 change: 1 addition & 0 deletions interactive_engine/executor/ir/core/src/plan/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2175,6 +2175,7 @@ mod graph {
pub enum PathResultOpt {
EndV = 0,
AllV = 1,
AllVE = 2,
}

/// To initialize an path expand operator from an edge_expand base
Expand Down
4 changes: 4 additions & 0 deletions interactive_engine/executor/ir/core/src/plan/physical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ impl AsPhysical for pb::PathExpand {
// 1. the previous op is ExpandE, and with no alias (which means that the edges won't be accessed later).
// 2. `GetV` is GetV(Adj) (i.e., opt=Start/End/Other) without any filters or further query semantics.
// 3. the direction should be: outE + inV = out; inE + outV = in; and bothE + otherV = both
// In addition, if PathExpand + GetV, make opt of GetV to be `End`.
fn build_and_try_fuse_get_v(builder: &mut JobBuilder, mut get_v: pb::GetV) -> IrResult<()> {
if get_v.opt == 4 {
return Err(IrError::Unsupported("Try to fuse GetV with Opt=Self into ExpandE".to_string()));
Expand Down Expand Up @@ -352,6 +353,9 @@ fn build_and_try_fuse_get_v(builder: &mut JobBuilder, mut get_v: pb::GetV) -> Ir
return Ok(());
}
}
} else if let physical_pb::physical_opr::operator::OpKind::Path(ref _path) = op_kind {
// make opt of getV after path expand as End.
get_v.opt = unsafe { std::mem::transmute(physical_pb::get_v::VOpt::End) };
}
}
builder.get_v(get_v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use pegasus_common::impl_as_any;
use crate::apis::{read_id, write_id, Details, DynDetails, Element, GraphElement, PropertyValue, ID};
use crate::utils::expr::eval::Context;

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct Edge {
id: ID,
label: Option<LabelId>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use ahash::HashMap;
use dyn_type::{BorrowObject, Object};
pub use edge::Edge;
use ir_common::{LabelId, NameOrId};
pub use path::GraphPath;
pub use path::{GraphPath, VertexOrEdge};
pub use property::{Details, DynDetails, PropKey, PropertyValue};
pub use vertex::Vertex;

Expand Down
Loading

0 comments on commit e9af91a

Please sign in to comment.