beliefer opened a new pull request #35269: URL: https://github.com/apache/spark/pull/35269
### What changes were proposed in this pull request? Many database support the function `to_char` to convert a number to string. The implement of `to_char` has many different between `Postgresql` ,`Oracle` and `Phoenix`. So, this PR follows the implement of `to_char` in `Oracle` that give a strict parameter verification. So, this PR follows the implement of `to_char` in `Phoenix` that uses `DecimalFormat`. This PR support the patterns for numeric formatting as follows: |Symbol|Meaning|Examples| |------|-------|--------| |**9**|Position for a digit; When formatting, it adds a leading blank space or trailing 0.|9999| |**0**|Position for a digit; When formatting, it adds leading/trailing 0.|0000| |**.**|Decimal point (only allowed once)|99.99| |**D**|Decimal point, same as **.** (only allowed once)|99D99| |**,**|Group (thousands) separator|9,999| |**G**|Group (thousands) separator, same as **,**|9G999| |**-**|Sign anchored to number (only allowed once)|-9999| |**S**|Sign anchored to number, same as **-** (only allowed once)|S9999| |**$**|Returns value with a leading/trailing dollar sign|$9999| **PostgreSQL:** https://www.postgresql.org/docs/12/functions-formatting.html **Oracle:** https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/TO_NUMBER.html#GUID-D4807212-AFD7-48A7-9AED-BEC3E8809866 **Vertica** https://www.vertica.com/docs/10.0.x/HTML/Content/Authoring/SQLReferenceManual/Functions/Formatting/TO_NUMBER.htm?tocpath=SQL%20Reference%20Manual%7CSQL%20Functions%7CFormatting%20Functions%7C_____7 **Redshift** https://docs.aws.amazon.com/redshift/latest/dg/r_TO_NUMBER.html **DB2** https://www.ibm.com/support/knowledgecenter/SSGU8G_14.1.0/com.ibm.sqls.doc/ids_sqs_1544.htm **Teradata** https://docs.teradata.com/r/kmuOwjp1zEYg98JsB8fu_A/TH2cDXBn6tala29S536nqg **Snowflake:** https://docs.snowflake.net/manuals/sql-reference/functions/to_decimal.html **Exasol** https://docs.exasol.com/sql_references/functions/alphabeticallistfunctions/to_number.htm#TO_NUMBER **Phoenix** http://phoenix.incubator.apache.org/language/functions.html#to_number **Singlestore** https://docs.singlestore.com/v7.3/reference/sql-reference/numeric-functions/to-number/ **Intersystems** https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=RSQL_TONUMBER The syntax like:), > select to_char(12454367, '00,000,000'); 12,454,367 ### Why are the changes needed? `to_number` is very useful for formatted currency to number conversion. ### Does this PR introduce any user-facing change? Yes. New feature. ### How was this patch tested? New tests -- 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]
