Skip to content

Commit a8952a4

Browse files
authored
fix(interactive): Fix Bugs of Mismatch Label in elementMap (#4326)
<!-- Thanks for your contribution! please review https://github.com/alibaba/GraphScope/blob/main/CONTRIBUTING.md before opening an issue. --> ## What do these changes do? as titled. <!-- Please give a short brief about these changes. --> ## Related issue number fix #4252 <!-- Are there any issues opened that will be resolved by merging this change? --> Fixes
1 parent 033590f commit a8952a4

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

โ€Žinteractive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/GraphTypeFactoryImpl.javaโ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,13 @@ public RelDataType createArbitraryMapType(
8686
@Override
8787
public @Nullable RelDataType leastRestrictive(List<RelDataType> types) {
8888
if (types.stream().anyMatch(t -> t instanceof GraphLabelType)) {
89+
// union all labels
90+
List<GraphLabelType.Entry> unionLabels = Lists.newArrayList();
8991
for (RelDataType type : types) {
9092
if (!(type instanceof GraphLabelType)) return null;
93+
unionLabels.addAll(((GraphLabelType) type).getLabelsEntry());
9194
}
92-
return types.get(0);
95+
return new GraphLabelType(unionLabels.stream().distinct().collect(Collectors.toList()));
9396
}
9497
if (types.stream().anyMatch(t -> t instanceof ArbitraryMapType)) {
9598
return leastRestrictiveForArbitraryMapType(types);

โ€Žinteractive_engine/compiler/src/test/java/com/alibaba/graphscope/gremlin/antlr4x/GraphBuilderTest.javaโ€Ž

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import com.alibaba.graphscope.common.ir.tools.GraphStdOperatorTable;
2929
import com.alibaba.graphscope.common.ir.tools.config.GraphOpt;
3030
import com.alibaba.graphscope.common.ir.tools.config.SourceConfig;
31+
import com.alibaba.graphscope.common.ir.type.ArbitraryMapType;
32+
import com.alibaba.graphscope.common.ir.type.GraphLabelType;
3133
import com.alibaba.graphscope.common.ir.type.GraphProperty;
3234
import com.alibaba.graphscope.common.utils.FileUtils;
3335
import com.alibaba.graphscope.gaia.proto.OuterExpression;
@@ -40,6 +42,7 @@
4042
import org.antlr.v4.runtime.tree.ParseTree;
4143
import org.apache.calcite.plan.RelOptPlanner;
4244
import org.apache.calcite.rel.RelNode;
45+
import org.apache.calcite.rel.type.RelDataType;
4346
import org.apache.calcite.rex.RexBuilder;
4447
import org.apache.calcite.rex.RexNode;
4548
import org.junit.Assert;
@@ -86,6 +89,36 @@ public static RelNode eval(String query, GraphBuilder builder) {
8689
return visitor.visit(parseTree).build();
8790
}
8891

92+
@Test
93+
public void g_V_elementMap_test() {
94+
GraphRelOptimizer optimizer = new GraphRelOptimizer(configs);
95+
IrMeta irMeta =
96+
Utils.mockIrMeta(
97+
"schema/ldbc.json",
98+
"statistics/ldbc30_statistics.json",
99+
optimizer.getGlogueHolder());
100+
GraphBuilder builder = Utils.mockGraphBuilder(optimizer, irMeta);
101+
RelNode node =
102+
eval(
103+
"g.V(72057594037928268).as(\"a\").outE(\"KNOWS\").as(\"b\").inV().as(\"c\").select('a',"
104+
+ " \"b\").by(elementMap())",
105+
builder);
106+
RelDataType projectType = node.getRowType().getFieldList().get(0).getType();
107+
RelDataType bValueType = projectType.getValueType();
108+
Assert.assertTrue(bValueType instanceof ArbitraryMapType);
109+
GraphLabelType labelType =
110+
(GraphLabelType)
111+
((ArbitraryMapType) bValueType)
112+
.getKeyValueTypeMap().values().stream()
113+
.filter(k -> k.getValue() instanceof GraphLabelType)
114+
.findFirst()
115+
.get()
116+
.getValue();
117+
// make sure the inferred type contains the label type
118+
Assert.assertTrue(
119+
labelType.getLabelsEntry().stream().anyMatch(k -> k.getLabel().equals("KNOWS")));
120+
}
121+
89122
@Test
90123
public void g_V_test() {
91124
RelNode node = eval("g.V()");
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!--
2+
~ /*
3+
~ * Copyright 2020 Alibaba Group Holding Limited.
4+
~ *
5+
~ * Licensed under the Apache License, Version 2.0 (the "License");
6+
~ * you may not use this file except in compliance with the License.
7+
~ * You may obtain a copy of the License at
8+
~ *
9+
~ * http://www.apache.org/licenses/LICENSE-2.0
10+
~ *
11+
~ * Unless required by applicable law or agreed to in writing, software
12+
~ * distributed under the License is distributed on an "AS IS" BASIS,
13+
~ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ * See the License for the specific language governing permissions and
15+
~ * limitations under the License.
16+
~ */
17+
-->
18+
19+
<configuration>
20+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
21+
ใ€€ใ€€ใ€€ใ€€ใ€€<encoder>
22+
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€<pattern>[%d{ISO8601}][%p][%t][%c:%L] %m%n</pattern>
23+
ใ€€ใ€€ใ€€ใ€€ใ€€</encoder>
24+
ใ€€ใ€€ใ€€</appender>
25+
26+
<root level="WARN">
27+
<appender-ref ref="STDOUT" />
28+
</root>
29+
</configuration>

0 commit comments

Comments
ย (0)