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

    https://github.com/apache/spark/pull/7605#discussion_r35397247
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala
 ---
    @@ -166,55 +171,50 @@ object HiveTypeCoercion {
        * - IntegerType to FloatType
        * - LongType to FloatType
        * - LongType to DoubleType
    +   * - DecimalType to Double
    +   *
    +   * This rule is only applied to Union/Except/Intersect
        */
       object WidenTypes extends Rule[LogicalPlan] {
     
    -    private[this] def widenOutputTypes(planName: String, left: 
LogicalPlan, right: LogicalPlan):
    -        (LogicalPlan, LogicalPlan) = {
    -
    -      // TODO: with fixed-precision decimals
    -      val castedInput = left.output.zip(right.output).map {
    -        // When a string is found on one side, make the other side a 
string too.
    -        case (lhs, rhs) if lhs.dataType == StringType && rhs.dataType != 
StringType =>
    -          (lhs, Alias(Cast(rhs, StringType), rhs.name)())
    -        case (lhs, rhs) if lhs.dataType != StringType && rhs.dataType == 
StringType =>
    -          (Alias(Cast(lhs, StringType), lhs.name)(), rhs)
    +    private[this] def widenOutputTypes(
    +        planName: String,
    +        left: LogicalPlan,
    +        right: LogicalPlan): (LogicalPlan, LogicalPlan) = {
     
    +      val castedTypes = left.output.zip(right.output).map {
             case (lhs, rhs) if lhs.dataType != rhs.dataType =>
    -          logDebug(s"Resolving mismatched $planName input ${lhs.dataType}, 
${rhs.dataType}")
    -          findTightestCommonTypeOfTwo(lhs.dataType, rhs.dataType).map { 
widestType =>
    -            val newLeft =
    -              if (lhs.dataType == widestType) lhs else Alias(Cast(lhs, 
widestType), lhs.name)()
    -            val newRight =
    -              if (rhs.dataType == widestType) rhs else Alias(Cast(rhs, 
widestType), rhs.name)()
    -
    -            (newLeft, newRight)
    -          }.getOrElse {
    -            // If there is no applicable conversion, leave expression 
unchanged.
    -            (lhs, rhs)
    +          (lhs.dataType, rhs.dataType) match {
    +            case (t1: DecimalType, t2: DecimalType) =>
    +              Some(DecimalPrecision.widerDecimalType(t1, t2))
    +            case (t: IntegralType, d: DecimalType) =>
    +              
Some(DecimalPrecision.widerDecimalType(DecimalType.forType(t), d))
    +            case (d: DecimalType, t: IntegralType) =>
    +              
Some(DecimalPrecision.widerDecimalType(DecimalType.forType(t), d))
    +            case (t: FractionalType, d: DecimalType) =>
    +              Some(DoubleType)
    +            case (d: DecimalType, t: FractionalType) =>
    +              Some(DoubleType)
    +            case _ =>
    +              findTightestCommonTypeToString(lhs.dataType, rhs.dataType)
               }
    -
    -        case other => other
    +        case other => None
           }
     
    -      val (castedLeft, castedRight) = castedInput.unzip
    -
    -      val newLeft =
    -        if (castedLeft.map(_.dataType) != left.output.map(_.dataType)) {
    -          logDebug(s"Widening numeric types in $planName $castedLeft 
${left.output}")
    -          Project(castedLeft, left)
    -        } else {
    -          left
    +      def castOutput(plan: LogicalPlan): LogicalPlan = {
    +        val casted = plan.output.zip(castedTypes).map {
    +          case (hs, Some(dt)) if dt != hs.dataType =>
    --- End diff --
    
    ic; lhs = left hand side. hs doesn't mean anything here.


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