Skip to content

Commit

Permalink
fix(interactive): Fix Bugs of Type Inference in both() (#4199)
Browse files Browse the repository at this point in the history
  • Loading branch information
shirly121 authored Sep 10, 2024
1 parent 9267d74 commit 1e3573f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,16 @@ private void checkPattern(Pattern pattern) {
});
if (edge.getElementDetails().getRange() == null) {
Preconditions.checkArgument(
Sets.newHashSet(src.getVertexTypeIds()).equals(expectedSrcIds),
!edge.isBoth()
? Sets.newHashSet(src.getVertexTypeIds()).equals(expectedSrcIds)
: expectedSrcIds.containsAll(src.getVertexTypeIds()),
"src vertex types %s not consistent with edge types %s",
src.getVertexTypeIds(),
edge.getEdgeTypeIds());
Preconditions.checkArgument(
Sets.newHashSet(dst.getVertexTypeIds()).equals(expectedDstIds),
!edge.isBoth()
? Sets.newHashSet(dst.getVertexTypeIds()).equals(expectedDstIds)
: expectedDstIds.containsAll(dst.getVertexTypeIds()),
"dst vertex types %s not consistent with edge types %s",
dst.getVertexTypeIds(),
edge.getEdgeTypeIds());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1778,4 +1778,45 @@ public void g_V_path_as_a_select_a_valueMap() {
+ " person]}], alias=[_], opt=[VERTEX])",
rel.explain().trim());
}

@Test
public void g_V_match_as_a_person_both_as_b_test() {
GraphBuilder builder = Utils.mockGraphBuilder(optimizer, irMeta);
RelNode node1 =
eval("g.V().match(as('a').hasLabel('person').both().as('b')).count()", builder);
RelNode after1 = optimizer.optimize(node1, new GraphIOProcessor(builder, irMeta));
Assert.assertEquals(
"GraphLogicalAggregate(keys=[{variables=[], aliases=[]}], values=[[{operands=[a,"
+ " b], aggFunction=COUNT, alias='$f0', distinct=false}]])\n"
+ " GraphPhysicalExpand(tableConfig=[[EdgeLabel(knows, person, person),"
+ " EdgeLabel(created, person, software)]], alias=[b], startAlias=[a],"
+ " opt=[BOTH], physicalOpt=[VERTEX])\n"
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[a], opt=[VERTEX])",
after1.explain().trim());
RelNode node2 =
eval("g.V().match(as('a').hasLabel('software').both().as('b')).count()", builder);
RelNode after2 = optimizer.optimize(node2, new GraphIOProcessor(builder, irMeta));
Assert.assertEquals(
"GraphLogicalAggregate(keys=[{variables=[], aliases=[]}], values=[[{operands=[a,"
+ " b], aggFunction=COUNT, alias='$f0', distinct=false}]])\n"
+ " GraphPhysicalGetV(tableConfig=[{isAll=false, tables=[person]}], alias=[b],"
+ " opt=[OTHER], physicalOpt=[ITSELF])\n"
+ " GraphPhysicalExpand(tableConfig=[{isAll=false, tables=[created]}],"
+ " alias=[_], startAlias=[a], opt=[BOTH], physicalOpt=[VERTEX])\n"
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[software]}],"
+ " alias=[a], opt=[VERTEX])",
after2.explain().trim());
RelNode node3 = eval("g.V().match(as('a').both().as('b')).count()", builder);
RelNode after3 = optimizer.optimize(node3, new GraphIOProcessor(builder, irMeta));
Assert.assertEquals(
"GraphLogicalAggregate(keys=[{variables=[], aliases=[]}], values=[[{operands=[a,"
+ " b], aggFunction=COUNT, alias='$f0', distinct=false}]])\n"
+ " GraphPhysicalExpand(tableConfig=[[EdgeLabel(knows, person, person),"
+ " EdgeLabel(created, person, software)]], alias=[b], startAlias=[a],"
+ " opt=[BOTH], physicalOpt=[VERTEX])\n"
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[software,"
+ " person]}], alias=[a], opt=[VERTEX])",
after3.explain().trim());
}
}

0 comments on commit 1e3573f

Please sign in to comment.