cloud-fan commented on code in PR #36150:
URL: https://github.com/apache/spark/pull/36150#discussion_r927753901


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala:
##########
@@ -198,6 +198,22 @@ abstract class TypeCoercionBase {
     }
   }
 
+  /**
+   * Widens the data types of the [[Unpivot]] values.
+   */
+  object UnpivotCoercion extends Rule[LogicalPlan] {
+    override def apply(plan: LogicalPlan): LogicalPlan =
+      plan resolveOperators {
+        case up: Unpivot
+          if up.values.nonEmpty && up.values.forall(_.resolved) && 
!up.valuesTypeCoercioned =>
+          val valueDataType = 
findWiderTypeWithoutStringPromotion(up.values.map(_.dataType))
+          val values = valueDataType.map(valueType =>
+            up.values.map(value => Alias(Cast(value, valueType), value.name)())
+          ).getOrElse(up.values)
+          up.copy(values = values)
+      }

Review Comment:
   ```suggestion
       override def apply(plan: LogicalPlan): LogicalPlan = plan 
resolveOperators {
         case up: Unpivot
           if up.values.nonEmpty && up.values.forall(_.resolved) && 
!up.valuesTypeCoercioned =>
           val valueDataType = 
findWiderTypeWithoutStringPromotion(up.values.map(_.dataType))
           val values = valueDataType.map(valueType =>
             up.values.map(value => Alias(Cast(value, valueType), value.name)())
           ).getOrElse(up.values)
           up.copy(values = values)
         }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to