You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/05/09 18:06:15 UTC

[GitHub] [spark] cloud-fan commented on a diff in pull request #36365: [SPARK-28516][SQL] Implement `to_char` and `try_to_char` functions to format Decimal values as strings

cloud-fan commented on code in PR #36365:
URL: https://github.com/apache/spark/pull/36365#discussion_r868281343


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/numberFormatExpressions.scala:
##########
@@ -168,3 +168,157 @@ case class TryToNumber(left: Expression, right: Expression)
       newRight: Expression): TryToNumber =
     copy(left = newLeft, right = newRight)
 }
+
+/**
+ * A function that converts decimal values to strings, returning NULL if the decimal value fails to
+ * match the format string.
+ */
+@ExpressionDescription(
+  usage = """
+    _FUNC_(numberExpr, formatExpr) - Convert `numberExpr` to a string based on the `formatExpr`.
+      Throws an exception if the conversion fails. The format can consist of the following
+      characters, case insensitive:
+        '0' or '9': Specifies an expected digit between 0 and 9. A sequence of 0 or 9 in the format
+          string matches a sequence of digits in the input value, generating a result string of the
+          same length as the corresponding sequence in the format string. The result string is
+          left-padded with zeros if the 0/9 sequence comprises more digits than the matching part of
+          the decimal value, starts with 0, and is before the decimal point.

Review Comment:
   shall we mention that it's left-padded with spaces otherwise?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org