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/06/21 22:58:26 UTC

[GitHub] [spark] dtenedor commented on a diff in pull request #36950: [SPARK-38796][SQL] Update documentation for number format strings with the {try_}to_number functions

dtenedor commented on code in PR #36950:
URL: https://github.com/apache/spark/pull/36950#discussion_r903134910


##########
docs/sql-ref-number-pattern.md:
##########
@@ -19,4 +19,101 @@ license: |
   limitations under the License.
 ---
 
-TODO: Add the content of Number Patterns for Formatting and Parsing
+### Description
+
+Functions such as `to_number` and `try_to_number` support converting between values of string and
+Decimal type. Such functions accept format strings indicating how to map between these types.
+
+### Syntax

Review Comment:
   Sure, this sounds good. Added this to the docs.



##########
docs/sql-ref-number-pattern.md:
##########
@@ -19,4 +19,101 @@ license: |
   limitations under the License.
 ---
 
-TODO: Add the content of Number Patterns for Formatting and Parsing
+### Description
+
+Functions such as `to_number` and `try_to_number` support converting between values of string and
+Decimal type. Such functions accept format strings indicating how to map between these types.
+
+### Syntax
+
+Number format strings support the following syntax:
+```
+  { ' [ S ] [ L | $ ] 
+      [ 0 | 9 | G | , ] [...] 
+      [ . | D ] 
+      [ 0 | 9 ] [...] 
+      [ L | $ ] [ PR | MI | S ] ' }
+```
+
+### Elements
+
+Each number format string can contain the following elements (case insensitive):
+
+- **`0`** or **`9`**
+
+  Specifies an expected digit between `0` and `9`.
+
+  A `0` to the left of the decimal point indicates that at least this many digits must be present.
+
+  A leading `9` indicates that these digits are optional.
+
+  The input value must not be larger than the number of digits to the left of the decimal point 
+  allowed by the format string.
+
+  Digits to the right of the decimal point in the format string indicate the most digits that the
+  input value may have to the right of the decimal point.
+
+- **`.`** or **`D`**
+
+  Specifies the position of the decimal point.
+
+  The input value does not need to include a decimal point.
+
+- **`,`** or **`G`**
+
+  Specifies the position of the `,` grouping (thousands) separator.
+
+  There must be a `0` or `9` to the left and right of each grouping separator. 
+
+- **`$`**
+
+  Specifies the location of the `$` currency sign. This character may only be specified once.
+
+- **`S`** 
+
+  Specifies the position of an optional '+' or '-' sign. This character may only be specified once.
+
+- **`MI`**
+
+  Specifies an optional `-` sign at the end, but no `+`.
+
+- **`PR`**
+
+  Maps negative input values to wrapping angle brackets (`<1>`) in the corresponding string.
+
+  Positive input values do not receive wrapping angle brackets.
+
+### Examples
+
+The following examples use the `try_to_number` SQL function which accepts an input string as the

Review Comment:
   Added this to the examples section at the end.



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