Skip to content

Commit

Permalink
fix(interactive): Fix Bugs of Mismatch Label in elementMap (#4326)
Browse files Browse the repository at this point in the history
<!--
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
  • Loading branch information
shirly121 authored Nov 20, 2024
1 parent 033590f commit a8952a4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,13 @@ public RelDataType createArbitraryMapType(
@Override
public @Nullable RelDataType leastRestrictive(List<RelDataType> types) {
if (types.stream().anyMatch(t -> t instanceof GraphLabelType)) {
// union all labels
List<GraphLabelType.Entry> unionLabels = Lists.newArrayList();
for (RelDataType type : types) {
if (!(type instanceof GraphLabelType)) return null;
unionLabels.addAll(((GraphLabelType) type).getLabelsEntry());
}
return types.get(0);
return new GraphLabelType(unionLabels.stream().distinct().collect(Collectors.toList()));
}
if (types.stream().anyMatch(t -> t instanceof ArbitraryMapType)) {
return leastRestrictiveForArbitraryMapType(types);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.alibaba.graphscope.common.ir.tools.GraphStdOperatorTable;
import com.alibaba.graphscope.common.ir.tools.config.GraphOpt;
import com.alibaba.graphscope.common.ir.tools.config.SourceConfig;
import com.alibaba.graphscope.common.ir.type.ArbitraryMapType;
import com.alibaba.graphscope.common.ir.type.GraphLabelType;
import com.alibaba.graphscope.common.ir.type.GraphProperty;
import com.alibaba.graphscope.common.utils.FileUtils;
import com.alibaba.graphscope.gaia.proto.OuterExpression;
Expand All @@ -40,6 +42,7 @@
import org.antlr.v4.runtime.tree.ParseTree;
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rex.RexBuilder;
import org.apache.calcite.rex.RexNode;
import org.junit.Assert;
Expand Down Expand Up @@ -86,6 +89,36 @@ public static RelNode eval(String query, GraphBuilder builder) {
return visitor.visit(parseTree).build();
}

@Test
public void g_V_elementMap_test() {
GraphRelOptimizer optimizer = new GraphRelOptimizer(configs);
IrMeta irMeta =
Utils.mockIrMeta(
"schema/ldbc.json",
"statistics/ldbc30_statistics.json",
optimizer.getGlogueHolder());
GraphBuilder builder = Utils.mockGraphBuilder(optimizer, irMeta);
RelNode node =
eval(
"g.V(72057594037928268).as(\"a\").outE(\"KNOWS\").as(\"b\").inV().as(\"c\").select('a',"
+ " \"b\").by(elementMap())",
builder);
RelDataType projectType = node.getRowType().getFieldList().get(0).getType();
RelDataType bValueType = projectType.getValueType();
Assert.assertTrue(bValueType instanceof ArbitraryMapType);
GraphLabelType labelType =
(GraphLabelType)
((ArbitraryMapType) bValueType)
.getKeyValueTypeMap().values().stream()
.filter(k -> k.getValue() instanceof GraphLabelType)
.findFirst()
.get()
.getValue();
// make sure the inferred type contains the label type
Assert.assertTrue(
labelType.getLabelsEntry().stream().anyMatch(k -> k.getLabel().equals("KNOWS")));
}

@Test
public void g_V_test() {
RelNode node = eval("g.V()");
Expand Down
29 changes: 29 additions & 0 deletions interactive_engine/compiler/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!--
~ /*
~ * Copyright 2020 Alibaba Group Holding Limited.
~ *
~ * Licensed under the Apache License, Version 2.0 (the "License");
~ * you may not use this file except in compliance with the License.
~ * You may obtain a copy of the License at
~ *
~ * http://www.apache.org/licenses/LICENSE-2.0
~ *
~ * Unless required by applicable law or agreed to in writing, software
~ * distributed under the License is distributed on an "AS IS" BASIS,
~ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ * See the License for the specific language governing permissions and
~ * limitations under the License.
~ */
-->

<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
ใ€€ใ€€ใ€€ใ€€ใ€€<encoder>
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€<pattern>[%d{ISO8601}][%p][%t][%c:%L] %m%n</pattern>
ใ€€ใ€€ใ€€ใ€€ใ€€</encoder>
ใ€€ใ€€ใ€€</appender>

<root level="WARN">
<appender-ref ref="STDOUT" />
</root>
</configuration>

0 comments on commit a8952a4

Please sign in to comment.