From 495529103802e2562d79966d52a92469ac313524 Mon Sep 17 00:00:00 2001 From: Xiaoli Zhou Date: Thu, 11 Jul 2024 17:46:46 +0800 Subject: [PATCH] fix(interactive): Fix Result Parsing Mismatch Errors of `Map` Structure (#4006) For the `map` structure, there is inconsistency between the type maintenance on the compiler side and the implementation on the runtime side. Specifically, the compiler maintains the types of entries in the map according to the order specified by the user, while the runtime uses a `TreeMap` to maintain entries based on the internal order of keys. This inconsistency has caused parsing issues for `map` results by the compiler. To address this issue, this PR primarily focuses on the following two aspects: 1. specifying the columns to be output and their order concretely in the `sink` operator to ensure columns are output in the order specified by the user; 2. maintaining specific mappings from keys to types in the `map` type, see [here](https://github.com/alibaba/GraphScope/pull/4006/files#diff-49e26198c19ddbe7e665b8d5a66ceced8b8d02916e07def597fd4a7cdfffeffa). During result parsing, this ensures that the type corresponding to the returned key is found in this map, thereby ensuring consistency. Co-authored-by: Longbin Lai --- .../common/ir/meta/procedure/Utils.java | 143 ------------------ .../rex/operator/SqlMapValueConstructor.java | 15 +- .../proto/GraphRelProtoPhysicalBuilder.java | 43 ++++-- .../common/ir/type/ArbitraryMapType.java | 26 ++-- .../common/ir/type/GraphTypeFactoryImpl.java | 72 +++++---- .../graphscope/common/result/Utils.java | 18 +++ .../cypher/result/CypherRecordParser.java | 42 ++--- .../gremlin/resultx/GremlinRecordParser.java | 59 ++++---- .../ir/runtime/GraphRelToProtoTest.java | 111 +++++++++----- .../gremlin/antlr4x/GraphBuilderTest.java | 8 +- .../test/resources/proto/st_path_test.json | 3 + 11 files changed, 239 insertions(+), 301 deletions(-) delete mode 100644 interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/procedure/Utils.java diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/procedure/Utils.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/procedure/Utils.java deleted file mode 100644 index ef15c817aacf..000000000000 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/procedure/Utils.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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. - */ - -package com.alibaba.graphscope.common.ir.meta.procedure; - -import com.alibaba.graphscope.common.ir.type.ArbitraryArrayType; -import com.alibaba.graphscope.common.ir.type.ArbitraryMapType; -import com.alibaba.graphscope.common.ir.type.GraphTypeFactoryImpl; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; - -import org.apache.calcite.rel.type.RelDataType; -import org.apache.calcite.rel.type.RelDataTypeFactory; -import org.apache.calcite.sql.type.SqlTypeName; - -import java.util.List; -import java.util.stream.Collectors; - -public class Utils { - public static String typeToStr(RelDataType dataType) { - SqlTypeName typeName = dataType.getSqlTypeName(); - if (typeName == SqlTypeName.CHAR) { - return "STRING"; - } else if (typeName == SqlTypeName.BIGINT) { - return "LONG"; - } else if (typeName == SqlTypeName.ARRAY || typeName == SqlTypeName.MULTISET) { - if (dataType instanceof ArbitraryArrayType) { - List componentTypes = - ((ArbitraryArrayType) dataType).getComponentTypes(); - StringBuilder sb = new StringBuilder(); - sb.append(typeName.getName() + "("); - for (int i = 0; i < componentTypes.size(); i++) { - sb.append(typeToStr(componentTypes.get(i))); - if (i != componentTypes.size() - 1) { - sb.append(","); - } - } - sb.append(")"); - return sb.toString(); - } else { - return String.format( - "%s(%s)", typeName.getName(), typeToStr(dataType.getComponentType())); - } - } else if (typeName == SqlTypeName.MAP) { - if (dataType instanceof ArbitraryMapType) { - List keyTypes = ((ArbitraryMapType) dataType).getKeyTypes(); - List valueTypes = ((ArbitraryMapType) dataType).getValueTypes(); - Preconditions.checkArgument( - keyTypes.size() == valueTypes.size(), - "key size and value size are not equal in " + dataType); - StringBuilder sb = new StringBuilder(); - sb.append(typeName.getName() + "("); - for (int i = 0; i < keyTypes.size(); i++) { - sb.append(typeToStr(keyTypes.get(i))); - sb.append(","); - sb.append(typeToStr(valueTypes.get(i))); - if (i != keyTypes.size() - 1) { - sb.append(","); - } - } - sb.append(")"); - return sb.toString(); - } else { - return String.format( - "%s(%s,%s)", - typeName.getName(), - typeToStr(dataType.getKeyType()), - typeToStr(dataType.getValueType())); - } - } else { - // todo: convert vertex or edge type to string - return typeName.getName(); - } - } - - public static RelDataType strToType(String typeStr, RelDataTypeFactory typeFactory) { - typeStr = typeStr.toUpperCase(); - if (typeStr.equals("STRING")) { - return typeFactory.createSqlType(SqlTypeName.CHAR); - } else if (typeStr.equals("LONG")) { - return typeFactory.createSqlType(SqlTypeName.BIGINT); - } else if (typeStr.startsWith(SqlTypeName.ARRAY.getName())) { - List componentTypeStr = getComponentTypeStr(typeStr); - if (componentTypeStr.size() == 1) { - RelDataType componentType = strToType(componentTypeStr.get(0), typeFactory); - return typeFactory.createArrayType(componentType, -1); - } else { - List componentTypes = - componentTypeStr.stream() - .map(k -> strToType(k, typeFactory)) - .collect(Collectors.toList()); - return ((GraphTypeFactoryImpl) typeFactory) - .createArbitraryArrayType(componentTypes, false); - } - } else if (typeStr.startsWith(SqlTypeName.MAP.getName())) { - List componentTypeStr = getComponentTypeStr(typeStr); - if (componentTypeStr.size() == 2) { - RelDataType keyType = strToType(componentTypeStr.get(0), typeFactory); - RelDataType valueType = strToType(componentTypeStr.get(1), typeFactory); - return typeFactory.createMapType(keyType, valueType); - } else { - List keyTypes = Lists.newArrayList(); - List valueTypes = Lists.newArrayList(); - for (int i = 0; i < componentTypeStr.size(); i++) { - if ((i & 1) == 0) { - keyTypes.add(strToType(componentTypeStr.get(i), typeFactory)); - } else { - valueTypes.add(strToType(componentTypeStr.get(i), typeFactory)); - } - } - return ((GraphTypeFactoryImpl) typeFactory) - .createArbitraryMapType(keyTypes, valueTypes, false); - } - } else if (typeStr.startsWith(SqlTypeName.MULTISET.getName())) { - RelDataType componentType = strToType(getComponentTypeStr(typeStr).get(0), typeFactory); - return typeFactory.createMultisetType(componentType, -1); - } else { - return typeFactory.createSqlType(SqlTypeName.valueOf(typeStr)); - } - } - - private static List getComponentTypeStr(String typeStr) { - int leftBraceIdx = typeStr.indexOf("("); - int rightBraceIdx = typeStr.lastIndexOf(")"); - Preconditions.checkArgument( - leftBraceIdx != -1 && rightBraceIdx != -1, "invalid type pattern " + typeStr); - return com.alibaba.graphscope.common.config.Utils.convertDotString( - typeStr.substring(leftBraceIdx + 1, rightBraceIdx)); - } -} diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rex/operator/SqlMapValueConstructor.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rex/operator/SqlMapValueConstructor.java index e6f81796694d..eeb5e87f5c42 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rex/operator/SqlMapValueConstructor.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rex/operator/SqlMapValueConstructor.java @@ -16,10 +16,14 @@ package com.alibaba.graphscope.common.ir.rex.operator; +import com.alibaba.graphscope.common.ir.rex.RexCallBinding; +import com.alibaba.graphscope.common.ir.type.ArbitraryMapType; import com.alibaba.graphscope.common.ir.type.GraphTypeFactoryImpl; +import com.google.common.collect.Maps; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeFactory; +import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlCallBinding; import org.apache.calcite.sql.SqlKind; import org.apache.calcite.sql.SqlOperatorBinding; @@ -31,6 +35,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import java.util.List; +import java.util.Map; /** * This operator is used to fold columns into a map, i.e. {name: a.name, age: a.age} in cypher queries. @@ -56,8 +61,16 @@ public RelDataType inferReturnType(SqlOperatorBinding opBinding) { && valueType.getSqlTypeName() != SqlTypeName.ANY) { return SqlTypeUtil.createMapType(opBinding.getTypeFactory(), keyType, valueType, false); } else { + Map keyValueTypeMap = Maps.newHashMap(); + List operands = ((RexCallBinding) opBinding).getRexOperands(); + for (int i = 0; i < operands.size(); i += 2) { + keyValueTypeMap.put( + operands.get(i), + new ArbitraryMapType.KeyValueType( + keyTypes.get(i / 2), valueTypes.get(i / 2))); + } return ((GraphTypeFactoryImpl) typeFactory) - .createArbitraryMapType(keyTypes, valueTypes, false); + .createArbitraryMapType(keyValueTypeMap, false); } } diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/GraphRelProtoPhysicalBuilder.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/GraphRelProtoPhysicalBuilder.java index 67a8a22b9e7d..2ede50e1f0f3 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/GraphRelProtoPhysicalBuilder.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/GraphRelProtoPhysicalBuilder.java @@ -24,9 +24,11 @@ import com.alibaba.graphscope.common.ir.rel.GraphShuttle; import com.alibaba.graphscope.common.ir.runtime.PhysicalBuilder; import com.alibaba.graphscope.common.ir.runtime.PhysicalPlan; +import com.alibaba.graphscope.common.ir.tools.AliasInference; import com.alibaba.graphscope.common.ir.tools.LogicalPlan; import com.alibaba.graphscope.gaia.proto.GraphAlgebra; import com.alibaba.graphscope.gaia.proto.GraphAlgebraPhysical; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -57,13 +59,19 @@ public class GraphRelProtoPhysicalBuilder extends PhysicalBuilder { // `g.V().out().union(out(), out())`, // `g.V().out()` is a common sub-plan, the pair of is recorded in this map private final IdentityHashMap> relToCommons; + private final boolean skipSinkColumns; public GraphRelProtoPhysicalBuilder( Configs graphConfig, IrMeta irMeta, LogicalPlan logicalPlan) { + this(graphConfig, irMeta, logicalPlan, false); + } + + @VisibleForTesting + public GraphRelProtoPhysicalBuilder( + Configs graphConfig, IrMeta irMeta, LogicalPlan logicalPlan, boolean skipSinkColumns) { super(logicalPlan); this.physicalBuilder = GraphAlgebraPhysical.PhysicalPlan.newBuilder(); this.relToCommons = createRelToCommons(logicalPlan); - this.relShuttle = new GraphRelToProtoConverter( irMeta.getSchema().isColumnId(), @@ -71,6 +79,7 @@ public GraphRelProtoPhysicalBuilder( this.physicalBuilder, this.relToCommons, createExtraParams(irMeta)); + this.skipSinkColumns = skipSinkColumns; } @Override @@ -79,7 +88,11 @@ public PhysicalPlan build() { try { RelNode regularQuery = this.logicalPlan.getRegularQuery(); regularQuery.accept(this.relShuttle); - appendDefaultSink(); + physicalBuilder.addPlan( + GraphAlgebraPhysical.PhysicalOpr.newBuilder() + .setOpr( + GraphAlgebraPhysical.PhysicalOpr.Operator.newBuilder() + .setSink(getSinkByColumns(regularQuery)))); plan = getPlanAsJson(physicalBuilder.build()); int planId = Objects.hash(logicalPlan); physicalBuilder.setPlanId(planId); @@ -92,17 +105,23 @@ public PhysicalPlan build() { } } - private void appendDefaultSink() { - GraphAlgebraPhysical.PhysicalOpr.Builder oprBuilder = - GraphAlgebraPhysical.PhysicalOpr.newBuilder(); + private GraphAlgebraPhysical.Sink getSinkByColumns(RelNode regularQuery) { GraphAlgebraPhysical.Sink.Builder sinkBuilder = GraphAlgebraPhysical.Sink.newBuilder(); - GraphAlgebra.Sink.SinkTarget.Builder sinkTargetBuilder = - GraphAlgebra.Sink.SinkTarget.newBuilder(); - sinkTargetBuilder.setSinkDefault(GraphAlgebra.SinkDefault.newBuilder().build()); - sinkBuilder.setSinkTarget(sinkTargetBuilder); - oprBuilder.setOpr( - GraphAlgebraPhysical.PhysicalOpr.Operator.newBuilder().setSink(sinkBuilder)); - physicalBuilder.addPlan(oprBuilder); + sinkBuilder.setSinkTarget( + GraphAlgebra.Sink.SinkTarget.newBuilder() + .setSinkDefault(GraphAlgebra.SinkDefault.newBuilder().build())); + regularQuery + .getRowType() + .getFieldList() + .forEach( + k -> { + if (!skipSinkColumns && k.getIndex() != AliasInference.DEFAULT_ID) { + sinkBuilder.addTags( + GraphAlgebraPhysical.Sink.OptTag.newBuilder() + .setTag(Utils.asAliasId(k.getIndex()))); + } + }); + return sinkBuilder.build(); } private String getPlanAsJson(GraphAlgebraPhysical.PhysicalPlan physicalPlan) { diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/ArbitraryMapType.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/ArbitraryMapType.java index 2b378479f0d5..3dde2bdda565 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/ArbitraryMapType.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/ArbitraryMapType.java @@ -17,39 +17,39 @@ package com.alibaba.graphscope.common.ir.type; import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.type.AbstractSqlType; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.calcite.util.Pair; import java.util.Collections; -import java.util.List; -import java.util.Objects; +import java.util.Map; /** * introduce a new map type to allow different keys or value types in a single map, * to support {@code MapLiteral} in cypher, i.e. [name: a.name, a: a, age: b.age] */ public class ArbitraryMapType extends AbstractSqlType { - private final List keyTypes; - private final List valueTypes; + private final Map keyValueTypeMap; - protected ArbitraryMapType( - List keyTypes, List valueTypes, boolean isNullable) { + protected ArbitraryMapType(Map keyValueTypeMap, boolean isNullable) { super(SqlTypeName.MAP, isNullable, null); - this.keyTypes = Objects.requireNonNull(keyTypes); - this.valueTypes = Objects.requireNonNull(valueTypes); + this.keyValueTypeMap = keyValueTypeMap; this.computeDigest(); } @Override protected void generateTypeString(StringBuilder sb, boolean withDetail) { - sb.append("(" + keyTypes.toString() + ", " + valueTypes.toString() + ") MAP"); + sb.append("(" + keyValueTypeMap + ") MAP"); } - public List getKeyTypes() { - return Collections.unmodifiableList(this.keyTypes); + public Map getKeyValueTypeMap() { + return Collections.unmodifiableMap(this.keyValueTypeMap); } - public List getValueTypes() { - return Collections.unmodifiableList(this.valueTypes); + public static class KeyValueType extends Pair { + public KeyValueType(RelDataType left, RelDataType right) { + super(left, right); + } } } diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/GraphTypeFactoryImpl.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/GraphTypeFactoryImpl.java index f31c408545ec..15f13bc03d6e 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/GraphTypeFactoryImpl.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/GraphTypeFactoryImpl.java @@ -19,13 +19,17 @@ import com.alibaba.graphscope.common.config.Configs; import com.alibaba.graphscope.common.config.FrontendConfig; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import org.apache.calcite.jdbc.JavaTypeFactoryImpl; import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rex.RexNode; import org.checkerframework.checker.nullness.qual.Nullable; import java.nio.charset.Charset; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; public class GraphTypeFactoryImpl extends JavaTypeFactoryImpl { private final Configs configs; @@ -75,8 +79,8 @@ public RelDataType createArbitraryArrayType( } public RelDataType createArbitraryMapType( - List keyTypes, List valueTypes, boolean isNullable) { - return new ArbitraryMapType(keyTypes, valueTypes, isNullable); + Map keyValueTypeMap, boolean isNullable) { + return new ArbitraryMapType(keyValueTypeMap, isNullable); } @Override @@ -98,44 +102,48 @@ public RelDataType createArbitraryMapType( // return null private @Nullable RelDataType leastRestrictiveForArbitraryMapType(List types) { boolean isNullable = false; - List> leastKeyTypes = Lists.newArrayList(); - List> leastValueTypes = Lists.newArrayList(); + Map> leastKeyValueTypes = Maps.newHashMap(); for (RelDataType type : types) { if (!(type instanceof ArbitraryMapType)) return null; ArbitraryMapType mapType = (ArbitraryMapType) type; if (mapType.isNullable()) isNullable = true; - if (leastKeyTypes.isEmpty() || leastValueTypes.isEmpty()) { - for (RelDataType keyType : mapType.getKeyTypes()) { - leastKeyTypes.add(Lists.newArrayList(keyType)); - } - for (RelDataType valueType : mapType.getValueTypes()) { - leastValueTypes.add(Lists.newArrayList(valueType)); - } + if (leastKeyValueTypes.isEmpty()) { + mapType.getKeyValueTypeMap() + .forEach( + (k, v) -> { + leastKeyValueTypes.put(k, Lists.newArrayList(v)); + }); } else { - if (leastKeyTypes.size() != mapType.getKeyTypes().size() - || leastValueTypes.size() != mapType.getValueTypes().size()) { - return null; - } - for (int i = 0; i < leastKeyTypes.size(); i++) { - leastKeyTypes.get(i).add(mapType.getKeyTypes().get(i)); - } - for (int i = 0; i < leastValueTypes.size(); i++) { - leastValueTypes.get(i).add(mapType.getValueTypes().get(i)); + for (Map.Entry entry : + mapType.getKeyValueTypeMap().entrySet()) { + List leastTypes = + leastKeyValueTypes.get(entry.getKey()); + if (leastTypes == null) { + return null; + } + leastTypes.add(entry.getValue()); } } } - List mapKeyTypes = Lists.newArrayList(); - for (List leastKeyType : leastKeyTypes) { - RelDataType type = leastRestrictive(leastKeyType); - if (type == null) return null; - mapKeyTypes.add(type); - } - List mapValueTypes = Lists.newArrayList(); - for (List leastValueType : leastValueTypes) { - RelDataType type = leastRestrictive(leastValueType); - if (type == null) return null; - mapValueTypes.add(type); + Map leastKeyValueType = Maps.newHashMap(); + for (Map.Entry> entry : + leastKeyValueTypes.entrySet()) { + RelDataType leastKeyType = + leastRestrictive( + entry.getValue().stream() + .map(ArbitraryMapType.KeyValueType::getKey) + .collect(Collectors.toList())); + if (leastKeyType == null) return null; + RelDataType leastValueType = + leastRestrictive( + entry.getValue().stream() + .map(ArbitraryMapType.KeyValueType::getValue) + .collect(Collectors.toList())); + if (leastValueType == null) return null; + leastKeyValueType.put( + entry.getKey(), + new ArbitraryMapType.KeyValueType(leastKeyType, leastValueType)); } - return createArbitraryMapType(mapKeyTypes, mapValueTypes, isNullable); + return createArbitraryMapType(leastKeyValueType, isNullable); } } diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/result/Utils.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/result/Utils.java index ea540bf06962..9efa9876747b 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/result/Utils.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/result/Utils.java @@ -16,6 +16,7 @@ package com.alibaba.graphscope.common.result; +import com.alibaba.graphscope.common.ir.type.ArbitraryMapType; import com.alibaba.graphscope.common.ir.type.GraphLabelType; import com.alibaba.graphscope.common.ir.type.GraphPathType; import com.alibaba.graphscope.common.ir.type.GraphSchemaType; @@ -25,13 +26,17 @@ 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.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.stream.Collectors; public class Utils { private static final Logger logger = LoggerFactory.getLogger(Utils.class); @@ -162,4 +167,17 @@ public static RelDataTypeField findFieldByPredicate( Predicate p, List typeFields) { return typeFields.stream().filter(k -> p.test(k)).findFirst().orElse(null); } + + public static ArbitraryMapType.KeyValueType getKeyValueType( + Common.Value target, Map keyValueTypeMap) { + Map conversionType = + keyValueTypeMap.entrySet().stream() + .collect( + Collectors.toMap( + entry -> + com.alibaba.graphscope.common.ir.runtime.proto.Utils + .protoValue((RexLiteral) entry.getKey()), + Map.Entry::getValue)); + return conversionType.get(target); + } } diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/result/CypherRecordParser.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/result/CypherRecordParser.java index 706019e0bb57..d7ccba292a61 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/result/CypherRecordParser.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/result/CypherRecordParser.java @@ -30,6 +30,7 @@ import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeField; +import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.NotImplementedException; @@ -67,24 +68,14 @@ public List parseFrom(IrResult.Record record) { + " should be consistent with output type " + outputType.getFieldCount()); List columns = new ArrayList<>(record.getColumnsCount()); - for (RelDataTypeField field : outputType.getFieldList()) { - IrResult.Column column = getColumn(record, field); + for (int i = 0; i < record.getColumnsCount(); ++i) { + RelDataTypeField field = outputType.getFieldList().get(i); + IrResult.Column column = record.getColumns(i); columns.add(parseEntry(column.getEntry(), field.getType())); } return columns; } - private IrResult.Column getColumn(IrResult.Record record, RelDataTypeField field) { - int aliasId = field.getIndex(); - for (IrResult.Column column : record.getColumnsList()) { - if (column.getNameOrId().getId() == aliasId) { - return column; - } - } - throw new IllegalArgumentException( - "column with alias id " + aliasId + " not found in record " + record); - } - @Override public RelDataType schema() { return this.outputType; @@ -107,9 +98,7 @@ protected AnyValue parseEntry(IrResult.Entry entry, @Nullable RelDataType dataTy case MAP: if (dataType instanceof ArbitraryMapType) { return parseKeyValues( - entry.getMap(), - ((ArbitraryMapType) dataType).getKeyTypes(), - ((ArbitraryMapType) dataType).getValueTypes()); + entry.getMap(), ((ArbitraryMapType) dataType).getKeyValueTypeMap()); } else { return parseKeyValues( entry.getMap(), dataType.getKeyType(), dataType.getValueType()); @@ -204,19 +193,16 @@ protected AnyValue parseKeyValues( protected AnyValue parseKeyValues( IrResult.KeyValues keyValues, - List keyTypes, - List valueTypes) { - List entries = keyValues.getKeyValuesList(); - Preconditions.checkArgument( - entries.size() == valueTypes.size(), - "KeyValues entry size=" - + entries.size() - + " is not consistent with value type size=" - + valueTypes.size()); + Map keyValueTypeMap) { Map valueMap = Maps.newLinkedHashMap(); - for (int i = 0; i < entries.size(); ++i) { - IrResult.KeyValues.KeyValue entry = entries.get(i); - valueMap.put(entry.getKey().getStr(), parseEntry(entry.getValue(), valueTypes.get(i))); + for (IrResult.KeyValues.KeyValue entry : keyValues.getKeyValuesList()) { + ArbitraryMapType.KeyValueType keyValueType = + Utils.getKeyValueType(entry.getKey(), keyValueTypeMap); + valueMap.put( + entry.getKey().getStr(), + parseEntry( + entry.getValue(), + keyValueType == null ? null : keyValueType.getValue())); } return VirtualValues.fromMap(valueMap, valueMap.size(), 0); } diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/gremlin/resultx/GremlinRecordParser.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/gremlin/resultx/GremlinRecordParser.java index dab05c9e6451..fb32053cb543 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/gremlin/resultx/GremlinRecordParser.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/gremlin/resultx/GremlinRecordParser.java @@ -32,6 +32,7 @@ import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeField; +import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.type.MapSqlType; import org.apache.commons.lang3.NotImplementedException; import org.apache.tinkerpop.gremlin.structure.Edge; @@ -121,9 +122,7 @@ private Object parseEntry(IrResult.Entry entry, RelDataType type) { case MAP: if (type instanceof ArbitraryMapType) { return parseKeyValues( - entry.getMap(), - ((ArbitraryMapType) type).getKeyTypes(), - ((ArbitraryMapType) type).getValueTypes()); + entry.getMap(), ((ArbitraryMapType) type).getKeyValueTypeMap()); } else { return parseKeyValues(entry.getMap(), type.getKeyType(), type.getValueType()); } @@ -172,19 +171,15 @@ private Map parseKeyValues( private Map parseKeyValues( IrResult.KeyValues keyValues, - List keyTypes, - List valueTypes) { - List entries = keyValues.getKeyValuesList(); - Preconditions.checkArgument( - entries.size() == valueTypes.size(), - "KeyValues entry size=" - + entries.size() - + " is not consistent with value type size=" - + valueTypes.size()); + Map keyValueTypeMap) { Map valueMap = Maps.newLinkedHashMap(); - for (int i = 0; i < entries.size(); ++i) { - IrResult.KeyValues.KeyValue entry = entries.get(i); - Object value = parseEntry(entry.getValue(), valueTypes.get(i)); + for (IrResult.KeyValues.KeyValue entry : keyValues.getKeyValuesList()) { + ArbitraryMapType.KeyValueType keyValueType = + Utils.getKeyValueType(entry.getKey(), keyValueTypeMap); + Object value = + parseEntry( + entry.getValue(), + keyValueType == null ? null : keyValueType.getValue()); if (value != null) { valueMap.put(parseMapKey(entry.getKey().getStr()), value); } @@ -296,20 +291,28 @@ private List parseGraphPath(IrResult.GraphPath path, @Nullable RelDataT k -> parseValue(k.getKey(), dataType.getKeyType()), v -> parseValue(v.getVal(), dataType.getValueType()))); } else if (dataType instanceof ArbitraryMapType) { - List pairArray = value.getPairArray().getItemList(); - List keyTypes = ((ArbitraryMapType) dataType).getKeyTypes(); - List valueTypes = ((ArbitraryMapType) dataType).getValueTypes(); Map map = Maps.newLinkedHashMap(); - for (int i = 0; i < pairArray.size(); ++i) { - Common.Pair pair = pairArray.get(i); - map.put( - parseValue( - pair.getKey(), - i < keyTypes.size() ? keyTypes.get(i) : null), - parseValue( - pair.getVal(), - i < valueTypes.size() ? valueTypes.get(i) : null)); - } + Map keyValueTypeMap = + ((ArbitraryMapType) dataType).getKeyValueTypeMap(); + value.getPairArray() + .getItemList() + .forEach( + pair -> { + ArbitraryMapType.KeyValueType keyValueType = + Utils.getKeyValueType( + pair.getKey(), keyValueTypeMap); + map.put( + parseValue( + pair.getKey(), + keyValueType == null + ? null + : keyValueType.getKey()), + parseValue( + pair.getVal(), + keyValueType == null + ? null + : keyValueType.getValue())); + }); return map; } case NONE: diff --git a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/runtime/GraphRelToProtoTest.java b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/runtime/GraphRelToProtoTest.java index e86f4dfc1426..b59695ef1337 100644 --- a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/runtime/GraphRelToProtoTest.java +++ b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/runtime/GraphRelToProtoTest.java @@ -64,7 +64,7 @@ public void scan_test() throws Exception { scan.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(scan))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(scan), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/scan_test.json"), plan.explain().trim()); @@ -87,7 +87,7 @@ public void scan_edge_test() throws Exception { scan.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(scan))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(scan), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/scan_edge_test.json"), @@ -116,7 +116,7 @@ public void scan_filter_test() throws Exception { scan.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(scan))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(scan), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/scan_filter_test.json"), @@ -146,7 +146,7 @@ public void edge_expand_test() throws Exception { expand.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(expand))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(expand), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/edge_expand_test.json"), @@ -193,7 +193,7 @@ public void get_v_test() throws Exception { getV.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(getV))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(getV), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/getv_test.json"), plan.explain().trim()); @@ -201,7 +201,10 @@ public void get_v_test() throws Exception { try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockPartitionedGraphConfig(), Utils.schemaMeta, new LogicalPlan(getV))) { + getMockPartitionedGraphConfig(), + Utils.schemaMeta, + new LogicalPlan(getV), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/partitioned_getv_test.json"), @@ -242,7 +245,7 @@ public void get_v_with_filter_test() throws Exception { getV.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(getV))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(getV), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/getv_with_filter_test.json"), @@ -293,7 +296,7 @@ public void path_expand_test() throws Exception { pxd.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(pxd))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(pxd), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/path_expand_test.json"), @@ -321,7 +324,7 @@ public void project_test() throws Exception { project.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(project))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(project), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/project_test.json"), @@ -331,7 +334,8 @@ public void project_test() throws Exception { new GraphRelProtoPhysicalBuilder( getMockPartitionedGraphConfig(), Utils.schemaMeta, - new LogicalPlan(project))) { + new LogicalPlan(project), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/partitioned_project_test.json"), @@ -369,7 +373,7 @@ public void project_02_test() throws Exception { project.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(project))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(project), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/project_test_2.json"), @@ -379,7 +383,8 @@ public void project_02_test() throws Exception { new GraphRelProtoPhysicalBuilder( getMockPartitionedGraphConfig(), Utils.schemaMeta, - new LogicalPlan(project))) { + new LogicalPlan(project), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/partitioned_project_test_2.json"), @@ -408,7 +413,7 @@ public void filter_test() throws Exception { filter.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(filter))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(filter), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/filter_test.json"), @@ -445,7 +450,7 @@ public void filter_test_2() throws Exception { filter.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(filter))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(filter), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/filter_test_2.json"), @@ -455,7 +460,8 @@ public void filter_test_2() throws Exception { new GraphRelProtoPhysicalBuilder( getMockPartitionedGraphConfig(), Utils.schemaMeta, - new LogicalPlan(filter))) { + new LogicalPlan(filter), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/partitioned_filter_test_2.json"), @@ -485,7 +491,7 @@ public void aggregate_test() throws Exception { aggregate.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(aggregate))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(aggregate), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/aggregate_test.json"), @@ -495,7 +501,8 @@ public void aggregate_test() throws Exception { new GraphRelProtoPhysicalBuilder( getMockPartitionedGraphConfig(), Utils.schemaMeta, - new LogicalPlan(aggregate))) { + new LogicalPlan(aggregate), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/partitioned_aggregate_test.json"), @@ -537,7 +544,7 @@ public void aggregate_test_2() throws Exception { aggregate.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(aggregate))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(aggregate), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/aggregate_test_2.json"), @@ -565,7 +572,7 @@ public void dedup_test_1() throws Exception { dedup.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(dedup))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(dedup), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/dedup_test_1.json"), @@ -575,7 +582,8 @@ public void dedup_test_1() throws Exception { new GraphRelProtoPhysicalBuilder( getMockPartitionedGraphConfig(), Utils.schemaMeta, - new LogicalPlan(dedup))) { + new LogicalPlan(dedup), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/partitioned_dedup_test_1.json"), @@ -601,7 +609,7 @@ public void dedup_test_2() throws Exception { dedup.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(dedup))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(dedup), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/dedup_test_2.json"), @@ -611,7 +619,8 @@ public void dedup_test_2() throws Exception { new GraphRelProtoPhysicalBuilder( getMockPartitionedGraphConfig(), Utils.schemaMeta, - new LogicalPlan(dedup))) { + new LogicalPlan(dedup), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/partitioned_dedup_test_2.json"), @@ -655,7 +664,7 @@ public void join_test_1() throws Exception { join.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(join))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(join), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/join_test_1.json"), @@ -663,7 +672,10 @@ public void join_test_1() throws Exception { } try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockPartitionedGraphConfig(), Utils.schemaMeta, new LogicalPlan(join))) { + getMockPartitionedGraphConfig(), + Utils.schemaMeta, + new LogicalPlan(join), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/partitioned_join_test_1.json"), @@ -736,7 +748,7 @@ public void join_test_2() throws Exception { join.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(join))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(join), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/join_test_2.json"), @@ -744,7 +756,10 @@ public void join_test_2() throws Exception { } try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockPartitionedGraphConfig(), Utils.schemaMeta, new LogicalPlan(join))) { + getMockPartitionedGraphConfig(), + Utils.schemaMeta, + new LogicalPlan(join), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/partitioned_join_test_2.json"), @@ -769,14 +784,17 @@ public void sort_test() throws Exception { sort.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(sort))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(sort), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/sort_test.json"), plan.explain().trim()); } try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockPartitionedGraphConfig(), Utils.schemaMeta, new LogicalPlan(sort))) { + getMockPartitionedGraphConfig(), + Utils.schemaMeta, + new LogicalPlan(sort), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/partitioned_sort_test.json"), @@ -801,7 +819,7 @@ public void limit_test() throws Exception { limit.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(limit))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(limit), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/limit_test.json"), plan.explain().trim()); @@ -842,7 +860,7 @@ public void expand_degree_test() throws Exception { after.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(after))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(after), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/edge_expand_degree_test.json"), @@ -853,7 +871,8 @@ public void expand_degree_test() throws Exception { new GraphRelProtoPhysicalBuilder( getMockPartitionedGraphConfig(), Utils.schemaMeta, - new LogicalPlan(after))) { + new LogicalPlan(after), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource( @@ -901,7 +920,7 @@ public void expand_vertex_test() throws Exception { after.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(after))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(after), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/edge_expand_vertex_test.json"), @@ -912,7 +931,8 @@ public void expand_vertex_test() throws Exception { new GraphRelProtoPhysicalBuilder( getMockPartitionedGraphConfig(), Utils.schemaMeta, - new LogicalPlan(after))) { + new LogicalPlan(after), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource( @@ -961,7 +981,7 @@ public void expand_vertex_filter_test() throws Exception { RelNode after = planner.findBestExp(); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(after))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(after), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/edge_expand_vertex_filter_test.json"), @@ -972,7 +992,8 @@ public void expand_vertex_filter_test() throws Exception { new GraphRelProtoPhysicalBuilder( getMockPartitionedGraphConfig(), Utils.schemaMeta, - new LogicalPlan(after))) { + new LogicalPlan(after), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource( @@ -1025,7 +1046,7 @@ public void expand_vertex_with_filters_test() throws Exception { after.explain().trim()); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(after))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(after), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource( @@ -1081,7 +1102,7 @@ public void path_expand_fused_test() throws Exception { RelNode after = planner.findBestExp(); try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(after))) { + getMockGraphConfig(), Utils.schemaMeta, new LogicalPlan(after), true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/path_fused_expand_test.json"), @@ -1127,7 +1148,10 @@ public void intersect_test() throws Exception { try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockCBOConfig(), getMockCBOMeta(optimizer), new LogicalPlan(after))) { + getMockCBOConfig(), + getMockCBOMeta(optimizer), + new LogicalPlan(after), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/intersect_test.json"), @@ -1138,7 +1162,8 @@ public void intersect_test() throws Exception { new GraphRelProtoPhysicalBuilder( getMockPartitionedCBOConfig(), getMockCBOMeta(optimizer), - new LogicalPlan(after))) { + new LogicalPlan(after), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/partitioned_intersect_test.json"), @@ -1190,7 +1215,10 @@ public void intersect_test_02() throws Exception { try (PhysicalBuilder protoBuilder = new GraphRelProtoPhysicalBuilder( - getMockCBOConfig(), getMockCBOMeta(optimizer), new LogicalPlan(after))) { + getMockCBOConfig(), + getMockCBOMeta(optimizer), + new LogicalPlan(after), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/intersect_test_2.json"), @@ -1200,7 +1228,8 @@ public void intersect_test_02() throws Exception { new GraphRelProtoPhysicalBuilder( getMockPartitionedCBOConfig(), getMockCBOMeta(optimizer), - new LogicalPlan(after))) { + new LogicalPlan(after), + true)) { PhysicalPlan plan = protoBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("proto/partitioned_intersect_test_2.json"), diff --git a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/gremlin/antlr4x/GraphBuilderTest.java b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/gremlin/antlr4x/GraphBuilderTest.java index 01bd4e217ea4..7ba22ca9f32a 100644 --- a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/gremlin/antlr4x/GraphBuilderTest.java +++ b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/gremlin/antlr4x/GraphBuilderTest.java @@ -1720,9 +1720,11 @@ public void g_V_select_a_b_valueMap() { "g.V().hasLabel('person').as('a').out('knows').as('b').select('a'," + " 'b').by(valueMap())"); Assert.assertEquals( - "([CHAR(1), CHAR(1)], [([CHAR(2), CHAR(4), CHAR(3)], [BIGINT, CHAR(1), INTEGER])" - + " MAP, ([CHAR(2), CHAR(4), CHAR(4), CHAR(12), CHAR(3)], [BIGINT, CHAR(1)," - + " CHAR(1), DATE, INTEGER]) MAP]) MAP", + "({_UTF-8'a'=, _UTF-8'id'=, _UTF-8'age'=}) MAP>, _UTF-8'b'=, _UTF-8'id'=," + + " _UTF-8'creationDate'=, _UTF-8'age'=," + + " _UTF-8'lang'=}) MAP>}) MAP", rel.getRowType().getFieldList().get(0).getType().toString()); } diff --git a/interactive_engine/compiler/src/test/resources/proto/st_path_test.json b/interactive_engine/compiler/src/test/resources/proto/st_path_test.json index 9a78f1a00e11..480246a1ea93 100644 --- a/interactive_engine/compiler/src/test/resources/proto/st_path_test.json +++ b/interactive_engine/compiler/src/test/resources/proto/st_path_test.json @@ -648,6 +648,9 @@ }, { "opr": { "sink": { + "tags": [{ + "tag": 1 + }], "sinkTarget": { "sinkDefault": { }