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

    https://github.com/apache/spark/pull/21470#discussion_r192314292
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
 ---
    @@ -803,18 +803,60 @@ object TypeCoercion {
               e.copy(left = Cast(e.left, TimestampType))
             }
     
    -      case b @ BinaryOperator(left, right) if left.dataType != 
right.dataType =>
    -        findTightestCommonType(left.dataType, right.dataType).map { 
commonType =>
    -          if (b.inputType.acceptsType(commonType)) {
    -            // If the expression accepts the tightest common type, cast to 
that.
    -            val newLeft = if (left.dataType == commonType) left else 
Cast(left, commonType)
    -            val newRight = if (right.dataType == commonType) right else 
Cast(right, commonType)
    -            b.withNewChildren(Seq(newLeft, newRight))
    -          } else {
    -            // Otherwise, don't do anything with the expression.
    -            b
    -          }
    -        }.getOrElse(b)  // If there is no applicable conversion, leave 
expression unchanged.
    +      case b @ BinaryOperator(left, right)
    +          if !BinaryOperator.sameType(left.dataType, right.dataType) =>
    +        (left.dataType, right.dataType) match {
    +          case (StructType(fields1), StructType(fields2)) =>
    +            val commonTypes = 
scala.collection.mutable.ArrayBuffer.empty[DataType]
    +            val len = fields1.length
    +            var i = 0
    +            var continue = fields1.length == fields2.length
    +            while (i < len && continue) {
    +              val commonType = findTightestCommonType(fields1(i).dataType, 
fields2(i).dataType)
    --- End diff --
    
    What about nested structs?


---

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

Reply via email to