[Improve](map) support map cast with map literal and implicate nested scala cast (#26126)
This commit is contained in:
@ -192,8 +192,10 @@ public class MapType extends Type {
|
||||
}
|
||||
|
||||
public static boolean canCastTo(MapType type, MapType targetType) {
|
||||
return Type.canCastTo(type.getKeyType(), targetType.getKeyType())
|
||||
&& Type.canCastTo(type.getValueType(), targetType.getValueType());
|
||||
return (targetType.getKeyType().isStringType() && type.getKeyType().isStringType()
|
||||
|| Type.canCastTo(type.getKeyType(), targetType.getKeyType()))
|
||||
&& (Type.canCastTo(type.getValueType(), targetType.getValueType())
|
||||
|| targetType.getValueType().isStringType() && type.getValueType().isStringType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -2169,6 +2169,17 @@ public abstract class Type {
|
||||
return false;
|
||||
}
|
||||
return matchExactType(((ArrayType) type2).getItemType(), ((ArrayType) type1).getItemType());
|
||||
} else if (type2.isMapType()) {
|
||||
// For types array, we also need to check contains null for case like
|
||||
// cast(array<not_null(int)> as array<int>)
|
||||
if (!((MapType) type2).getIsKeyContainsNull() == ((MapType) type1).getIsKeyContainsNull()) {
|
||||
return false;
|
||||
}
|
||||
if (!((MapType) type2).getIsValueContainsNull() == ((MapType) type1).getIsValueContainsNull()) {
|
||||
return false;
|
||||
}
|
||||
return matchExactType(((MapType) type2).getKeyType(), ((MapType) type1).getKeyType())
|
||||
&& matchExactType(((MapType) type2).getValueType(), ((MapType) type1).getValueType());
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user