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


##########
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:
   **[P1] Include the legacy flag in ToCharacter's expression identity**
   
   The setting changes results but exists only inside the lazy formatter: the 
`ToCharacter` case class still contains only `left` and `right`. Consequently, 
expressions analyzed with opposite settings have identical canonicalized forms. 
`CacheManager.lookupCachedDataInternal` matches plans using 
`QueryPlan.sameResult`, which compares those forms, so a fresh query can reuse 
results produced under the opposite setting. Capture the resolved flag as a 
case-class parameter and preserve it through expression copies so cache 
matching distinguishes the two behaviors.
   
   **Failure scenario:** With the flag false, materialize `spark.sql("SELECT 
to_char(id, '999') AS s FROM range(1)").cache().collect()`, producing '  0'. 
Set spark.sql.legacy.toChar.formatZeroAsBlank=true and execute the same SQL as 
a fresh DataFrame. Cache substitution returns '  0' instead of the required '   
', defeating the legacy switch.



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