Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7202#discussion_r33886006
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala
 ---
    @@ -713,39 +715,68 @@ object HiveTypeCoercion {
     
           case e: ExpectsInputTypes =>
             val children: Seq[Expression] = e.children.zip(e.inputTypes).map { 
case (in, expected) =>
    -          implicitCast(in, expected)
    +          // If we cannot do the implicit cast, just use the original 
input.
    +          implicitCast(in, expected).getOrElse(in)
             }
             e.withNewChildren(children)
         }
     
         /**
    -     * If needed, cast the expression into the expected type.
    -     * If the implicit cast is not allowed, return the expression itself.
    +     * Given an expected data type, try to cast the expression and return 
the cast expression.
    +     *
    +     * If the expression already fits the input type, we simply return the 
expression itself.
    +     * If the expression has an incompatible type that cannot be 
implicitly cast, return None.
          */
    -    def implicitCast(e: Expression, expectedType: AbstractDataType): 
Expression = {
    +    def implicitCast(e: Expression, expectedType: AbstractDataType): 
Option[Expression] = {
           val inType = e.dataType
    -      (inType, expectedType) match {
    +
    +      // Note that ret is nullable to avoid typing a lot of Some(...) in 
this local scope.
    +      // We wrap immediately an Option after this.
    +      @Nullable val ret: Expression = (inType, expectedType) match {
    +
    +        // If the expected type is already a parent of the input type, no 
need to cast.
    +        case _ if expectedType.isParentOf(inType) => e
    +
             // Cast null type (usually from null literals) into target types
    -        case (NullType, target: DataType) => Cast(e, 
target.defaultConcreteType)
    +        case (NullType, target) => Cast(e, target.defaultConcreteType)
     
             // Implicit cast among numeric types
    +        // If input is decimal, and we expect a decimal type, just use the 
input.
    +        case (_: DecimalType, DecimalType) => e
    --- End diff --
    
    This is not needed? We have defined `isParentOf` in `DecimalType`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to