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_r333041292
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
##########
@@ -2267,6 +2267,215 @@ case class FormatNumber(x: Expression, d: Expression)
override def prettyName: String = "format_number"
}
+/**
+ * A function that converts string to numeric.
+ */
+// scalastyle:off line.size.limit
+@ExpressionDescription(
+ usage = """
+ _FUNC_(strExpr, patternExpr) - Convert a string to a number based on the
pattern.
+ The pattern 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)
+ 'L': currency symbol (uses locale)
+ 'D': decimal point (uses locale)
+ 'G': group separator (uses locale)
+ """,
+ examples = """
+ Examples:
+ > SELECT _FUNC_('4540', '999');
+ 454
+ > SELECT _FUNC_('454.00', '000D00');
+ 454
+ > SELECT _FUNC_('12,454.8-', '99G999D9S');
+ -12454.8
+ > SELECT _FUNC_('CNY234234.4350', 'L999999.0000');
+ 234234.435
+ """)
+// scalastyle:on line.size.limit
+case class ToNumber(strExpr: Expression, patternExpr: Expression)
+ extends BinaryExpression with ImplicitCastInputTypes {
+
+ // scalastyle:off caselocale
+ private lazy val patternStr =
patternExpr.eval().asInstanceOf[UTF8String].toUpperCase.toString
Review comment:
Here, you assume that `patternExpr` is foldable expression, correct? What
happens if it is not. You can see there how to handle both cases:
https://github.com/apache/spark/blob/eecef75350efda3efa7c5acb3b5eaa0d2fc8a552/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala#L615-L619
----------------------------------------------------------------
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]