cloud-fan commented on a change in pull request #35060:
URL: https://github.com/apache/spark/pull/35060#discussion_r781181319
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/NumberUtils.scala
##########
@@ -77,57 +101,61 @@ object NumberUtils {
signIndex > 0 && signIndex < format.length - 1
}
- if (normalizedFormat.count(_ == pointSign) > 1) {
+ if (normalizedFormat.length == 0) {
+ throw QueryCompilationErrors.emptyNumberFormatError()
+ } else if (normalizedFormat.count(_ == POINT_SIGN) > 1) {
throw QueryCompilationErrors.multipleSignInNumberFormatError(
- s"'$letterPointSign' or '$pointSign'", numberFormat)
- } else if (normalizedFormat.count(_ == minusSign) > 1) {
+ s"'$POINT_LETTER' or '$POINT_SIGN'", numberFormat)
+ } else if (normalizedFormat.count(_ == MINUS_SIGN) > 1) {
throw QueryCompilationErrors.multipleSignInNumberFormatError(
- s"'$letterMinusSign' or '$minusSign'", numberFormat)
- } else if (normalizedFormat.count(_ == dollarSign) > 1) {
- throw
QueryCompilationErrors.multipleSignInNumberFormatError(s"'$dollarSign'",
numberFormat)
- } else if (invalidSignPosition(normalizedFormat, minusSign)) {
+ s"'$MINUS_LETTER' or '$MINUS_SIGN'", numberFormat)
+ } else if (normalizedFormat.count(_ == DOLLAR_SIGN) > 1) {
+ throw
QueryCompilationErrors.multipleSignInNumberFormatError(s"'$DOLLAR_SIGN'",
numberFormat)
+ } else if (invalidSignPosition(normalizedFormat, MINUS_SIGN)) {
throw QueryCompilationErrors.nonFistOrLastCharInNumberFormatError(
- s"'$letterMinusSign' or '$minusSign'", numberFormat)
- } else if (invalidSignPosition(normalizedFormat, dollarSign)) {
+ s"'$MINUS_LETTER' or '$MINUS_SIGN'", numberFormat)
+ } else if (invalidSignPosition(normalizedFormat, DOLLAR_SIGN)) {
throw QueryCompilationErrors.nonFistOrLastCharInNumberFormatError(
- s"'$dollarSign'", numberFormat)
+ s"'$DOLLAR_SIGN'", numberFormat)
+ }
+ }
+
+ private def getPrecision(numberFormat: String): Int =
+ numberFormat.filterNot(isSign).length
+
+ private def getScale(numberFormat: String): Int = {
+ val formatSplits = numberFormat.split(POINT_SIGN)
+ if (formatSplits.length == 1) {
+ 0
+ } else {
+ formatSplits(1).filterNot(isSign).length
}
}
/**
* Convert string to numeric based on the given number format.
* The format can consist of the following characters:
- * '9': digit position (can be dropped if insignificant)
- * '0': digit position (will not be dropped, even if insignificant)
- * '.': decimal point (only allowed once)
- * ',': group (thousands) separator
- * 'S': sign anchored to number (uses locale)
- * 'D': decimal point (uses locale)
- * 'G': group separator (uses locale)
- * '$': specifies that the input value has a leading $ (Dollar) sign.
+ * '0' or '9': digit position
+ * '.' or 'D': decimal point (only allowed once)
+ * ',' or 'G': group (thousands) separator
+ * '-' or 'S': sign anchored to number
+ * '$': returns value with a leading dollar sign
Review comment:
`returns`? This is `def parse`
--
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]