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

    https://github.com/apache/spark/pull/6551#discussion_r31798086
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala
 ---
    @@ -59,6 +59,42 @@ object HiveTypeCoercion {
       }
     
       /**
    +   * Implicit promote the DataType to StringType if
    +   * one of the data type in (dt1, dt2) is StringType, and the other is 
not either
    +   * BooleanType or BinaryType, the TightestCommonType should be StringType
    +   * eg: 1. CaseWhenLike  case when ... then dt1 else dt2 end
    +   *     2. Coalesce(null, dt1, dt2)
    +
    +   */
    +  val promoteToStringTypeOfTwo: (DataType, DataType) => Option[DataType] = 
{
    +    case (t1: StringType, t2: DataType) if (t2 != BinaryType && t2 != 
BooleanType) =>
    +      Some(StringType)
    +
    +    case (t1: DataType, t2: StringType) if (t1 != BinaryType && t1 != 
BooleanType) =>
    +      Some(StringType)
    +
    +    case _ => None
    +  }
    +
    +  /**
    +   * Find the tightest common type of a set of types by continuously 
applying
    +   * `findTightestCommonTypeOfTwo` on these types.
    +   */
    +  private def findTightestCommonTypeAndTryPromoteToString(types: 
Seq[DataType]) = {
    +    types.foldLeft[Option[DataType]](Some(NullType))((r, c) => r match {
    +      case None => None
    +      case Some(d) =>
    +        val dt = findTightestCommonTypeOfTwo(d, c)
    +        if (dt == None) {
    +          promoteToStringTypeOfTwo(d, c)
    +        } else {
    +          dt
    --- End diff --
    
    `findTightestCommonTypeOfTwo(d, c).orElse(promoteToStringTypeOfTwo(d, c))`?


---
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