Skip to content

Commit

Permalink
fix(interactive): Fix Bugs of Type Inference in Collect(labels(n)) (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
shirly121 authored Jan 2, 2025
1 parent 06d254c commit 0c3d19e
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,14 @@ public static final Common.DataType protoBasicDataType(RelDataType basicType) {
case MULTISET:
case ARRAY:
RelDataType elementType = basicType.getComponentType();
switch (elementType.getSqlTypeName()) {
case INTEGER:
Common.DataType dataType = protoBasicDataType(elementType);
switch (dataType) {
case INT32:
return Common.DataType.INT32_ARRAY;
case BIGINT:
case INT64:
return Common.DataType.INT64_ARRAY;
case CHAR:
case STRING:
return Common.DataType.STRING_ARRAY;
case DECIMAL:
case FLOAT:
case DOUBLE:
return Common.DataType.DOUBLE_ARRAY;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@
import com.alibaba.graphscope.common.ir.tools.GraphBuilder;
import com.alibaba.graphscope.common.ir.tools.GraphStdOperatorTable;
import com.alibaba.graphscope.common.ir.tools.LogicalPlan;
import com.alibaba.graphscope.common.ir.tools.config.ExpandConfig;
import com.alibaba.graphscope.common.ir.tools.config.GetVConfig;
import com.alibaba.graphscope.common.ir.tools.config.GraphOpt;
import com.alibaba.graphscope.common.ir.tools.config.LabelConfig;
import com.alibaba.graphscope.common.ir.tools.config.PathExpandConfig;
import com.alibaba.graphscope.common.ir.tools.config.SourceConfig;
import com.alibaba.graphscope.common.ir.tools.config.*;
import com.alibaba.graphscope.common.utils.FileUtils;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -1237,6 +1232,24 @@ public void intersect_test_02() throws Exception {
}
}

@Test
public void collect_labels_test() {
Configs configs = getMockCBOConfig();
GraphRelOptimizer optimizer = new GraphRelOptimizer(configs);
IrMeta irMeta = getMockCBOMeta(optimizer);
GraphBuilder builder = Utils.mockGraphBuilder(optimizer, irMeta);
RelNode before =
com.alibaba.graphscope.cypher.antlr4.Utils.eval(
"Match (n:PERSON) Return collect(labels(n));", builder)
.build();
RelNode after = optimizer.optimize(before, new GraphIOProcessor(builder, irMeta));
PhysicalBuilder protoBuilder =
new GraphRelProtoPhysicalBuilder(configs, irMeta, new LogicalPlan(after));
Assert.assertEquals(
FileUtils.readJsonFromResource("proto/collect_labels.json"),
protoBuilder.build().explain().trim());
}

private Configs getMockCBOConfig() {
return new Configs(
ImmutableMap.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"plan": [{
"opr": {
"scan": {
"alias": 0,
"params": {
"tables": [{
"id": 1
}],
"sampleRatio": 1.0
}
}
},
"metaData": [{
"type": {
"graphType": {
"graphDataType": [{
"label": {
"label": 1
},
"props": [{
"propId": {
"name": "id"
},
"type": "INT64"
}, {
"propId": {
"name": "firstName"
},
"type": "STRING"
}, {
"propId": {
"name": "lastName"
},
"type": "STRING"
}, {
"propId": {
"name": "gender"
},
"type": "STRING"
}, {
"propId": {
"name": "birthday"
},
"type": "INT64"
}, {
"propId": {
"name": "creationDate"
},
"type": "DATE32"
}, {
"propId": {
"name": "locationIP"
},
"type": "STRING"
}, {
"propId": {
"name": "browserUsed"
},
"type": "STRING"
}]
}]
}
}
}]
}, {
"opr": {
"groupBy": {
"functions": [{
"vars": [{
"tag": {
"id": 0
},
"property": {
"label": {
}
},
"nodeType": {
"dataType": "INT32"
}
}],
"aggregate": "TO_LIST",
"alias": 1
}]
}
},
"metaData": [{
"type": {
"dataType": "INT32_ARRAY"
},
"alias": 1
}]
}, {
"opr": {
"sink": {
"tags": [{
"tag": 1
}],
"sinkTarget": {
"sinkDefault": {
}
}
}
}
}]
}

0 comments on commit 0c3d19e

Please sign in to comment.