Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglei1949 authored Aug 14, 2024
2 parents 0ffc63a + 11a2b63 commit 206a4b9
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeField;
import org.apache.calcite.rex.RexLiteral;
import org.apache.calcite.rex.RexNode;
import org.apache.commons.lang3.ObjectUtils;
Expand Down Expand Up @@ -700,7 +701,10 @@ private GraphSchemaType createSchemaType(
boolean isNullable = originalType == null ? false : originalType.isNullable();
if (newLabels.size() == 1) {
return new GraphSchemaType(
opt, new GraphLabelType(newLabels), ImmutableList.of(), isNullable);
opt,
new GraphLabelType(newLabels),
getOriginalFields(newLabels.get(0), originalType),
isNullable);
} else {
List<GraphSchemaType> fuzzyTypes =
newLabels.stream()
Expand All @@ -709,12 +713,24 @@ private GraphSchemaType createSchemaType(
new GraphSchemaType(
opt,
new GraphLabelType(ImmutableList.of(k)),
ImmutableList.of()))
getOriginalFields(k, originalType)))
.collect(Collectors.toList());
return GraphSchemaType.create(fuzzyTypes, builder.getTypeFactory(), isNullable);
}
}

private List<RelDataTypeField> getOriginalFields(
GraphLabelType.Entry labelEntry, @Nullable GraphSchemaType originalType) {
if (originalType == null) return ImmutableList.of();
List<GraphSchemaType> candidates = originalType.getSchemaTypeAsList();
for (GraphSchemaType candidate : candidates) {
if (candidate.getLabelType().getLabelsEntry().contains(labelEntry)) {
return candidate.getFieldList();
}
}
return ImmutableList.of();
}

private class RelGraph {
private final Map<String, List<RelNode>> aliasNameToRels;
private final List<RelNode> rels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.alibaba.graphscope.common.config.Configs;
import com.alibaba.graphscope.common.config.FrontendConfig;
import com.alibaba.graphscope.common.ir.rel.graph.GraphLogicalSource;
import com.alibaba.graphscope.common.ir.tools.GraphBuilder;
import com.alibaba.graphscope.common.ir.tools.LogicalPlan;
import com.google.common.collect.ImmutableMap;

Expand Down Expand Up @@ -504,4 +505,21 @@ public void match_24_test() {
+ "], matchOpt=[INNER])",
node.explain().trim());
}

@Test
public void property_exist_after_type_inference_test() {
GraphBuilder builder =
com.alibaba.graphscope.common.ir.Utils.mockGraphBuilder(
"schema/ldbc_schema_exp_hierarchy.json");
// check property 'creationDate' still exists after type inference has updated the type of
// 'HASCREATOR'
RelNode rel =
com.alibaba.graphscope.cypher.antlr4.Utils.eval(
"Match (a:PERSON)<-[h:HASCREATOR]-(b:COMMENT) Return h;", builder)
.build();
Assert.assertEquals(
"RecordType(Graph_Schema_Type(labels=[EdgeLabel(HASCREATOR, COMMENT, PERSON)],"
+ " properties=[BIGINT creationDate]) h)",
rel.getRowType().toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,24 @@
"label": {
"srcLabel": 2,
"dstLabel": 1
}
},
"props": [{
"propId": {
"name": "creationDate"
},
"type": "INT64"
}]
}, {
"label": {
"srcLabel": 3,
"dstLabel": 1
}
},
"props": [{
"propId": {
"name": "creationDate"
},
"type": "INT64"
}]
}]
}
},
Expand Down Expand Up @@ -250,4 +262,4 @@
}
}
}]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
"tables": [{
"id": 0
}],
"columns": [{
"name": "creationDate"
}],
"sampleRatio": 1.0
},
"alias": 1,
Expand All @@ -87,12 +90,24 @@
"label": {
"srcLabel": 2,
"dstLabel": 1
}
},
"props": [{
"propId": {
"name": "creationDate"
},
"type": "INT64"
}]
}, {
"label": {
"srcLabel": 3,
"dstLabel": 1
}
},
"props": [{
"propId": {
"name": "creationDate"
},
"type": "INT64"
}]
}]
}
},
Expand Down Expand Up @@ -436,4 +451,4 @@
}
}
}]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,24 @@
"label": {
"srcLabel": 2,
"dstLabel": 1
}
},
"props": [{
"propId": {
"name": "creationDate"
},
"type": "INT64"
}]
}, {
"label": {
"srcLabel": 3,
"dstLabel": 1
}
},
"props": [{
"propId": {
"name": "creationDate"
},
"type": "INT64"
}]
}]
}
},
Expand Down Expand Up @@ -274,4 +286,4 @@
}
}
}]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
"tables": [{
"id": 0
}],
"columns": [{
"name": "creationDate"
}],
"sampleRatio": 1.0
},
"alias": 1,
Expand All @@ -95,12 +98,24 @@
"label": {
"srcLabel": 2,
"dstLabel": 1
}
},
"props": [{
"propId": {
"name": "creationDate"
},
"type": "INT64"
}]
}, {
"label": {
"srcLabel": 3,
"dstLabel": 1
}
},
"props": [{
"propId": {
"name": "creationDate"
},
"type": "INT64"
}]
}]
}
},
Expand Down Expand Up @@ -460,4 +475,4 @@
}
}
}]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,16 @@
}
}
],
"columns": []
"columns": [
{
"key": {
"id": 2,
"name": "creationDate"
},
"data_type": 2,
"is_primary_key": false
}
]
},
{
"label": {
Expand Down

0 comments on commit 206a4b9

Please sign in to comment.