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

    https://github.com/apache/spark/pull/7511#discussion_r34966304
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala
 ---
    @@ -362,47 +362,59 @@ object HiveTypeCoercion {
           DoubleType -> DecimalType(15, 15)
         )
     
    -    def apply(plan: LogicalPlan): LogicalPlan = plan transform {
    -      // fix decimal precision for union
    -      case u @ Union(left, right) if u.childrenResolved && !u.resolved =>
    -        val castedInput = left.output.zip(right.output).map {
    -          case (lhs, rhs) if lhs.dataType != rhs.dataType =>
    -            (lhs.dataType, rhs.dataType) match {
    -              case (DecimalType.Fixed(p1, s1), DecimalType.Fixed(p2, s2)) 
=>
    -                // Union decimals with precision/scale p1/s2 and p2/s2  
will be promoted to
    -                // DecimalType(max(s1, s2) + max(p1-s1, p2-s2), max(s1, 
s2))
    -                val fixedType = DecimalType(max(s1, s2) + max(p1 - s1, p2 
- s2), max(s1, s2))
    -                (Alias(Cast(lhs, fixedType), lhs.name)(), Alias(Cast(rhs, 
fixedType), rhs.name)())
    -              case (t, DecimalType.Fixed(p, s)) if 
intTypeToFixed.contains(t) =>
    -                (Alias(Cast(lhs, intTypeToFixed(t)), lhs.name)(), rhs)
    -              case (DecimalType.Fixed(p, s), t) if 
intTypeToFixed.contains(t) =>
    -                (lhs, Alias(Cast(rhs, intTypeToFixed(t)), rhs.name)())
    -              case (t, DecimalType.Fixed(p, s)) if 
floatTypeToFixed.contains(t) =>
    -                (Alias(Cast(lhs, floatTypeToFixed(t)), lhs.name)(), rhs)
    -              case (DecimalType.Fixed(p, s), t) if 
floatTypeToFixed.contains(t) =>
    -                (lhs, Alias(Cast(rhs, floatTypeToFixed(t)), rhs.name)())
    -              case _ => (lhs, rhs)
    -            }
    -          case other => other
    -        }
    +    private def castDecimalPrecision(
    +        left: LogicalPlan,
    +        right: LogicalPlan): (LogicalPlan, LogicalPlan) = {
    +      val castedInput = left.output.zip(right.output).map {
    +        case (lhs, rhs) if lhs.dataType != rhs.dataType =>
    +          (lhs.dataType, rhs.dataType) match {
    +            case (DecimalType.Fixed(p1, s1), DecimalType.Fixed(p2, s2)) =>
    +              // Union decimals with precision/scale p1/s2 and p2/s2  will 
be promoted to
    --- End diff --
    
    nit: update the `Union` in comments.


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