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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala:
##########
@@ -1999,28 +2017,13 @@ case class Cast(
       }).getClass.getCanonicalName.stripSuffix("$")
       (c, evPrim, _) => code"$evPrim = $numericObj.toInt($c);"
     } else {
-      val fromDt = ctx.addReferenceObj("from", from, from.getClass.getName)
-      val toDt = ctx.addReferenceObj("to", to, to.getClass.getName)
-      (c, evPrim, _) =>
-        code"""
-          if ($c == ($integralType) $c) {
-            $evPrim = ($integralType) $c;
-          } else {
-            throw QueryExecutionErrors.castingCauseOverflowError($c, $fromDt, 
$toDt);
-          }
-        """
-    }
-  }
-
-
-  private[this] def lowerAndUpperBound(integralType: String): (String, String) 
= {
-    val (min, max, typeIndicator) = integralType.toLowerCase(Locale.ROOT) 
match {
-      case "long" => (Long.MinValue, Long.MaxValue, "L")
-      case "int" => (Int.MinValue, Int.MaxValue, "")
-      case "short" => (Short.MinValue, Short.MaxValue, "")
-      case "byte" => (Byte.MinValue, Byte.MaxValue, "")
+      // Byte / short narrowing: call the matching CastUtils helper. Existing 
*ExactNumeric
+      // objects don't expose cross-type narrowing to byte / short (their 
toByte / toShort are
+      // same-type identities), so a Java helper is the cleanest fit.
+      val castUtils = classOf[CastUtils].getName

Review Comment:
   nit (optional, fine to defer to a follow-up): now that this else-branch no 
longer calls `ctx.addReferenceObj("from"/"to", ...)`, both `ctx: 
CodegenContext` and `to: DataType` are unused in 
`castIntegralTypeToIntegralTypeExactCode` — and the same is true for 
`castFractionToIntegralTypeCode` just below. Since the SPARK-56908 series is 
about simplification, it would be consistent to drop both params from both 
helpers (and from the 5+5 = 10 call sites). Up to you whether to do it here or 
as a tiny follow-up.



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