Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GIE Compiler] Add data type of algebra operator output to physical plan #2870

Merged
merged 10 commits into from
Jun 15, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public RelNode visit(GraphLogicalSource source) {
if (source.getAliasId() != AliasInference.DEFAULT_ID) {
checkFfiResult(LIB.setScanAlias(ptrScan, ArgUtils.asAlias(source.getAliasId())));
}
checkFfiResult(
LIB.setScanMeta(
ptrScan,
new FfiPbPointer.ByValue(
com.alibaba.graphscope.common.ir.runtime.proto.Utils.protoRowType(
source.getRowType(), isColumnId)
.get(0)
.toByteArray())));
return new PhysicalNode(source, ptrScan);
}

Expand All @@ -96,6 +104,14 @@ public RelNode visit(GraphLogicalExpand expand) {
if (expand.getAliasId() != AliasInference.DEFAULT_ID) {
checkFfiResult(LIB.setEdgexpdAlias(ptrExpand, ArgUtils.asAlias(expand.getAliasId())));
}
checkFfiResult(
LIB.setEdgexpdMeta(
ptrExpand,
new FfiPbPointer.ByValue(
com.alibaba.graphscope.common.ir.runtime.proto.Utils.protoRowType(
expand.getRowType(), isColumnId)
.get(0)
.toByteArray())));
return new PhysicalNode(expand, ptrExpand);
}

Expand All @@ -106,6 +122,14 @@ public RelNode visit(GraphLogicalGetV getV) {
if (getV.getAliasId() != AliasInference.DEFAULT_ID) {
checkFfiResult(LIB.setGetvAlias(ptrGetV, ArgUtils.asAlias(getV.getAliasId())));
}
checkFfiResult(
LIB.setGetvMeta(
ptrGetV,
new FfiPbPointer.ByValue(
com.alibaba.graphscope.common.ir.runtime.proto.Utils.protoRowType(
getV.getRowType(), isColumnId)
.get(0)
.toByteArray())));
return new PhysicalNode(getV, ptrGetV);
}

Expand Down Expand Up @@ -135,6 +159,15 @@ public RelNode visit(GraphLogicalSingleMatch match) {
Pointer ptrSentence = LIB.initPatternSentence(FfiJoinKind.Inner);
addFfiBinder(ptrSentence, match.getSentence(), true);
checkFfiResult(LIB.addPatternSentence(ptrPattern, ptrSentence));
com.alibaba.graphscope.common.ir.runtime.proto.Utils.protoRowType(
match.getRowType(), isColumnId)
.forEach(
k -> {
checkFfiResult(
LIB.addPatternMeta(
ptrPattern,
new FfiPbPointer.ByValue(k.toByteArray())));
});
return new PhysicalNode(match, ptrPattern);
case OPTIONAL:
case ANTI:
Expand All @@ -151,6 +184,14 @@ public RelNode visit(GraphLogicalMultiMatch match) {
addFfiBinder(ptrSentence, sentence, true);
checkFfiResult(LIB.addPatternSentence(ptrPattern, ptrSentence));
}
com.alibaba.graphscope.common.ir.runtime.proto.Utils.protoRowType(
match.getRowType(), isColumnId)
.forEach(
k -> {
checkFfiResult(
LIB.addPatternMeta(
ptrPattern, new FfiPbPointer.ByValue(k.toByteArray())));
});
return new PhysicalNode(match, ptrPattern);
}

Expand Down Expand Up @@ -183,6 +224,14 @@ public PhysicalNode visit(GraphLogicalProject project) {
new FfiPbPointer.ByValue(expression.toByteArray()),
ffiAlias));
}
com.alibaba.graphscope.common.ir.runtime.proto.Utils.protoRowType(
project.getRowType(), isColumnId)
.forEach(
k -> {
checkFfiResult(
LIB.addProjectMeta(
ptrProject, new FfiPbPointer.ByValue(k.toByteArray())));
});
return new PhysicalNode(project, ptrProject);
}

Expand Down Expand Up @@ -249,6 +298,14 @@ public PhysicalNode visit(GraphLogicalAggregate aggregate) {
ffiAggOpt,
ffiAlias));
}
com.alibaba.graphscope.common.ir.runtime.proto.Utils.protoRowType(
aggregate.getRowType(), isColumnId)
.forEach(
k -> {
checkFfiResult(
LIB.addGroupbyKeyValueMeta(
ptrGroup, new FfiPbPointer.ByValue(k.toByteArray())));
});
return new PhysicalNode(aggregate, ptrGroup);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,18 @@ FfiResult.ByValue appendPatternOperator(
FfiResult.ByValue addParamsExtra(Pointer params, String key, String value);

Pointer initSinkGraphOperator(String graphName);

FfiResult.ByValue setScanMeta(Pointer scan, FfiPbPointer.ByValue meta);

FfiResult.ByValue setEdgexpdMeta(Pointer edgexpd, FfiPbPointer.ByValue meta);

FfiResult.ByValue setGetvMeta(Pointer getV, FfiPbPointer.ByValue meta);

FfiResult.ByValue addProjectMeta(Pointer project, FfiPbPointer.ByValue meta);

FfiResult.ByValue addGroupbyKeyValueMeta(Pointer groupBy, FfiPbPointer.ByValue meta);

FfiResult.ByValue addPatternMeta(Pointer pattern, FfiPbPointer.ByValue meta);

FfiResult.ByValue setUnfoldMeta(Pointer unfold, FfiPbPointer.ByValue meta);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

public class FfiLogicalPlanTest {
// Match (x:person)-[:knows*1..3]->(:person {age: 10})
// Return count(*)
@Test
public void logical_plan_test() throws Exception {
GraphBuilder builder = Utils.mockGraphBuilder();
Expand All @@ -49,7 +50,7 @@ public void logical_plan_test() throws Exception {
.pathOpt(GraphOpt.PathExpandPath.SIMPLE)
.resultOpt(GraphOpt.PathExpandResult.ALL_V)
.build();
RelNode node =
RelNode aggregate =
builder.source(
new SourceConfig(
GraphOpt.Source.VERTEX,
Expand All @@ -62,26 +63,21 @@ public void logical_plan_test() throws Exception {
GraphStdOperatorTable.EQUALS,
pxdBuilder.variable(null, "age"),
pxdBuilder.literal(10)))
.build();
RelNode aggregate =
builder.match(node, GraphOpt.Match.INNER)
.aggregate(builder.groupKey(), builder.count(builder.variable("x")))
.build();
Assert.assertEquals(
"GraphLogicalAggregate(keys=[{variables=[], aliases=[]}], values=[[{operands=[x],"
+ " aggFunction=COUNT, alias='$f0', distinct=false}]])\n"
+ " GraphLogicalSingleMatch(input=[null],"
+ " sentence=[GraphLogicalGetV(tableConfig=[{isAll=false, tables=[person]}],"
+ " GraphLogicalGetV(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[DEFAULT], fusedFilter=[[=(DEFAULT.age, 10)]], opt=[END])\n"
+ " GraphLogicalPathExpand(expand=[GraphLogicalExpand(tableConfig=[{isAll=false,"
+ " GraphLogicalPathExpand(expand=[GraphLogicalExpand(tableConfig=[{isAll=false,"
+ " 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=[ALL_V],"
+ " alias=[DEFAULT])\n"
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[x], opt=[VERTEX])\n"
+ "], matchOpt=[INNER])",
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[person]}],"
+ " alias=[x], opt=[VERTEX])",
aggregate.explain().trim());
try (PhysicalBuilder<byte[]> ffiBuilder =
new FfiPhysicalBuilder(
Expand Down
Loading
Loading