Skip to content

Commit

Permalink
fix(interactive): Fix Bugs in Converting Match into Join (#3311)
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?
This PR fixes a bug related to queries like `Match (a) Match
(a)-[]->(b), (b)-[]->(c) Return a, b`, where there are multiple
sentences in the second Match clause, causing issues when converting
such matches into join structures.

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

## Related issue number

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

Fixes
  • Loading branch information
shirly121 authored Oct 26, 2023
1 parent 4d3a83e commit 1942a67
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,12 @@ public GraphBuilder match(RelNode first, Iterable<? extends RelNode> others) {
RelNode input = size() > 0 ? peek() : null;
RelNode match =
GraphLogicalMultiMatch.create(
(GraphOptCluster) cluster,
null,
input,
first,
ImmutableList.copyOf(others));
if (size() > 0) pop();
push(match);
(GraphOptCluster) cluster, null, null, first, ImmutableList.copyOf(others));
if (input == null) {
push(match);
} else {
push(match).join(getJoinRelType(GraphOpt.Match.INNER), getJoinCondition(input, match));
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.alibaba.graphscope.cypher.antlr4.visitor.type.ExprVisitorResult;
import com.alibaba.graphscope.grammar.CypherGSBaseVisitor;
import com.alibaba.graphscope.grammar.CypherGSParser;
import com.google.common.base.Preconditions;

import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rex.RexCall;
Expand Down Expand Up @@ -63,6 +64,8 @@ public GraphBuilder visitOC_Match(CypherGSParser.OC_MatchContext ctx) {
sentences.get(0),
(ctx.OPTIONAL() != null) ? GraphOpt.Match.OPTIONAL : GraphOpt.Match.INNER);
} else if (sentences.size() > 1) {
Preconditions.checkArgument(
ctx.OPTIONAL() == null, "multiple sentences in match should not be optional");
builder.match(sentences.get(0), sentences.subList(1, sentences.size()));
} else {
throw new IllegalArgumentException("sentences in match should not be empty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,39 @@ public void match_19_test() {
+ " _UTF-8'.*marko.*')]], opt=[VERTEX])",
node.explain().trim());
}

@Test
public void match_20_test() {
RelNode node =
Utils.eval(
"Match (a:person)-[]->(b:person) Match (a:person)-[]-(c:person),"
+ " (c:person)-[]->(b:person) Return a, b")
.build();
Assert.assertEquals(
"GraphLogicalProject(a=[a], b=[b], isAppend=[false])\n"
+ " LogicalJoin(condition=[AND(=(a, a), =(b, b))], joinType=[inner])\n"
+ " GraphLogicalSingleMatch(input=[null],"
+ " sentence=[GraphLogicalGetV(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[b], opt=[END])\n"
+ " GraphLogicalExpand(tableConfig=[{isAll=true, tables=[created, knows]}],"
+ " alias=[DEFAULT], opt=[OUT])\n"
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[a], opt=[VERTEX])\n"
+ "], matchOpt=[INNER])\n"
+ " GraphLogicalMultiMatch(input=[null],"
+ " sentences=[{s0=[GraphLogicalGetV(tableConfig=[{isAll=false,"
+ " tables=[person]}], alias=[c], opt=[OTHER])\n"
+ " GraphLogicalExpand(tableConfig=[{isAll=true, tables=[created, knows]}],"
+ " alias=[DEFAULT], opt=[BOTH])\n"
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[a], opt=[VERTEX])\n"
+ "], s1=[GraphLogicalGetV(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[b], opt=[END])\n"
+ " GraphLogicalExpand(tableConfig=[{isAll=true, tables=[created, knows]}],"
+ " alias=[DEFAULT], opt=[OUT])\n"
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[c], opt=[VERTEX])\n"
+ "]}])",
node.explain().trim());
}
}

0 comments on commit 1942a67

Please sign in to comment.