MaxGekk commented on a change in pull request #25963: [SPARK-28137][SQL] Add
Postgresql function to_number.
URL: https://github.com/apache/spark/pull/25963#discussion_r336631189
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
##########
@@ -2267,6 +2267,156 @@ case class FormatNumber(x: Expression, d: Expression)
override def prettyName: String = "format_number"
}
+object ToNumber {
+ def transfer(input: UTF8String, pattern: UTF8String): UTF8String = {
+ val inputStr = input.toString
+ val patternStr =
pattern.toString.toUpperCase(Locale.ROOT).replaceAll("FM", "")
+ val hasSign = inputStr.startsWith("-") ||
+ (patternStr.contains('S') && inputStr.contains('-')) ||
+ (patternStr.contains("MI") && inputStr.contains('-')) ||
+ (patternStr.contains("PR") && inputStr.startsWith("<"))
+ val (newInputStr, newPatternStr) = if (hasSign) {
+ (inputStr.replaceAll("-|<|>", ""),
patternStr.replaceAll("S|(MI)|(PR)|(FM)", ""))
+ } else {
+ (inputStr, patternStr.replaceAll("FM", ""))
+ }
+ val inputChars = newInputStr.toCharArray()
+ val patternChars = newPatternStr.toIterator
Review comment:
Why do you need to convert it to iterator? String's `foreach` can iterate
over chars as well.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]