Skip to content
Snippets Groups Projects
Commit cb8c241f authored by Reynold Xin's avatar Reynold Xin
Browse files

[SPARK-9200][SQL] Don't implicitly cast non-atomic types to string type.

Author: Reynold Xin <rxin@databricks.com>

Closes #7636 from rxin/complex-string-implicit-cast and squashes the following commits:

3e67327 [Reynold Xin] [SPARK-9200][SQL] Don't implicitly cast non-atomic types to string type.
parent 408e64b2
No related branches found
No related tags found
No related merge requests found
...@@ -720,7 +720,8 @@ object HiveTypeCoercion { ...@@ -720,7 +720,8 @@ object HiveTypeCoercion {
case (StringType, DateType) => Cast(e, DateType) case (StringType, DateType) => Cast(e, DateType)
case (StringType, TimestampType) => Cast(e, TimestampType) case (StringType, TimestampType) => Cast(e, TimestampType)
case (StringType, BinaryType) => Cast(e, BinaryType) case (StringType, BinaryType) => Cast(e, BinaryType)
case (any, StringType) if any != StringType => Cast(e, StringType) // Cast any atomic type to string.
case (any: AtomicType, StringType) if any != StringType => Cast(e, StringType)
// When we reach here, input type is not acceptable for any types in this type collection, // When we reach here, input type is not acceptable for any types in this type collection,
// try to find the first one we can implicitly cast. // try to find the first one we can implicitly cast.
......
...@@ -115,6 +115,14 @@ class HiveTypeCoercionSuite extends PlanTest { ...@@ -115,6 +115,14 @@ class HiveTypeCoercionSuite extends PlanTest {
shouldNotCast(IntegerType, ArrayType) shouldNotCast(IntegerType, ArrayType)
shouldNotCast(IntegerType, MapType) shouldNotCast(IntegerType, MapType)
shouldNotCast(IntegerType, StructType) shouldNotCast(IntegerType, StructType)
shouldNotCast(IntervalType, StringType)
// Don't implicitly cast complex types to string.
shouldNotCast(ArrayType(StringType), StringType)
shouldNotCast(MapType(StringType, StringType), StringType)
shouldNotCast(new StructType().add("a1", StringType), StringType)
shouldNotCast(MapType(StringType, StringType), StringType)
} }
test("tightest common bound for types") { test("tightest common bound for types") {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment