Skip to content

Commit 54a22fb

Browse files
authored
fix(interactive): Fix Bugs of Alias Id in Union (#4404)
<!-- 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 <!-- Are there any issues opened that will be resolved by merging this change? --> Fixes #4385
1 parent f3a1a02 commit 54a22fb

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/exception/FrontendException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public String getMessage() {
6565
StringBuilder sb = new StringBuilder();
6666
sb.append("ErrorCode: ").append(errorCode.name()).append("\n");
6767
String msg = super.getMessage();
68-
if (!msg.endsWith("\n")) {
68+
if (msg == null || !msg.endsWith("\n")) {
6969
msg += "\n";
7070
}
7171
sb.append("Message: ").append(msg);

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
import com.google.common.collect.Maps;
2323

2424
import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
25-
import org.apache.calcite.rel.type.RelDataType;
25+
import org.apache.calcite.rel.type.*;
2626
import org.apache.calcite.rex.RexNode;
27+
import org.apache.calcite.util.Util;
2728
import org.checkerframework.checker.nullness.qual.Nullable;
2829

2930
import java.nio.charset.Charset;
@@ -100,6 +101,46 @@ public RelDataType createArbitraryMapType(
100101
return super.leastRestrictive(types);
101102
}
102103

104+
/**
105+
* reimplement the {@link RelDataTypeFactoryImpl#leastRestrictiveStructuredType(List)} method
106+
* to maintain the original alias id in the input types
107+
* @param types
108+
* @return
109+
*/
110+
@Override
111+
protected @Nullable RelDataType leastRestrictiveStructuredType(final List<RelDataType> types) {
112+
final RelDataType type0 = types.get(0);
113+
if (!type0.isStruct()) {
114+
return null;
115+
}
116+
final int fieldCount = type0.getFieldCount();
117+
boolean isNullable = false;
118+
for (RelDataType type : types) {
119+
if (!type.isStruct()) {
120+
return null;
121+
}
122+
if (type.getFieldList().size() != fieldCount) {
123+
return null;
124+
}
125+
isNullable |= type.isNullable();
126+
}
127+
List<RelDataTypeField> fields = Lists.newArrayList();
128+
for (int j = 0; j < fieldCount; ++j) {
129+
final int k = j;
130+
RelDataType type =
131+
leastRestrictive(Util.transform(types, t -> t.getFieldList().get(k).getType()));
132+
if (type == null) {
133+
return null;
134+
}
135+
fields.add(
136+
new RelDataTypeFieldImpl(
137+
type0.getFieldList().get(j).getName(),
138+
type0.getFieldList().get(j).getIndex(),
139+
type));
140+
}
141+
return new RelRecordType(StructKind.FULLY_QUALIFIED, fields, isNullable);
142+
}
143+
103144
// re-implement lease-restrictive type inference for arbitrary map types
104145
// for each key type and value type, check if they have a least-restrictive type, otherwise
105146
// return null

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.alibaba.graphscope.common.ir.planner.GraphIOProcessor;
2424
import com.alibaba.graphscope.common.ir.planner.GraphRelOptimizer;
2525
import com.alibaba.graphscope.common.ir.planner.rules.ExpandGetVFusionRule;
26+
import com.alibaba.graphscope.common.ir.rel.GraphLogicalProject;
27+
import com.alibaba.graphscope.common.ir.rex.RexGraphVariable;
2628
import com.alibaba.graphscope.common.ir.runtime.proto.RexToProtoConverter;
2729
import com.alibaba.graphscope.common.ir.tools.GraphBuilder;
2830
import com.alibaba.graphscope.common.ir.tools.GraphStdOperatorTable;
@@ -1852,4 +1854,36 @@ public void g_V_match_as_a_person_both_as_b_test() {
18521854
+ " person]}], alias=[a], opt=[VERTEX])",
18531855
after3.explain().trim());
18541856
}
1857+
1858+
@Test
1859+
public void union_valueMap_test() {
1860+
Configs configs =
1861+
new Configs(
1862+
ImmutableMap.of(
1863+
"graph.planner.is.on",
1864+
"true",
1865+
"graph.planner.opt",
1866+
"CBO",
1867+
"graph.planner.rules",
1868+
"FilterIntoJoinRule, FilterMatchRule, ExtendIntersectRule,"
1869+
+ " ExpandGetVFusionRule"));
1870+
GraphRelOptimizer optimizer = new GraphRelOptimizer(configs);
1871+
IrMeta irMeta =
1872+
Utils.mockIrMeta(
1873+
"schema/ldbc.json",
1874+
"statistics/ldbc30_statistics.json",
1875+
optimizer.getGlogueHolder());
1876+
GraphBuilder builder = Utils.mockGraphBuilder(optimizer, irMeta);
1877+
RelNode node1 =
1878+
eval(
1879+
"g.V().hasLabel(\"PERSON\").has(\"id\","
1880+
+ " 1816).union(outE(\"LIKES\").limit(10).as('a').inV().as('b').select('a','b').by(valueMap(\"creationDate\")),"
1881+
+ " outE(\"KNOWS\").limit(10).as('c').inV().as('d').select('c','d').by(valueMap(\"creationDate\")))",
1882+
builder);
1883+
RelNode after1 = optimizer.optimize(node1, new GraphIOProcessor(builder, irMeta));
1884+
GraphLogicalProject project = (GraphLogicalProject) after1;
1885+
RexNode expr = project.getProjects().get(0);
1886+
RexGraphVariable var = (RexGraphVariable) expr;
1887+
Assert.assertEquals(2, var.getAliasId());
1888+
}
18551889
}

0 commit comments

Comments
 (0)