Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
lidongze0629 committed Jun 6, 2024
2 parents c7b33d2 + c2e35fd commit a757e13
Show file tree
Hide file tree
Showing 20 changed files with 227 additions and 114 deletions.
1 change: 1 addition & 0 deletions interactive_engine/compiler/src/main/antlr4/GremlinGS.g4
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ traversalMethod_bothE
traversalMethod_with
: 'with' LPAREN StringLiteral COMMA oC_Literal RPAREN
| 'with' LPAREN evaluationTimeoutKey COMMA evaluationTimeoutValue RPAREN
| 'with' LPAREN StringLiteral COMMA (ANON_TRAVERSAL_ROOT DOT)? traversalMethod_expr RPAREN // to support path until condition in gremlin-calcite, i.e. with('UNTIL', expr(_.age > 20))
;

evaluationTimeoutKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ public TrimResult trimFields(GraphLogicalPathExpand pathExpand, UsedFields field
pathExpand.getFetch(),
pathExpand.getResultOpt(),
pathExpand.getPathOpt(),
pathExpand.getUntilCondition(),
pathExpand.getAliasName(),
pathExpand.getStartAlias());
return result(newPathExpand, mapping, pathExpand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ public void visit(RelNode node, int ordinal, @Nullable RelNode parent) {
parent instanceof GraphLogicalGetV,
"there should be a getV operator after path expand since"
+ " edge in patten should have two endpoints");
Preconditions.checkArgument(
((GraphLogicalPathExpand) node).getUntilCondition() == null,
"cannot apply optimization if path expand has until"
+ " conditions");
PatternVertex vertex = visitAndAddVertex((GraphLogicalGetV) parent);
visitAndAddPxdEdge(
(GraphLogicalPathExpand) node, lastVisited, vertex);
Expand Down Expand Up @@ -809,7 +813,8 @@ private RelNode createExpandGetV(
edge.getElementDetails().getRange().getOffset(),
edge.getElementDetails().getRange().getFetch());
GraphLogicalPathExpand pxd =
(GraphLogicalPathExpand) builder.pathExpand(pxdBuilder.build()).build();
(GraphLogicalPathExpand)
builder.pathExpand(pxdBuilder.buildConfig()).build();
GraphLogicalExpand expand = (GraphLogicalExpand) pxd.getExpand();
GraphSchemaType edgeType =
(GraphSchemaType) expand.getRowType().getFieldList().get(0).getType();
Expand Down Expand Up @@ -858,6 +863,7 @@ private GraphLogicalPathExpand createPathExpandWithOptional(
pxd.getFetch(),
pxd.getResultOpt(),
pxd.getPathOpt(),
pxd.getUntilCondition(),
pxd.getAliasName(),
pxd.getStartAlias(),
optional);
Expand All @@ -872,6 +878,7 @@ private GraphLogicalPathExpand createPathExpandWithOptional(
pxd.getFetch(),
pxd.getResultOpt(),
pxd.getPathOpt(),
pxd.getUntilCondition(),
pxd.getAliasName(),
pxd.getStartAlias(),
optional);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ public void onMatch(RelOptRuleCall call) {
pathExpand.getFetch(),
pathExpand.getResultOpt(),
pathExpand.getPathOpt(),
pathExpand.getUntilCondition(),
pathExpand.getAliasName(),
pathExpand.getStartAlias(),
pathExpand.isOptional());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class GraphLogicalPathExpand extends SingleRel {

private final boolean optional;

private final @Nullable RexNode untilCondition;

protected GraphLogicalPathExpand(
GraphOptCluster cluster,
@Nullable List<RelHint> hints,
Expand All @@ -73,6 +75,7 @@ protected GraphLogicalPathExpand(
@Nullable RexNode fetch,
GraphOpt.PathExpandResult resultOpt,
GraphOpt.PathExpandPath pathOpt,
@Nullable RexNode untilCondition,
@Nullable String aliasName,
AliasNameWithId startAlias,
boolean optional) {
Expand All @@ -97,6 +100,7 @@ protected GraphLogicalPathExpand(
(this.aliasId == AliasInference.DEFAULT_ID)
? resultOpt
: GraphOpt.PathExpandResult.ALL_V_E;
this.untilCondition = untilCondition;
}

protected GraphLogicalPathExpand(
Expand All @@ -108,6 +112,7 @@ protected GraphLogicalPathExpand(
@Nullable RexNode fetch,
GraphOpt.PathExpandResult resultOpt,
GraphOpt.PathExpandPath pathOpt,
@Nullable RexNode untilCondition,
@Nullable String aliasName,
AliasNameWithId startAlias,
boolean optional) {
Expand All @@ -125,6 +130,7 @@ protected GraphLogicalPathExpand(
this.aliasId = cluster.getIdGenerator().generate(this.aliasName);
this.startAlias = Objects.requireNonNull(startAlias);
this.optional = optional;
this.untilCondition = untilCondition;
}

public static GraphLogicalPathExpand create(
Expand All @@ -137,6 +143,7 @@ public static GraphLogicalPathExpand create(
@Nullable RexNode fetch,
GraphOpt.PathExpandResult resultOpt,
GraphOpt.PathExpandPath pathOpt,
@Nullable RexNode untilCondition,
String aliasName,
AliasNameWithId startAlias,
boolean optional) {
Expand All @@ -150,6 +157,7 @@ public static GraphLogicalPathExpand create(
fetch,
resultOpt,
pathOpt,
untilCondition,
aliasName,
startAlias,
optional);
Expand All @@ -165,6 +173,7 @@ public static GraphLogicalPathExpand create(
@Nullable RexNode fetch,
GraphOpt.PathExpandResult resultOpt,
GraphOpt.PathExpandPath pathOpt,
@Nullable RexNode untilCondition,
String aliasName,
AliasNameWithId startAlias) {
return create(
Expand All @@ -177,6 +186,7 @@ public static GraphLogicalPathExpand create(
fetch,
resultOpt,
pathOpt,
untilCondition,
aliasName,
startAlias,
false);
Expand All @@ -191,6 +201,7 @@ public static GraphLogicalPathExpand create(
@Nullable RexNode fetch,
GraphOpt.PathExpandResult resultOpt,
GraphOpt.PathExpandPath pathOpt,
@Nullable RexNode untilCondition,
String aliasName,
AliasNameWithId startAlias) {
return create(
Expand All @@ -202,6 +213,7 @@ public static GraphLogicalPathExpand create(
fetch,
resultOpt,
pathOpt,
untilCondition,
aliasName,
startAlias,
false);
Expand All @@ -216,6 +228,7 @@ public static GraphLogicalPathExpand create(
@Nullable RexNode fetch,
GraphOpt.PathExpandResult resultOpt,
GraphOpt.PathExpandPath pathOpt,
@Nullable RexNode untilCondition,
String aliasName,
AliasNameWithId startAlias,
boolean optional) {
Expand All @@ -231,6 +244,7 @@ public static GraphLogicalPathExpand create(
fetch,
resultOpt,
pathOpt,
untilCondition,
aliasName,
startAlias,
optional);
Expand All @@ -246,6 +260,7 @@ public RelWriter explainTerms(RelWriter pw) {
.itemIf("fetch", fetch, fetch != null)
.item("path_opt", getPathOpt())
.item("result_opt", getResultOpt())
.itemIf("until_condition", untilCondition, untilCondition != null)
.item("alias", AliasInference.SIMPLE_NAME(getAliasName()))
.itemIf(
"aliasId",
Expand Down Expand Up @@ -306,6 +321,10 @@ public boolean isOptional() {
return optional;
}

public @Nullable RexNode getUntilCondition() {
return untilCondition;
}

@Override
protected RelDataType deriveRowType() {
return new RelRecordType(
Expand Down Expand Up @@ -352,6 +371,7 @@ public GraphLogicalPathExpand copy(RelTraitSet traitSet, List<RelNode> inputs) {
getFetch(),
getResultOpt(),
getPathOpt(),
getUntilCondition(),
getAliasName(),
getStartAlias(),
isOptional());
Expand All @@ -366,6 +386,7 @@ public GraphLogicalPathExpand copy(RelTraitSet traitSet, List<RelNode> inputs) {
getFetch(),
getResultOpt(),
getPathOpt(),
getUntilCondition(),
getAliasName(),
getStartAlias(),
isOptional());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ public RelNode visit(GraphLogicalPathExpand pxd) {
pathExpandBuilder.setResultOpt(Utils.protoPathResultOpt(pxd.getResultOpt()));
GraphAlgebra.Range range = buildRange(pxd.getOffset(), pxd.getFetch());
pathExpandBuilder.setHopRange(range);
if (pxd.getUntilCondition() != null) {
OuterExpression.Expression untilCondition =
pxd.getUntilCondition()
.accept(new RexToProtoConverter(true, isColumnId, this.rexBuilder));
pathExpandBuilder.setCondition(untilCondition);
}
if (pxd.getAliasId() != AliasInference.DEFAULT_ID) {
pathExpandBuilder.setAlias(Utils.asAliasId(pxd.getAliasId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public GraphBuilder pathExpand(PathExpandConfig pxdConfig) {
fetchNode,
pxdConfig.getResultOpt(),
pxdConfig.getPathOpt(),
pxdConfig.getUntilCondition(),
pxdConfig.getAlias(),
getAliasNameWithId(
pxdConfig.getStartAlias(),
Expand Down Expand Up @@ -1817,7 +1818,7 @@ public GraphBuilder as(String alias) {
fetch == null ? -1 : ((RexLiteral) fetch).getValueAs(Integer.class))
.startAlias(pxdExpand.getStartAlias().getAliasName())
.alias(alias);
pathExpand(pxdBuilder.build());
pathExpand(pxdBuilder.buildConfig());
} else if (top instanceof GraphLogicalProject) {
GraphLogicalProject project = (GraphLogicalProject) top;
project(project.getProjects(), Lists.newArrayList(alias), project.isAppend());
Expand Down
Loading

0 comments on commit a757e13

Please sign in to comment.