dtenedor commented on code in PR #60734:
URL: https://github.com/apache/spark/pull/60734#discussion_r4648753383


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/numberFormatExpressions.scala:
##########
@@ -312,7 +313,10 @@ case class ToCharacter(left: Expression, right: Expression)
   private lazy val numberFormatter = {
     val value = right.eval()
     if (value != null) {
-      new ToNumberParser(value.toString.toUpperCase(Locale.ROOT), true)
+      new ToNumberParser(
+        value.toString.toUpperCase(Locale.ROOT),
+        errorOnFail = true,
+        legacyFormatZeroAsBlank = 
SQLConf.get.getConf(SQLConf.LEGACY_TO_CHAR_FORMAT_ZERO_AS_BLANK))

Review Comment:
   Thanks, good catch. Fixed in f372961ee53f53dbbf66338778a916134a8b2234:
   
   - `ToCharacter` now takes `legacyFormatZeroAsBlank` as a constructor 
parameter, read from `spark.sql.legacy.toChar.formatZeroAsBlank` when the 
expression is built (same pattern as `Abs.failOnError`). `copy` in 
`withNewChildrenInternal` keeps it, and the formatter uses it instead of 
reading the conf lazily.
   - Expressions built under different values are no longer `semanticEquals`, 
so `CacheManager` won't substitute results across settings. `flatArguments` 
still lists only `left` and `right`, so plan strings and golden files don't 
change.
   - Added your scenario as a test in `StringFunctionsSuite`. It failed before 
this change (the second query returned `'  0'` from the cache) and passes now. 
`StringExpressionsSuite` also checks that the value is captured at construction 
time, survives `withNewChildren`, and makes the two expressions not 
semantically equal.
   



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