diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/GraphTypeInference.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/GraphTypeInference.java index 5efd51bc12c7..de516330b390 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/GraphTypeInference.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/GraphTypeInference.java @@ -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; @@ -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 fuzzyTypes = newLabels.stream() @@ -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 getOriginalFields( + GraphLabelType.Entry labelEntry, @Nullable GraphSchemaType originalType) { + if (originalType == null) return ImmutableList.of(); + List 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> aliasNameToRels; private final List rels; diff --git a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/antlr4/MatchTest.java b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/antlr4/MatchTest.java index c19d71ab85ea..9fac91413579 100644 --- a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/antlr4/MatchTest.java +++ b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/antlr4/MatchTest.java @@ -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; @@ -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()); + } } diff --git a/interactive_engine/compiler/src/test/resources/proto/intersect_test.json b/interactive_engine/compiler/src/test/resources/proto/intersect_test.json index 5341c37cc6a0..75d2a411c153 100644 --- a/interactive_engine/compiler/src/test/resources/proto/intersect_test.json +++ b/interactive_engine/compiler/src/test/resources/proto/intersect_test.json @@ -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" + }] }] } }, @@ -250,4 +262,4 @@ } } }] -} \ No newline at end of file +} diff --git a/interactive_engine/compiler/src/test/resources/proto/intersect_test_2.json b/interactive_engine/compiler/src/test/resources/proto/intersect_test_2.json index 1ca5b9f307de..95399e202519 100644 --- a/interactive_engine/compiler/src/test/resources/proto/intersect_test_2.json +++ b/interactive_engine/compiler/src/test/resources/proto/intersect_test_2.json @@ -73,6 +73,9 @@ "tables": [{ "id": 0 }], + "columns": [{ + "name": "creationDate" + }], "sampleRatio": 1.0 }, "alias": 1, @@ -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" + }] }] } }, @@ -436,4 +451,4 @@ } } }] -} \ No newline at end of file +} diff --git a/interactive_engine/compiler/src/test/resources/proto/partitioned_intersect_test.json b/interactive_engine/compiler/src/test/resources/proto/partitioned_intersect_test.json index 015570927444..002f573adf14 100644 --- a/interactive_engine/compiler/src/test/resources/proto/partitioned_intersect_test.json +++ b/interactive_engine/compiler/src/test/resources/proto/partitioned_intersect_test.json @@ -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" + }] }] } }, @@ -274,4 +286,4 @@ } } }] -} \ No newline at end of file +} diff --git a/interactive_engine/compiler/src/test/resources/proto/partitioned_intersect_test_2.json b/interactive_engine/compiler/src/test/resources/proto/partitioned_intersect_test_2.json index 50aa41100031..eacf38f51d36 100644 --- a/interactive_engine/compiler/src/test/resources/proto/partitioned_intersect_test_2.json +++ b/interactive_engine/compiler/src/test/resources/proto/partitioned_intersect_test_2.json @@ -81,6 +81,9 @@ "tables": [{ "id": 0 }], + "columns": [{ + "name": "creationDate" + }], "sampleRatio": 1.0 }, "alias": 1, @@ -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" + }] }] } }, @@ -460,4 +475,4 @@ } } }] -} \ No newline at end of file +} diff --git a/interactive_engine/compiler/src/test/resources/schema/ldbc_schema_exp_hierarchy.json b/interactive_engine/compiler/src/test/resources/schema/ldbc_schema_exp_hierarchy.json index 6594af8d51d7..43034a576ee7 100644 --- a/interactive_engine/compiler/src/test/resources/schema/ldbc_schema_exp_hierarchy.json +++ b/interactive_engine/compiler/src/test/resources/schema/ldbc_schema_exp_hierarchy.json @@ -814,7 +814,16 @@ } } ], - "columns": [] + "columns": [ + { + "key": { + "id": 2, + "name": "creationDate" + }, + "data_type": 2, + "is_primary_key": false + } + ] }, { "label": {