Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22544#discussion_r220460094
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionSuite.scala
 ---
    @@ -257,12 +257,48 @@ class TypeCoercionSuite extends AnalysisTest {
         shouldNotCast(checkedType, IntegralType)
       }
     
    -  test("implicit type cast - MapType(StringType, StringType)") {
    -    val checkedType = MapType(StringType, StringType)
    -    checkTypeCasting(checkedType, castableTypes = Seq(checkedType))
    -    shouldNotCast(checkedType, DecimalType)
    -    shouldNotCast(checkedType, NumericType)
    -    shouldNotCast(checkedType, IntegralType)
    +  test("implicit type cast between two Map types") {
    +    val sourceType = MapType(IntegerType, IntegerType, true)
    +    val castableTypes = numericTypes ++ 
Seq(StringType).filter(!Cast.forceNullable(IntegerType, _))
    +    val targetTypes = numericTypes.filter(!Cast.forceNullable(IntegerType, 
_)).map { t =>
    +      MapType(t, sourceType.valueType, valueContainsNull = true)
    +    }
    +    val nonCastableTargetTypes = 
allTypes.filterNot(castableTypes.contains(_)).map {t =>
    +      MapType(t, sourceType.valueType, valueContainsNull = true)
    +    }
    +
    +    // Tests that its possible to setup implicit casts between two map 
types when
    +    // source map's key type is integer and the target map's key type are 
either Byte, Short,
    +    // Long, Double, Float, Decimal(38, 18) or String.
    +    targetTypes.foreach { targetType =>
    +      shouldCast(sourceType, targetType, targetType)
    +    }
    +
    +    // Tests that its not possible to setup implicit casts between two map 
types when
    +    // source map's key type is integer and the target map's key type are 
either Binary,
    +    // Boolean, Date, Timestamp, Array, Struct, CaleandarIntervalType or 
NullType
    +    nonCastableTargetTypes.foreach { targetType =>
    +      shouldNotCast(sourceType, targetType)
    +    }
    +
    +    // Tests that its not possible to cast from nullable map type to not 
nullable map type.
    +    val targetNotNullableTypes = allTypes.filterNot(_ == IntegerType).map 
{ t =>
    +      MapType(t, sourceType.valueType, valueContainsNull = false)
    +    }
    +    val sourceMapExprWithValueNull =
    +      CreateMap(Seq(Literal.default(sourceType.keyType),
    +        Literal.create(null, sourceType.valueType)))
    +    targetNotNullableTypes.foreach { targetType =>
    +      val x = 10
    +      val castDefault =
    +        
TypeCoercion.ImplicitTypeCasts.implicitCast(sourceMapExprWithValueNull, 
targetType)
    +      assert(castDefault.isEmpty,
    +        s"Should not be able to cast $sourceType to $sourceType, but got 
$castDefault")
    +    }
    +
    +    shouldNotCast(MapType(DoubleType, DoubleType, valueContainsNull = 
false),
    +      CalendarIntervalType)
    --- End diff --
    
    why there is a test for `CalendarIntervalType`?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to