Skip to content

Commit b37ab90

Browse files
shirly121longbinlaisiyuan0322
authored
[GIE Compiler] Add data type of algebra operator output to physical plan (#2870)
Co-authored-by: Longbin Lai <[email protected]> Co-authored-by: siyuan0322 <[email protected]>
1 parent 79cd577 commit b37ab90

File tree

5 files changed

+332
-129
lines changed

5 files changed

+332
-129
lines changed

interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/ffi/RelToFfiConverter.java

+57
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ public RelNode visit(GraphLogicalSource source) {
8585
if (source.getAliasId() != AliasInference.DEFAULT_ID) {
8686
checkFfiResult(LIB.setScanAlias(ptrScan, ArgUtils.asAlias(source.getAliasId())));
8787
}
88+
checkFfiResult(
89+
LIB.setScanMeta(
90+
ptrScan,
91+
new FfiPbPointer.ByValue(
92+
com.alibaba.graphscope.common.ir.runtime.proto.Utils.protoRowType(
93+
source.getRowType(), isColumnId)
94+
.get(0)
95+
.toByteArray())));
8896
return new PhysicalNode(source, ptrScan);
8997
}
9098

@@ -96,6 +104,14 @@ public RelNode visit(GraphLogicalExpand expand) {
96104
if (expand.getAliasId() != AliasInference.DEFAULT_ID) {
97105
checkFfiResult(LIB.setEdgexpdAlias(ptrExpand, ArgUtils.asAlias(expand.getAliasId())));
98106
}
107+
checkFfiResult(
108+
LIB.setEdgexpdMeta(
109+
ptrExpand,
110+
new FfiPbPointer.ByValue(
111+
com.alibaba.graphscope.common.ir.runtime.proto.Utils.protoRowType(
112+
expand.getRowType(), isColumnId)
113+
.get(0)
114+
.toByteArray())));
99115
return new PhysicalNode(expand, ptrExpand);
100116
}
101117

@@ -106,6 +122,14 @@ public RelNode visit(GraphLogicalGetV getV) {
106122
if (getV.getAliasId() != AliasInference.DEFAULT_ID) {
107123
checkFfiResult(LIB.setGetvAlias(ptrGetV, ArgUtils.asAlias(getV.getAliasId())));
108124
}
125+
checkFfiResult(
126+
LIB.setGetvMeta(
127+
ptrGetV,
128+
new FfiPbPointer.ByValue(
129+
com.alibaba.graphscope.common.ir.runtime.proto.Utils.protoRowType(
130+
getV.getRowType(), isColumnId)
131+
.get(0)
132+
.toByteArray())));
109133
return new PhysicalNode(getV, ptrGetV);
110134
}
111135

@@ -135,6 +159,15 @@ public RelNode visit(GraphLogicalSingleMatch match) {
135159
Pointer ptrSentence = LIB.initPatternSentence(FfiJoinKind.Inner);
136160
addFfiBinder(ptrSentence, match.getSentence(), true);
137161
checkFfiResult(LIB.addPatternSentence(ptrPattern, ptrSentence));
162+
com.alibaba.graphscope.common.ir.runtime.proto.Utils.protoRowType(
163+
match.getRowType(), isColumnId)
164+
.forEach(
165+
k -> {
166+
checkFfiResult(
167+
LIB.addPatternMeta(
168+
ptrPattern,
169+
new FfiPbPointer.ByValue(k.toByteArray())));
170+
});
138171
return new PhysicalNode(match, ptrPattern);
139172
case OPTIONAL:
140173
case ANTI:
@@ -151,6 +184,14 @@ public RelNode visit(GraphLogicalMultiMatch match) {
151184
addFfiBinder(ptrSentence, sentence, true);
152185
checkFfiResult(LIB.addPatternSentence(ptrPattern, ptrSentence));
153186
}
187+
com.alibaba.graphscope.common.ir.runtime.proto.Utils.protoRowType(
188+
match.getRowType(), isColumnId)
189+
.forEach(
190+
k -> {
191+
checkFfiResult(
192+
LIB.addPatternMeta(
193+
ptrPattern, new FfiPbPointer.ByValue(k.toByteArray())));
194+
});
154195
return new PhysicalNode(match, ptrPattern);
155196
}
156197

@@ -183,6 +224,14 @@ public PhysicalNode visit(GraphLogicalProject project) {
183224
new FfiPbPointer.ByValue(expression.toByteArray()),
184225
ffiAlias));
185226
}
227+
com.alibaba.graphscope.common.ir.runtime.proto.Utils.protoRowType(
228+
project.getRowType(), isColumnId)
229+
.forEach(
230+
k -> {
231+
checkFfiResult(
232+
LIB.addProjectMeta(
233+
ptrProject, new FfiPbPointer.ByValue(k.toByteArray())));
234+
});
186235
return new PhysicalNode(project, ptrProject);
187236
}
188237

@@ -249,6 +298,14 @@ public PhysicalNode visit(GraphLogicalAggregate aggregate) {
249298
ffiAggOpt,
250299
ffiAlias));
251300
}
301+
com.alibaba.graphscope.common.ir.runtime.proto.Utils.protoRowType(
302+
aggregate.getRowType(), isColumnId)
303+
.forEach(
304+
k -> {
305+
checkFfiResult(
306+
LIB.addGroupbyKeyValueMeta(
307+
ptrGroup, new FfiPbPointer.ByValue(k.toByteArray())));
308+
});
252309
return new PhysicalNode(aggregate, ptrGroup);
253310
}
254311

interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/jna/IrCoreLibrary.java

+14
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,18 @@ FfiResult.ByValue appendPatternOperator(
229229
FfiResult.ByValue addParamsExtra(Pointer params, String key, String value);
230230

231231
Pointer initSinkGraphOperator(String graphName);
232+
233+
FfiResult.ByValue setScanMeta(Pointer scan, FfiPbPointer.ByValue meta);
234+
235+
FfiResult.ByValue setEdgexpdMeta(Pointer edgexpd, FfiPbPointer.ByValue meta);
236+
237+
FfiResult.ByValue setGetvMeta(Pointer getV, FfiPbPointer.ByValue meta);
238+
239+
FfiResult.ByValue addProjectMeta(Pointer project, FfiPbPointer.ByValue meta);
240+
241+
FfiResult.ByValue addGroupbyKeyValueMeta(Pointer groupBy, FfiPbPointer.ByValue meta);
242+
243+
FfiResult.ByValue addPatternMeta(Pointer pattern, FfiPbPointer.ByValue meta);
244+
245+
FfiResult.ByValue setUnfoldMeta(Pointer unfold, FfiPbPointer.ByValue meta);
232246
}

interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/runtime/FfiLogicalPlanTest.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
public class FfiLogicalPlanTest {
3535
// Match (x:person)-[:knows*1..3]->(:person {age: 10})
36+
// Return count(*)
3637
@Test
3738
public void logical_plan_1_test() throws Exception {
3839
GraphBuilder builder = Utils.mockGraphBuilder();
@@ -50,7 +51,7 @@ public void logical_plan_1_test() throws Exception {
5051
.pathOpt(GraphOpt.PathExpandPath.SIMPLE)
5152
.resultOpt(GraphOpt.PathExpandResult.ALL_V)
5253
.build();
53-
RelNode node =
54+
RelNode aggregate =
5455
builder.source(
5556
new SourceConfig(
5657
GraphOpt.Source.VERTEX,
@@ -63,26 +64,21 @@ public void logical_plan_1_test() throws Exception {
6364
GraphStdOperatorTable.EQUALS,
6465
pxdBuilder.variable(null, "age"),
6566
pxdBuilder.literal(10)))
66-
.build();
67-
RelNode aggregate =
68-
builder.match(node, GraphOpt.Match.INNER)
6967
.aggregate(builder.groupKey(), builder.count(builder.variable("x")))
7068
.build();
7169
Assert.assertEquals(
7270
"GraphLogicalAggregate(keys=[{variables=[], aliases=[]}], values=[[{operands=[x],"
7371
+ " aggFunction=COUNT, alias='$f0', distinct=false}]])\n"
74-
+ " GraphLogicalSingleMatch(input=[null],"
75-
+ " sentence=[GraphLogicalGetV(tableConfig=[{isAll=false, tables=[person]}],"
72+
+ " GraphLogicalGetV(tableConfig=[{isAll=false, tables=[person]}],"
7673
+ " alias=[DEFAULT], fusedFilter=[[=(DEFAULT.age, 10)]], opt=[END])\n"
77-
+ " GraphLogicalPathExpand(expand=[GraphLogicalExpand(tableConfig=[{isAll=false,"
74+
+ " GraphLogicalPathExpand(expand=[GraphLogicalExpand(tableConfig=[{isAll=false,"
7875
+ " tables=[knows]}], alias=[DEFAULT], opt=[OUT])\n"
7976
+ "], getV=[GraphLogicalGetV(tableConfig=[{isAll=false, tables=[person]}],"
8077
+ " alias=[DEFAULT], opt=[END])\n"
8178
+ "], offset=[1], fetch=[3], path_opt=[SIMPLE], result_opt=[ALL_V],"
8279
+ " alias=[DEFAULT])\n"
83-
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[person]}],"
84-
+ " alias=[x], opt=[VERTEX])\n"
85-
+ "], matchOpt=[INNER])",
80+
+ " GraphLogicalSource(tableConfig=[{isAll=false, tables=[person]}],"
81+
+ " alias=[x], opt=[VERTEX])",
8682
aggregate.explain().trim());
8783
try (PhysicalBuilder<byte[]> ffiBuilder =
8884
new FfiPhysicalBuilder(

0 commit comments

Comments
 (0)