diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rex/operator/SqlArrayValueConstructor.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rex/operator/SqlArrayValueConstructor.java index c5a60a0663ff..c03e22628ef0 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rex/operator/SqlArrayValueConstructor.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rex/operator/SqlArrayValueConstructor.java @@ -66,7 +66,7 @@ public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFail return (componentType == null) ? typeFactory.createSqlType(SqlTypeName.ANY) : componentType; - } catch (AssertionError e) { + } catch (Throwable e) { return typeFactory.createSqlType(SqlTypeName.ANY); } } 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 7d55978caca3..8cb3f114ddf6 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 @@ -47,13 +47,16 @@ public RelDataType inferReturnType(SqlOperatorBinding opBinding) { List argTypes = opBinding.collectOperandTypes(); List keyTypes = Util.quotientList(argTypes, 2, 0); List valueTypes = Util.quotientList(argTypes, 2, 1); - RelDataType keyType = typeFactory.leastRestrictive(keyTypes); + RelDataType keyType = getComponentType(typeFactory, keyTypes); RelDataType valueType = getComponentType(typeFactory, valueTypes); - if (valueType != null && valueType.getSqlTypeName() != SqlTypeName.ANY) { + if (keyType != null + && keyType.getSqlTypeName() != SqlTypeName.ANY + && valueType != null + && valueType.getSqlTypeName() != SqlTypeName.ANY) { return SqlTypeUtil.createMapType(opBinding.getTypeFactory(), keyType, valueType, false); } else { return ((GraphTypeFactoryImpl) typeFactory) - .createArbitraryMapType(keyType, valueTypes, false); + .createArbitraryMapType(keyTypes, valueTypes, false); } } @@ -74,7 +77,7 @@ public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFail return (componentType == null) ? typeFactory.createSqlType(SqlTypeName.ANY) : componentType; - } catch (AssertionError e) { + } catch (Throwable e) { return typeFactory.createSqlType(SqlTypeName.ANY); } } diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/ArbitraryArrayType.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/ArbitraryArrayType.java index de91c4e0d76a..56263226d367 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/ArbitraryArrayType.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/type/ArbitraryArrayType.java @@ -19,10 +19,10 @@ import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.sql.type.AbstractSqlType; import org.apache.calcite.sql.type.SqlTypeName; -import org.apache.commons.lang3.ObjectUtils; import java.util.Collections; import java.util.List; +import java.util.Objects; /** * introduce a new array type to allow different component types in a single array, @@ -33,7 +33,7 @@ public class ArbitraryArrayType extends AbstractSqlType { public ArbitraryArrayType(List componentTypes, boolean isNullable) { super(SqlTypeName.ARRAY, isNullable, null); - this.componentTypes = ObjectUtils.requireNonEmpty(componentTypes); + this.componentTypes = Objects.requireNonNull(componentTypes); this.computeDigest(); } 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 8cc878324d75..2b378479f0d5 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 @@ -19,36 +19,34 @@ import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.sql.type.AbstractSqlType; import org.apache.calcite.sql.type.SqlTypeName; -import org.apache.commons.lang3.ObjectUtils; import java.util.Collections; import java.util.List; import java.util.Objects; /** - * introduce a new map type to allow different value types in a single 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 RelDataType keyType; + private final List keyTypes; private final List valueTypes; protected ArbitraryMapType( - RelDataType keyType, List valueTypes, boolean isNullable) { + List keyTypes, List valueTypes, boolean isNullable) { super(SqlTypeName.MAP, isNullable, null); - this.keyType = Objects.requireNonNull(keyType); - this.valueTypes = ObjectUtils.requireNonEmpty(valueTypes); + this.keyTypes = Objects.requireNonNull(keyTypes); + this.valueTypes = Objects.requireNonNull(valueTypes); this.computeDigest(); } @Override protected void generateTypeString(StringBuilder sb, boolean withDetail) { - sb.append("(" + keyType.toString() + ", " + valueTypes.toString() + ") MAP"); + sb.append("(" + keyTypes.toString() + ", " + valueTypes.toString() + ") MAP"); } - @Override - public RelDataType getKeyType() { - return this.keyType; + public List getKeyTypes() { + return Collections.unmodifiableList(this.keyTypes); } public List getValueTypes() { 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 6e886b4e0560..c73ac7e6a1ca 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 @@ -71,7 +71,7 @@ public RelDataType createArbitraryArrayType( } public RelDataType createArbitraryMapType( - RelDataType keyType, List valueTypes, boolean isNullable) { - return new ArbitraryMapType(keyType, valueTypes, isNullable); + List keyTypes, List valueTypes, boolean isNullable) { + return new ArbitraryMapType(keyTypes, valueTypes, isNullable); } } 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 0c0afc734a73..66bde8437c6a 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 @@ -98,7 +98,7 @@ protected AnyValue parseEntry(IrResult.Entry entry, @Nullable RelDataType dataTy } else if (dataType instanceof ArbitraryMapType) { return parseKeyValues( entry.getMap(), - dataType.getKeyType(), + ((ArbitraryMapType) dataType).getKeyTypes(), ((ArbitraryMapType) dataType).getValueTypes()); } default: @@ -190,7 +190,9 @@ protected AnyValue parseKeyValues( } protected AnyValue parseKeyValues( - IrResult.KeyValues keyValues, RelDataType keyType, List valueTypes) { + IrResult.KeyValues keyValues, + List keyTypes, + List valueTypes) { List entries = keyValues.getKeyValuesList(); Preconditions.checkArgument( entries.size() == valueTypes.size(),