Github user cloud-fan commented on a diff in the pull request: https://github.com/apache/spark/pull/22544#discussion_r220531899 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala --- @@ -974,6 +974,33 @@ object TypeCoercion { if !Cast.forceNullable(fromType, toType) => implicitCast(fromType, toType).map(ArrayType(_, false)).orNull + // Implicit cast between Map types. + // Follows the same semantics of implicit casting between two array types. + // Refer to documentation above. + case (MapType(fromKeyType, fromValueType, fn), MapType(toKeyType, toValueType, true)) + if !Cast.forceNullable(fromKeyType, toKeyType) => + val newKeyType = implicitCast(fromKeyType, toKeyType).orNull + val newValueType = implicitCast(fromValueType, toValueType).orNull + if (newKeyType != null && newValueType != null) { + MapType(newKeyType, newValueType, true) + } else { + null + } + + case (MapType(fromKeyType, fromValueType, true), MapType(toKeyType, toValueType, false)) => + null + + case (MapType(fromKeyType, fromValueType, false), MapType(toKeyType, toValueType, false)) + if (!(Cast.forceNullable(fromKeyType, toKeyType) || + Cast.forceNullable(fromValueType, toValueType))) => + val newKeyType = implicitCast(fromKeyType, toKeyType).orNull + val newValueType = implicitCast(fromValueType, toValueType).orNull + if (newKeyType != null && newValueType != null) { + MapType(newKeyType, newValueType, false) + } else { + null + } + --- End diff -- nit: ``` case (MapType(fromKeyType, fromValueType, fromNullable), MapType(toKeyType, toValueType, toNullable)) if !Cast.forceNullable(fromKeyType, toKeyType) && Cast.resolvableNullability(fromNullable, toNullable) .... if (Cast.forceNullable(fromValueType, toValueType) $$ !toNullable) { null } else { MapType(newKeyType, newValueType, toNullable) } ```
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org