Skip to content

Commit 0c3d19e

Browse files
authored
fix(interactive): Fix Bugs of Type Inference in Collect(labels(n)) (#4398)
<!-- Thanks for your contribution! please review https://github.com/alibaba/GraphScope/blob/main/CONTRIBUTING.md before opening an issue. --> ## What do these changes do? <!-- 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 #4388
1 parent 06d254c commit 0c3d19e

File tree

3 files changed

+130
-12
lines changed

3 files changed

+130
-12
lines changed

interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/Utils.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,14 @@ public static final Common.DataType protoBasicDataType(RelDataType basicType) {
296296
case MULTISET:
297297
case ARRAY:
298298
RelDataType elementType = basicType.getComponentType();
299-
switch (elementType.getSqlTypeName()) {
300-
case INTEGER:
299+
Common.DataType dataType = protoBasicDataType(elementType);
300+
switch (dataType) {
301+
case INT32:
301302
return Common.DataType.INT32_ARRAY;
302-
case BIGINT:
303+
case INT64:
303304
return Common.DataType.INT64_ARRAY;
304-
case CHAR:
305+
case STRING:
305306
return Common.DataType.STRING_ARRAY;
306-
case DECIMAL:
307-
case FLOAT:
308307
case DOUBLE:
309308
return Common.DataType.DOUBLE_ARRAY;
310309
default:

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@
2727
import com.alibaba.graphscope.common.ir.tools.GraphBuilder;
2828
import com.alibaba.graphscope.common.ir.tools.GraphStdOperatorTable;
2929
import com.alibaba.graphscope.common.ir.tools.LogicalPlan;
30-
import com.alibaba.graphscope.common.ir.tools.config.ExpandConfig;
31-
import com.alibaba.graphscope.common.ir.tools.config.GetVConfig;
32-
import com.alibaba.graphscope.common.ir.tools.config.GraphOpt;
33-
import com.alibaba.graphscope.common.ir.tools.config.LabelConfig;
34-
import com.alibaba.graphscope.common.ir.tools.config.PathExpandConfig;
35-
import com.alibaba.graphscope.common.ir.tools.config.SourceConfig;
30+
import com.alibaba.graphscope.common.ir.tools.config.*;
3631
import com.alibaba.graphscope.common.utils.FileUtils;
3732
import com.google.common.collect.ImmutableList;
3833
import com.google.common.collect.ImmutableMap;
@@ -1237,6 +1232,24 @@ public void intersect_test_02() throws Exception {
12371232
}
12381233
}
12391234

1235+
@Test
1236+
public void collect_labels_test() {
1237+
Configs configs = getMockCBOConfig();
1238+
GraphRelOptimizer optimizer = new GraphRelOptimizer(configs);
1239+
IrMeta irMeta = getMockCBOMeta(optimizer);
1240+
GraphBuilder builder = Utils.mockGraphBuilder(optimizer, irMeta);
1241+
RelNode before =
1242+
com.alibaba.graphscope.cypher.antlr4.Utils.eval(
1243+
"Match (n:PERSON) Return collect(labels(n));", builder)
1244+
.build();
1245+
RelNode after = optimizer.optimize(before, new GraphIOProcessor(builder, irMeta));
1246+
PhysicalBuilder protoBuilder =
1247+
new GraphRelProtoPhysicalBuilder(configs, irMeta, new LogicalPlan(after));
1248+
Assert.assertEquals(
1249+
FileUtils.readJsonFromResource("proto/collect_labels.json"),
1250+
protoBuilder.build().explain().trim());
1251+
}
1252+
12401253
private Configs getMockCBOConfig() {
12411254
return new Configs(
12421255
ImmutableMap.of(
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"plan": [{
3+
"opr": {
4+
"scan": {
5+
"alias": 0,
6+
"params": {
7+
"tables": [{
8+
"id": 1
9+
}],
10+
"sampleRatio": 1.0
11+
}
12+
}
13+
},
14+
"metaData": [{
15+
"type": {
16+
"graphType": {
17+
"graphDataType": [{
18+
"label": {
19+
"label": 1
20+
},
21+
"props": [{
22+
"propId": {
23+
"name": "id"
24+
},
25+
"type": "INT64"
26+
}, {
27+
"propId": {
28+
"name": "firstName"
29+
},
30+
"type": "STRING"
31+
}, {
32+
"propId": {
33+
"name": "lastName"
34+
},
35+
"type": "STRING"
36+
}, {
37+
"propId": {
38+
"name": "gender"
39+
},
40+
"type": "STRING"
41+
}, {
42+
"propId": {
43+
"name": "birthday"
44+
},
45+
"type": "INT64"
46+
}, {
47+
"propId": {
48+
"name": "creationDate"
49+
},
50+
"type": "DATE32"
51+
}, {
52+
"propId": {
53+
"name": "locationIP"
54+
},
55+
"type": "STRING"
56+
}, {
57+
"propId": {
58+
"name": "browserUsed"
59+
},
60+
"type": "STRING"
61+
}]
62+
}]
63+
}
64+
}
65+
}]
66+
}, {
67+
"opr": {
68+
"groupBy": {
69+
"functions": [{
70+
"vars": [{
71+
"tag": {
72+
"id": 0
73+
},
74+
"property": {
75+
"label": {
76+
}
77+
},
78+
"nodeType": {
79+
"dataType": "INT32"
80+
}
81+
}],
82+
"aggregate": "TO_LIST",
83+
"alias": 1
84+
}]
85+
}
86+
},
87+
"metaData": [{
88+
"type": {
89+
"dataType": "INT32_ARRAY"
90+
},
91+
"alias": 1
92+
}]
93+
}, {
94+
"opr": {
95+
"sink": {
96+
"tags": [{
97+
"tag": 1
98+
}],
99+
"sinkTarget": {
100+
"sinkDefault": {
101+
}
102+
}
103+
}
104+
}
105+
}]
106+
}

0 commit comments

Comments
 (0)