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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala:
##########
@@ -2390,12 +2390,20 @@ case class FormatString(children: Expression*) extends 
Expression with ImplicitC
       null
     } else {
       val formatter = new java.util.Formatter(Locale.US)
-      val arglist = children.tail.map(_.eval(input).asInstanceOf[AnyRef])
+      val arglist = children.tail.map(child => 
toFormatterArg(child.eval(input)))
       UTF8String.fromString(
         formatter.format(pattern.asInstanceOf[UTF8String].toString, arglist: 
_*).toString)
     }
   }
 
+  // java.util.Formatter dispatches on the runtime class of its argument and 
has no case for
+  // Catalyst's Decimal, so %f/%e/%g reject it. java.math.BigDecimal is 
accepted and stays exact.
+  // %a stays unsupported: Formatter accepts it only for float and double.
+  private def toFormatterArg(value: Any): AnyRef = value match {
+    case d: Decimal => d.toJavaBigDecimal

Review Comment:
   Confirmed: the Decimal("1.50") %h assertion now pins the 
java.math.BigDecimal hash result.
   
   <!-- SPARK_DEV_REVIEW_REPLY 
{"feedback_id":"inline:3926331021","thread_id":"inline:3926331021","verdict_sha256":"8962b2f244b4a8a02254ee3e94fbb0fc1f898f281cfa0aba7c9b69ab4915925b"}
 -->



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