beliefer commented on a change in pull request #35060:
URL: https://github.com/apache/spark/pull/35060#discussion_r783658998



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/NumberUtils.scala
##########
@@ -18,52 +18,76 @@
 package org.apache.spark.sql.catalyst.util
 
 import java.math.BigDecimal
-import java.text.{DecimalFormat, NumberFormat, ParsePosition}
+import java.text.{DecimalFormat, ParsePosition}
 import java.util.Locale
 
+import org.apache.spark.sql.AnalysisException
+import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
 import org.apache.spark.sql.errors.{QueryCompilationErrors, 
QueryExecutionErrors}
 import org.apache.spark.sql.types.Decimal
 import org.apache.spark.unsafe.types.UTF8String
 
 object NumberUtils {
 
-  private val pointSign = '.'
-  private val letterPointSign = 'D'
-  private val commaSign = ','
-  private val letterCommaSign = 'G'
-  private val minusSign = '-'
-  private val letterMinusSign = 'S'
-  private val dollarSign = '$'
+  private final val POINT_SIGN = '.'
+  private final val POINT_LETTER = 'D'
+  private final val COMMA_SIGN = ','
+  private final val COMMA_LETTER = 'G'
+  private final val MINUS_SIGN = '-'
+  private final val MINUS_LETTER = 'S'
+  private final val DOLLAR_SIGN = '$'
+  private final val NINE_DIGIT = '9'
+  private final val ZERO_DIGIT = '0'
+  private final val POUND_SIGN = '#'
 
-  private val commaSignStr = commaSign.toString
+  private final val COMMA_SIGN_STRING = COMMA_SIGN.toString
+  private final val POUND_SIGN_STRING = POUND_SIGN.toString
 
+  private final val SIGN_SET = Set(POINT_SIGN, COMMA_SIGN, MINUS_SIGN, 
DOLLAR_SIGN)
+
+  /**
+   * DecimalFormat provides '#' and '0' as placeholder of digit, ',' as 
grouping separator,
+   * '.' as decimal separator, '-' as minus, '$' as dollar, but not '9', 'G', 
'D', 'S'. So we need
+   * replace them show below:
+   * 1. '9' -> '#'
+   * 2. 'G' -> ','
+   * 3. 'D' -> '.'
+   * 4. 'S' -> '-'
+   *
+   * Note: When calling format, we must preserve the digits after decimal 
point, so the digits
+   * after decimal point should be replaced as '0'. For example: '999.9' will 
be normalized as
+   * '###.0' and '999.99' will be normalized as '###.00', so if the input is 
454, the format
+   * output will be 454.0 and 454.00 respectively.
+   *
+   * @param format number format string
+   * @return normalized number format string
+   */
   private def normalize(format: String): String = {
-    var notFindDecimalPoint = true
+    var flag = true

Review comment:
       OK




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