xkrogen commented on code in PR #37389:
URL: https://github.com/apache/spark/pull/37389#discussion_r936853437


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -1036,12 +1036,8 @@ object SimplifyCasts extends Rule[LogicalPlan] {
 
   // Returns whether the from DataType can be safely casted to the to DataType 
without losing
   // any precision or range.
-  private def isWiderCast(from: DataType, to: NumericType): Boolean = (from, 
to) match {
-    case (from: NumericType, to: DecimalType) if to.isWiderThan(from) => true
-    case (from: DecimalType, to: NumericType) if from.isTighterThan(to) => true
-    case (from: IntegralType, to: IntegralType) => Cast.canUpCast(from, to)
-    case _ => from == to

Review Comment:
   This refactor changes the behavior when `from` is non-numeric and `from == 
to`. Previously returns true, now false. Is this intentional?
   
   To preserve behavior, and be more Scala-idiomatic by using pattern matching 
instead of `isInstanceOf`, I would suggest:
   ```scala
     private def isWiderCast(from: DataType, to: NumericType): Boolean = from 
match {
       case NumericType => Cast.canUpCast(from, to)
       case _ => from == to
     }
   ```



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