This is an automated email from the ASF dual-hosted git repository. kassiez pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push: new 2596fb22816 [opt](functions) update some numeric functions docs (#1811) 2596fb22816 is described below commit 2596fb228164a523e0d94dd0268f2f46a216e2d9 Author: chaoyangqi <87635040+chaoyan...@users.noreply.github.com> AuthorDate: Tue Jan 21 17:25:15 2025 +0800 [opt](functions) update some numeric functions docs (#1811) ## Versions - [x] dev - [x] 3.0 - [x] 2.1 - [ ] 2.0 ## Languages - [x] Chinese - [x] English ## Docs Checklist - [ ] Checked by AI - [ ] Test Cases Built --- .../scalar-functions/numeric-functions/sqrt.md | 62 ++++++------ .../scalar-functions/numeric-functions/tan.md | 48 +++++---- .../scalar-functions/numeric-functions/tanh.md | 49 +++++----- .../scalar-functions/numeric-functions/truncate.md | 79 ++++++++------- .../numeric-functions/uuid_numeric.md | 28 +++--- .../numeric-functions/width-bucket.md | 107 +++++++++++---------- .../scalar-functions/numeric-functions/sqrt.md | 60 ++++++------ .../scalar-functions/numeric-functions/tan.md | 44 +++++---- .../scalar-functions/numeric-functions/tanh.md | 45 +++++---- .../scalar-functions/numeric-functions/truncate.md | 73 ++++++++------ .../numeric-functions/uuid_numeric.md | 20 ++-- .../numeric-functions/width-bucket.md | 98 ++++++++++--------- .../scalar-functions/numeric-functions/sqrt.md | 60 ++++++------ .../scalar-functions/numeric-functions/tan.md | 44 +++++---- .../scalar-functions/numeric-functions/tanh.md | 45 +++++---- .../scalar-functions/numeric-functions/truncate.md | 73 ++++++++------ .../numeric-functions/uuid_numeric.md | 20 ++-- .../numeric-functions/width-bucket.md | 98 ++++++++++--------- .../scalar-functions/numeric-functions/sqrt.md | 60 ++++++------ .../scalar-functions/numeric-functions/tan.md | 44 +++++---- .../scalar-functions/numeric-functions/tanh.md | 45 +++++---- .../scalar-functions/numeric-functions/truncate.md | 73 ++++++++------ .../numeric-functions/uuid_numeric.md | 20 ++-- .../numeric-functions/width-bucket.md | 98 ++++++++++--------- .../scalar-functions/numeric-functions/sqrt.md | 62 ++++++------ .../scalar-functions/numeric-functions/tan.md | 48 +++++---- .../scalar-functions/numeric-functions/tanh.md | 49 +++++----- .../scalar-functions/numeric-functions/truncate.md | 79 ++++++++------- .../numeric-functions/uuid_numeric.md | 28 +++--- .../numeric-functions/width-bucket.md | 107 +++++++++++---------- .../scalar-functions/numeric-functions/sqrt.md | 62 ++++++------ .../scalar-functions/numeric-functions/tan.md | 48 +++++---- .../scalar-functions/numeric-functions/tanh.md | 49 +++++----- .../scalar-functions/numeric-functions/truncate.md | 79 ++++++++------- .../numeric-functions/uuid_numeric.md | 28 +++--- .../numeric-functions/width-bucket.md | 107 +++++++++++---------- 36 files changed, 1173 insertions(+), 966 deletions(-) diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md index ec3821cd869..c8199940773 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md @@ -22,40 +22,44 @@ specific language governing permissions and limitations under the License. --> -## sqrt +## Description -### description -#### Syntax +Returns the square root of a value, where the input value must be greater than or equal to 0. Special cases: -`DOUBLE sqrt(DOUBLE x)` -Returns the square root of `x`.`x` is required to be greater than or equal to `0`. +- If the parameter is less than 0, returns NULL. -:::tip -Another alias for this function is `dsqrt`. -::: +## Aliases -### example +- DSQRT +## Syntax + +```sql +SQRT(<a>) ``` -mysql> select sqrt(9); -+-----------+ -| sqrt(9.0) | -+-----------+ -| 3 | -+-----------+ -mysql> select sqrt(2); -+--------------------+ -| sqrt(2.0) | -+--------------------+ -| 1.4142135623730951 | -+--------------------+ -mysql> select sqrt(100.0); -+-------------+ -| sqrt(100.0) | -+-------------+ -| 10 | -+-------------+ + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<a>` | The value whose square root is to be calculated | + +## Return Value + +The square root of parameter a. Special cases: + +- If the parameter is less than 0, returns NULL + +## Example + +```sql +select sqrt(9),sqrt(2),sqrt(-1) ``` -### keywords - SQRT, DSQRT +```text ++-------------------------+-------------------------+--------------------------+ +| sqrt(cast(9 as DOUBLE)) | sqrt(cast(2 as DOUBLE)) | sqrt(cast(-1 as DOUBLE)) | ++-------------------------+-------------------------+--------------------------+ +| 3 | 1.4142135623730951 | NULL | ++-------------------------+-------------------------+--------------------------+ +``` diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md index bd95b3b3e7f..95bf2b8abf2 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md @@ -22,30 +22,36 @@ specific language governing permissions and limitations under the License. --> -## tan +## Description -### description -#### Syntax +Returns the tangent of x, where x is the value in radians. -`DOUBLE tan(DOUBLE x)` -Returns the tangent of `x`, where `x` is in radians. - -### example +## Syntax +```sql +TAN(<x>) ``` -mysql> select tan(0); -+----------+ -| tan(0.0) | -+----------+ -| 0 | -+----------+ -mysql> select tan(1); -+--------------------+ -| tan(1.0) | -+--------------------+ -| 1.5574077246549023 | -+--------------------+ + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<x>` | The value for which the tangent is to be calculated | + +## Return Value + +Returns the tangent of x. + +## Example + +```sql +select tan(0),tan(1),tan(-1); ``` -### keywords - TAN +```text ++------------------------+------------------------+-------------------------+ +| tan(cast(0 as DOUBLE)) | tan(cast(1 as DOUBLE)) | tan(cast(-1 as DOUBLE)) | ++------------------------+------------------------+-------------------------+ +| 0 | 1.5574077246549023 | -1.5574077246549023 | ++------------------------+------------------------+-------------------------+ +``` diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md index 81336354895..47c3c087a49 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md @@ -22,31 +22,36 @@ specific language governing permissions and limitations under the License. --> -## tanh +## Description -### description -#### Syntax +Returns the hyperbolic tangent of x. -`DOUBLE tanh(DOUBLE x)` -Returns the hyperbolic tangent of `x`, tanh(x) = sinh(x) / cosh(x). - -### example +## Syntax +```sql +TANH(<x>) ``` -mysql> select tanh(0); -+---------+ -| tanh(0) | -+---------+ -| 0 | -+---------+ - -mysql> select tanh(1); -+---------------------+ -| tanh(1) | -+---------------------+ -| 0.76159415595576485 | -+---------------------+ + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<x>` | The value for which the hyperbolic tangent is to be calculated | + +## Return Value + +The hyperbolic tangent of parameter x. + +## Example + +```sql +select tanh(0),tanh(1); ``` -### keywords - TANH +```text ++-------------------------+-------------------------+ +| tanh(cast(0 as DOUBLE)) | tanh(cast(1 as DOUBLE)) | ++-------------------------+-------------------------+ +| 0 | 0.7615941559557649 | ++-------------------------+-------------------------+ +``` diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md index 79e8de2886a..7d2cedf7d28 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md @@ -22,46 +22,58 @@ specific language governing permissions and limitations under the License. --> -## truncate +## Description -### description -#### Syntax -`DOUBLE truncate(DOUBLE x, INT d)` +Perform numerical truncation on x to the number of decimal places d -Numerically truncate `x` according to the number of decimal places `d`. +## Syntax -The rules are as follows: +```sql +TRUNCATE(<x>, <d>) +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<x>` | The value that needs to be numerically truncated | +| `<d>` | The number of decimal places to retain | + +## Return Value + +Perform numerical truncation on x to the number of decimal places d. Truncation rules: + +If d is a literal: + +- When d > 0: Keep d decimal places of x. +- When d = 0: Remove the decimal part of x and retain only the integer part. +- When d < 0: Remove the decimal part of x and replace the integer part with the number of digits specified by d, using the digit 0. -If `d` is literal: -When `d > 0`: keep `d` decimal places of `x` -When `d = 0`: remove the fractional part of `x` and keep only the integer part -When `d < 0`: Remove the fractional part of `x`, and replace the integer part with the number `0` according to the number of digits specified by `d` +If d is a column, and the first argument is of type Decimal, then the resulting Decimal will have the same number of decimal places as the input Decimal -Else if `d` is a column, and `x` has Decimal type, scale of result Decimal will always be same with input Decimal. +## Example -### example + d is a litera +```sql +select truncate(124.3867, 2),truncate(124.3867, 0),truncate(124.3867, -2); ``` -mysql> select truncate(124.3867, 2); -+-----------------------+ -| truncate(124.3867, 2) | -+-----------------------+ -| 124.38 | -+-----------------------+ -mysql> select truncate(124.3867, 0); -+-----------------------+ -| truncate(124.3867, 0) | -+-----------------------+ -| 124 | -+-----------------------+ -mysql> select truncate(-124.3867, -2); -+-------------------------+ -| truncate(-124.3867, -2) | -+-------------------------+ -| -100 | -+-------------------------+ -mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.123456" as Decimal(9,6)), number) from numbers("number"="5"); --------------- + +```text ++-----------------------+-----------------------+------------------------+ +| truncate(124.3867, 2) | truncate(124.3867, 0) | truncate(124.3867, -2) | ++-----------------------+-----------------------+------------------------+ +| 124.38 | 124 | 100 | ++-----------------------+-----------------------+------------------------+ +``` + + d is a column + +```sql +select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.123456" as Decimal(9,6)), number) from numbers("number"="5"); +``` + +```text +---------------------------------------+--------+----------------------------------------------------------------------+ | cast('123.123456' as DECIMALV3(9, 6)) | number | truncate(cast('123.123456' as DECIMALV3(9, 6)), cast(number as INT)) | +---------------------------------------+--------+----------------------------------------------------------------------+ @@ -72,6 +84,3 @@ mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.12 | 123.123456 | 4 | 123.123400 | +---------------------------------------+--------+----------------------------------------------------------------------+ ``` - -### keywords - TRUNCATE diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md index 07d7ec3f9c5..0908f748f41 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md @@ -1,6 +1,6 @@ --- { - "title": "uuid_numeric", + "title": "UUID_NUMERIC", "language": "en" } --- @@ -24,28 +24,30 @@ specific language governing permissions and limitations under the License. --> -## uuid_numeric -### description -#### Syntax +## Description -`LARGEINT uuid_numeric()` +Return a LARGEINT type uuid -Return a uuid in type `LARGEINT`. +## Syntax -Note that `LARGEINT` has type Int128, so we could get a negative number from `uuid_numeric()`. +```sql +UUID_NUMERIC() +``` + +## Return Value -### example +Return a LARGEINT type uuid. Note that LARGEINT is an Int128, so uuid_numeric() may produce negative values +## Example + +```sql +select uuid_numeric() ``` -mysql> select uuid_numeric(); +```text +----------------------------------------+ | uuid_numeric() | +----------------------------------------+ | 82218484683747862468445277894131281464 | +----------------------------------------+ ``` - -### keywords - - UUID UUID-NUMERIC diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md index 56a2e7ee8fd..0885479f127 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md @@ -24,71 +24,69 @@ specific language governing permissions and limitations under the License. --> -## width_bucket +## Description -### Description +Construct an equal-width histogram, where the histogram range is divided into equal-sized intervals, and after calculation, return the bucket number where the value of the expression falls. Special cases: -Constructs equi-width histograms, in which the histogram range is divided into intervals of identical size, and returns the bucket number into which the value of an expression falls, after it has been evaluated. The function returns an integer value or null (if any input is null). +- The function returns an integer value or NULL (if any input is NULL, it will return NULL) -#### Syntax - -`INT width_bucket(Expr expr, T min_value, T max_value, INT num_buckets)` - -#### Arguments -`expr` - -The expression for which the histogram is created. This expression must evaluate to a numeric value or to a value that can be implicitly converted to a numeric value. - -The value must be within the range of `-(2^53 - 1)` to `2^53 - 1` (inclusive). - -`min_value` and `max_value` - -The low and high end points of the acceptable range for the expression. The end points must also evaluate to numeric values and not be equal. - -The low and high end points must be within the range of `-(2^53 - 1)` to `2^53 - 1` (inclusive). In addition, the difference between these points must be less than `2^53` (i.e. `abs(max_value - min_value) < 2^53)`. - -`num_buckets` - -The desired number of buckets; must be a positive integer value. A value from the expression is assigned to each bucket, and the function then returns the corresponding bucket number. +## Syntax +```sql +WIDTH_BUCKET(<expr>, <min_value>, <max_value>, <num_buckets>) +``` -#### Returned value -It returns the bucket number into which the value of an expression falls. +## Parameters -When an expression falls outside the range, the function returns: +| Parameter | Description | +| -- | -- | +| `<expr>` | The expression for creating the histogram. This expression must evaluate to a numeric value or a value that can be implicitly converted to a numeric value. The value's range must be from `-(2^53 - 1)` to `2^53 - 1` (inclusive) | +| `<min_value>` | The lowest value point of the acceptable range for the expression. The parameter must be numeric and not equal to `<max_value>`. The range must be from `-(2^53 - 1)` to `2^53 - 1` (inclusive). Additionally, the difference between the highest and lowest value points must be less than `2^53` (for example: `abs(max_value - min_value) < 2^53)` | +| `<max_value>` | The highest value point of the acceptable range for the expression. The parameter must be numeric and not equal to `<min_value>`. The range must be from `-(2^53 - 1)` to `2^53 - 1` (inclusive). Additionally, the difference between the highest and lowest value points must be less than `2^53` (for example: `abs(max_value - min_value) < 2^53)` | +| `<num_buckets>` | The number of buckets. It must be a positive integer. The function assigns a value from the expression to each bucket and returns the corresponding bucket number | -`0` if the expression is less than `min_value`. +## Return Value -`num_buckets + 1` if the expression is greater than or equal to `max_value`. +Return the bucket number where the expression value falls. The function returns the following rules when the expression is out of range: -`null` if any input is `null`. +- If the value of the expression is less than `min_value`, return 0. +- If the value of the expression is greater than or equal to max_value, return `num_buckets + 1`. +- If any parameter is `null`, return `null` -### example +## Example ```sql DROP TABLE IF EXISTS width_bucket_test; CREATE TABLE IF NOT EXISTS width_bucket_test ( - `k1` int NULL COMMENT "", - `v1` date NULL COMMENT "", - `v2` double NULL COMMENT "", - `v3` bigint NULL COMMENT "" - ) ENGINE=OLAP - DUPLICATE KEY(`k1`) - DISTRIBUTED BY HASH(`k1`) BUCKETS 1 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1", - "storage_format" = "V2" - ); - -INSERT INTO width_bucket_test VALUES (1, "2022-11-18", 290000.00, 290000), - (2, "2023-11-18", 320000.00, 320000), - (3, "2024-11-18", 399999.99, 399999), - (4, "2025-11-18", 400000.00, 400000), - (5, "2026-11-18", 470000.00, 470000), - (6, "2027-11-18", 510000.00, 510000), - (7, "2028-11-18", 610000.00, 610000), - (8, null, null, null); +`k1` int NULL COMMENT "", +`v1` date NULL COMMENT "", +`v2` double NULL COMMENT "", +`v3` bigint NULL COMMENT "" +) ENGINE=OLAP +DUPLICATE KEY(`k1`) +DISTRIBUTED BY HASH(`k1`) BUCKETS 1 +PROPERTIES ( +"replication_allocation" = "tag.location.default: 1", +"storage_format" = "V2" +); + +INSERT INTO width_bucket_test VALUES +(1, "2022-11-18", 290000.00, 290000), +(2, "2023-11-18", 320000.00, 320000), +(3, "2024-11-18", 399999.99, 399999), +(4, "2025-11-18", 400000.00, 400000), +(5, "2026-11-18", 470000.00, 470000), +(6, "2027-11-18", 510000.00, 510000), +(7, "2028-11-18", 610000.00, 610000), +(8, null, null, null); +``` +```sql SELECT * FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+ | k1 | v1 | v2 | v3 | +------+------------+-----------+--------+ @@ -101,9 +99,13 @@ SELECT * FROM width_bucket_test ORDER BY k1; | 7 | 2028-11-18 | 610000 | 610000 | | 8 | NULL | NULL | NULL | +------+------------+-----------+--------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v1, date('2023-11-18'), date('2027-11-18'), 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -116,9 +118,13 @@ SELECT k1, v1, v2, v3, width_bucket(v1, date('2023-11-18'), date('2027-11-18'), | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v2, 200000, 600000, 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -131,9 +137,13 @@ SELECT k1, v1, v2, v3, width_bucket(v2, 200000, 600000, 4) AS w FROM width_bucke | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v3, 200000, 600000, 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -146,7 +156,4 @@ SELECT k1, v1, v2, v3, width_bucket(v3, 200000, 600000, 4) AS w FROM width_bucke | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ - ``` -### keywords -WIDTH_BUCKET \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md index cf030ea4295..780cbdc33be 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md @@ -22,40 +22,44 @@ specific language governing permissions and limitations under the License. --> -## sqrt - ## 描述 + +返回一个值的平方根,要求输入值大于或等于0。特殊情况: + +- 当参数为小于 0 时,返回 NULL + +## 别名 + +- DSQRT + ## 语法 -`DOUBLE sqrt(DOUBLE x)` -返回`x`的平方根,要求x大于或等于0. +```sql +SQRT(<a>) +``` -:::tip -该函数的另一个别名为 `dsqrt`。 -::: +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<a>` | 需要被计算平方根的值 | + +## 返回值 + +参数 a 的平方根。特殊情况: + +- 当参数为小于 0 时,返回 NULL ## 举例 -``` -mysql> select sqrt(9); -+-----------+ -| sqrt(9.0) | -+-----------+ -| 3 | -+-----------+ -mysql> select sqrt(2); -+--------------------+ -| sqrt(2.0) | -+--------------------+ -| 1.4142135623730951 | -+--------------------+ -mysql> select sqrt(100.0); -+-------------+ -| sqrt(100.0) | -+-------------+ -| 10 | -+-------------+ +```sql +select sqrt(9),sqrt(2),sqrt(-1) ``` -### keywords - SQRT, DSQRT +```text ++-------------------------+-------------------------+--------------------------+ +| sqrt(cast(9 as DOUBLE)) | sqrt(cast(2 as DOUBLE)) | sqrt(cast(-1 as DOUBLE)) | ++-------------------------+-------------------------+--------------------------+ +| 3 | 1.4142135623730951 | NULL | ++-------------------------+-------------------------+--------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md index e57f81c4913..dc2803f63a7 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md @@ -22,30 +22,36 @@ specific language governing permissions and limitations under the License. --> -## tan - ## 描述 + +返回 x 的正切值, x 为弧度值 + ## 语法 -`DOUBLE tan(DOUBLE x)` -返回`x`的正切值,`x`为弧度值. +```sql +TAN(<x>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要被计算正切值的值 | + +## 返回值 + +返回 x 的正切值 ## 举例 -``` -mysql> select tan(0); -+----------+ -| tan(0.0) | -+----------+ -| 0 | -+----------+ -mysql> select tan(1); -+--------------------+ -| tan(1.0) | -+--------------------+ -| 1.5574077246549023 | -+--------------------+ +```sql +select tan(0),tan(1),tan(-1); ``` -### keywords - TAN +```text ++------------------------+------------------------+-------------------------+ +| tan(cast(0 as DOUBLE)) | tan(cast(1 as DOUBLE)) | tan(cast(-1 as DOUBLE)) | ++------------------------+------------------------+-------------------------+ +| 0 | 1.5574077246549023 | -1.5574077246549023 | ++------------------------+------------------------+-------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md index 42ba3457cd7..721f31034ea 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md @@ -22,31 +22,36 @@ specific language governing permissions and limitations under the License. --> -## tanh - ## 描述 + +返回 x 的双曲正切值。 + ## 语法 -`DOUBLE tanh(DOUBLE x)` -返回`x`的双曲正切值,tanh(x) = sinh(x) / cosh(x). +```sql +TANH(<x>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要被计算双曲正切值 | + +## 返回值 + +参数 x 的双曲正切值。 ## 举例 -``` -mysql> select tanh(0); -+---------+ -| tanh(0) | -+---------+ -| 0 | -+---------+ - -mysql> select tanh(1); -+---------------------+ -| tanh(1) | -+---------------------+ -| 0.76159415595576485 | -+---------------------+ +```sql +select tanh(0),tanh(1); ``` -### keywords - TANH +```text ++-------------------------+-------------------------+ +| tanh(cast(0 as DOUBLE)) | tanh(cast(1 as DOUBLE)) | ++-------------------------+-------------------------+ +| 0 | 0.7615941559557649 | ++-------------------------+-------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md index a7a23c427fc..06989e3798d 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md @@ -22,46 +22,58 @@ specific language governing permissions and limitations under the License. --> -## truncate - ## 描述 + +按照保留小数的位数 d 对 x 进行数值截取。 + ## 语法 -`DOUBLE truncate(DOUBLE x, INT d)` -按照保留小数的位数`d`对`x`进行数值截取。 +```sql +TRUNCATE(<x>, <d>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要被数值截取的值 | +| `<d>` | 保留小数的位数 | + +## 返回值 + +按照保留小数的位数 d 对 x 进行数值截取。截取规则: -规则如下: +如果 `d` 为字面量: -如果 `d` 为字面量: -当`d > 0`时:保留`x`的`d`位小数 -当`d = 0`时:将`x`的小数部分去除,只保留整数部分 -当`d < 0`时:将`x`的小数部分去除,整数部分按照 `d`所指定的位数,采用数字`0`进行替换 +- 当`d > 0`时:保留`x`的`d`位小数 +- 当`d = 0`时:将`x`的小数部分去除,只保留整数部分 +- 当`d < 0`时:将`x`的小数部分去除,整数部分按照 `d`所指定的位数,采用数字`0`进行替换 如果 `d` 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。 ## 举例 + d 为字面量 + +```sql +select truncate(124.3867, 2),truncate(124.3867, 0),truncate(124.3867, -2); +``` + +```text ++-----------------------+-----------------------+------------------------+ +| truncate(124.3867, 2) | truncate(124.3867, 0) | truncate(124.3867, -2) | ++-----------------------+-----------------------+------------------------+ +| 124.38 | 124 | 100 | ++-----------------------+-----------------------+------------------------+ +``` + + d 为一个列 + +```sql +select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.123456" as Decimal(9,6)), number) from numbers("number"="5"); ``` -mysql> select truncate(124.3867, 2); -+-----------------------+ -| truncate(124.3867, 2) | -+-----------------------+ -| 124.38 | -+-----------------------+ -mysql> select truncate(124.3867, 0); -+-----------------------+ -| truncate(124.3867, 0) | -+-----------------------+ -| 124 | -+-----------------------+ -mysql> select truncate(-124.3867, -2); -+-------------------------+ -| truncate(-124.3867, -2) | -+-------------------------+ -| -100 | -+-------------------------+ -mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.123456" as Decimal(9,6)), number) from numbers("number"="5"); --------------- + +```text +---------------------------------------+--------+----------------------------------------------------------------------+ | cast('123.123456' as DECIMALV3(9, 6)) | number | truncate(cast('123.123456' as DECIMALV3(9, 6)), cast(number as INT)) | +---------------------------------------+--------+----------------------------------------------------------------------+ @@ -72,6 +84,3 @@ mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.12 | 123.123456 | 4 | 123.123400 | +---------------------------------------+--------+----------------------------------------------------------------------+ ``` - -### keywords - TRUNCATE diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md index 4a30df17c51..1b723f4977c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md @@ -1,6 +1,6 @@ --- { - "title": "uuid_numeric", + "title": "UUID_NUMERIC", "language": "zh-CN" } --- @@ -24,26 +24,30 @@ specific language governing permissions and limitations under the License. --> -## uuid_numeric ## 描述 + +返回一个 `LARGEINT` 类型的 `uuid` + ## 语法 -`LARGEINT uuid_numeric()` +```sql +UUID_NUMERIC() +``` + +## 返回值 返回一个 `LARGEINT` 类型的 `uuid`。注意 `LARGEINT` 是一个 Int128,所以 `uuid_numeric()` 可能会得到负值。 ## 举例 +```sql +select uuid_numeric() ``` -mysql> select uuid_numeric(); +```text +----------------------------------------+ | uuid_numeric() | +----------------------------------------+ | 82218484683747862468445277894131281464 | +----------------------------------------+ ``` - -### keywords - - UUID UUID-NUMERIC diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md index c8999dfbedb..d9748fb556f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md @@ -24,40 +24,34 @@ specific language governing permissions and limitations under the License. --> -## width_bucket - ## 描述 -构造等宽直方图,其中直方图范围被划分为相同大小的区间,并在计算后返回表达式的值所在的桶号。该函数返回一个整数值或空值(如果任何输入为空值则返回空值)。 +构造等宽直方图,其中直方图范围被划分为相同大小的区间,并在计算后返回表达式的值所在的桶号。特殊情况: + +- 该函数返回一个整数值或空值(如果任何输入为空值则返回空值)。 ## 语法 -`INT width_bucket(Expr expr, T min_value, T max_value, INT num_buckets)` +```sql +WIDTH_BUCKET(<expr>, <min_value>, <max_value>, <num_buckets>) +``` ## 参数 -`expr` - -创建直方图的表达式。此表达式必须计算为数值或可隐式转换为数值的值。 - -此值的范围必须为 `-(2^53 - 1)` 到 `2^53 - 1` (含). - -`min_value` 和 `max_value` - -表达式可接受范围的最低值点和最高值点。这两个参数必须为数值并且不相等。 -最低值点和最高值点的范围必须为 `-(2^53 - 1)` to `2^53 - 1` (含)). 此外,最高值点与最低值点的差必须小于 `2^53` (例如: `abs(max_value - min_value) < 2^53)`. - -`num_buckets` - -分桶的数量,必须是正整数值。将表达式中的一个值分配给每个存储桶,然后该函数返回相应的存储桶编号。 +| 参数 | 说明 | +| -- | -- | +| `<expr>` | 创建直方图的表达式。此表达式必须计算为数值或可隐式转换为数值的值,此值的范围必须为 `-(2^53 - 1)` 到 `2^53 - 1` (含) | +| `<min_value>` | 表达式可接受范围的最低值点。参数必须为数值且不等于`<max_value>`,范围必须为 `-(2^53 - 1)` to `2^53 - 1` (含)). 此外,最高值点与最低值点的差必须小于 `2^53` (例如: `abs(max_value - min_value) < 2^53)` | +| `<max_value>` | 表达式可接受范围的最高值点。参数必须为数值且不等于`<min_value>`,范围必须为 `-(2^53 - 1)` to `2^53 - 1` (含)). 此外,最高值点与最低值点的差必须小于 `2^53` (例如: `abs(max_value - min_value) < 2^53)` | +| `<num_buckets>` | 分桶的数量,必须是正整数值。将表达式中的一个值分配给每个存储桶,然后该函数返回相应的存储桶编号 | ## 返回值 -返回表达式值所在的桶号。 - -当表达式超出范围时,函数返回规则如下: - -如果表达式的值小于`min_value`返回`0`. -如果表达式的值大于或等于`max_value`返回`num_buckets + 1`. +返回表达式值所在的桶号。当表达式超出范围时,函数返回规则如下: -如果任意参数为`null`返回`null`. +- 如果表达式的值小于`min_value`返回`0`. +- 如果表达式的值大于或等于`max_value`返回`num_buckets + 1`. +- 如果任意参数为`null`返回`null`. ## 举例 @@ -65,29 +59,34 @@ under the License. DROP TABLE IF EXISTS width_bucket_test; CREATE TABLE IF NOT EXISTS width_bucket_test ( - `k1` int NULL COMMENT "", - `v1` date NULL COMMENT "", - `v2` double NULL COMMENT "", - `v3` bigint NULL COMMENT "" - ) ENGINE=OLAP - DUPLICATE KEY(`k1`) - DISTRIBUTED BY HASH(`k1`) BUCKETS 1 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1", - "storage_format" = "V2" - ); - -INSERT INTO width_bucket_test VALUES (1, "2022-11-18", 290000.00, 290000), - (2, "2023-11-18", 320000.00, 320000), - (3, "2024-11-18", 399999.99, 399999), - (4, "2025-11-18", 400000.00, 400000), - (5, "2026-11-18", 470000.00, 470000), - (6, "2027-11-18", 510000.00, 510000), - (7, "2028-11-18", 610000.00, 610000), - (8, null, null, null); +`k1` int NULL COMMENT "", +`v1` date NULL COMMENT "", +`v2` double NULL COMMENT "", +`v3` bigint NULL COMMENT "" +) ENGINE=OLAP +DUPLICATE KEY(`k1`) +DISTRIBUTED BY HASH(`k1`) BUCKETS 1 +PROPERTIES ( +"replication_allocation" = "tag.location.default: 1", +"storage_format" = "V2" +); + +INSERT INTO width_bucket_test VALUES +(1, "2022-11-18", 290000.00, 290000), +(2, "2023-11-18", 320000.00, 320000), +(3, "2024-11-18", 399999.99, 399999), +(4, "2025-11-18", 400000.00, 400000), +(5, "2026-11-18", 470000.00, 470000), +(6, "2027-11-18", 510000.00, 510000), +(7, "2028-11-18", 610000.00, 610000), +(8, null, null, null); +``` +```sql SELECT * FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+ | k1 | v1 | v2 | v3 | +------+------------+-----------+--------+ @@ -100,9 +99,13 @@ SELECT * FROM width_bucket_test ORDER BY k1; | 7 | 2028-11-18 | 610000 | 610000 | | 8 | NULL | NULL | NULL | +------+------------+-----------+--------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v1, date('2023-11-18'), date('2027-11-18'), 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -115,9 +118,13 @@ SELECT k1, v1, v2, v3, width_bucket(v1, date('2023-11-18'), date('2027-11-18'), | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v2, 200000, 600000, 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -130,9 +137,13 @@ SELECT k1, v1, v2, v3, width_bucket(v2, 200000, 600000, 4) AS w FROM width_bucke | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v3, 200000, 600000, 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -145,7 +156,4 @@ SELECT k1, v1, v2, v3, width_bucket(v3, 200000, 600000, 4) AS w FROM width_bucke | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ - ``` -### keywords -WIDTH_BUCKET \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md index cf030ea4295..780cbdc33be 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md @@ -22,40 +22,44 @@ specific language governing permissions and limitations under the License. --> -## sqrt - ## 描述 + +返回一个值的平方根,要求输入值大于或等于0。特殊情况: + +- 当参数为小于 0 时,返回 NULL + +## 别名 + +- DSQRT + ## 语法 -`DOUBLE sqrt(DOUBLE x)` -返回`x`的平方根,要求x大于或等于0. +```sql +SQRT(<a>) +``` -:::tip -该函数的另一个别名为 `dsqrt`。 -::: +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<a>` | 需要被计算平方根的值 | + +## 返回值 + +参数 a 的平方根。特殊情况: + +- 当参数为小于 0 时,返回 NULL ## 举例 -``` -mysql> select sqrt(9); -+-----------+ -| sqrt(9.0) | -+-----------+ -| 3 | -+-----------+ -mysql> select sqrt(2); -+--------------------+ -| sqrt(2.0) | -+--------------------+ -| 1.4142135623730951 | -+--------------------+ -mysql> select sqrt(100.0); -+-------------+ -| sqrt(100.0) | -+-------------+ -| 10 | -+-------------+ +```sql +select sqrt(9),sqrt(2),sqrt(-1) ``` -### keywords - SQRT, DSQRT +```text ++-------------------------+-------------------------+--------------------------+ +| sqrt(cast(9 as DOUBLE)) | sqrt(cast(2 as DOUBLE)) | sqrt(cast(-1 as DOUBLE)) | ++-------------------------+-------------------------+--------------------------+ +| 3 | 1.4142135623730951 | NULL | ++-------------------------+-------------------------+--------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md index e57f81c4913..dc2803f63a7 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md @@ -22,30 +22,36 @@ specific language governing permissions and limitations under the License. --> -## tan - ## 描述 + +返回 x 的正切值, x 为弧度值 + ## 语法 -`DOUBLE tan(DOUBLE x)` -返回`x`的正切值,`x`为弧度值. +```sql +TAN(<x>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要被计算正切值的值 | + +## 返回值 + +返回 x 的正切值 ## 举例 -``` -mysql> select tan(0); -+----------+ -| tan(0.0) | -+----------+ -| 0 | -+----------+ -mysql> select tan(1); -+--------------------+ -| tan(1.0) | -+--------------------+ -| 1.5574077246549023 | -+--------------------+ +```sql +select tan(0),tan(1),tan(-1); ``` -### keywords - TAN +```text ++------------------------+------------------------+-------------------------+ +| tan(cast(0 as DOUBLE)) | tan(cast(1 as DOUBLE)) | tan(cast(-1 as DOUBLE)) | ++------------------------+------------------------+-------------------------+ +| 0 | 1.5574077246549023 | -1.5574077246549023 | ++------------------------+------------------------+-------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md index 42ba3457cd7..721f31034ea 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md @@ -22,31 +22,36 @@ specific language governing permissions and limitations under the License. --> -## tanh - ## 描述 + +返回 x 的双曲正切值。 + ## 语法 -`DOUBLE tanh(DOUBLE x)` -返回`x`的双曲正切值,tanh(x) = sinh(x) / cosh(x). +```sql +TANH(<x>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要被计算双曲正切值 | + +## 返回值 + +参数 x 的双曲正切值。 ## 举例 -``` -mysql> select tanh(0); -+---------+ -| tanh(0) | -+---------+ -| 0 | -+---------+ - -mysql> select tanh(1); -+---------------------+ -| tanh(1) | -+---------------------+ -| 0.76159415595576485 | -+---------------------+ +```sql +select tanh(0),tanh(1); ``` -### keywords - TANH +```text ++-------------------------+-------------------------+ +| tanh(cast(0 as DOUBLE)) | tanh(cast(1 as DOUBLE)) | ++-------------------------+-------------------------+ +| 0 | 0.7615941559557649 | ++-------------------------+-------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md index a7a23c427fc..06989e3798d 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md @@ -22,46 +22,58 @@ specific language governing permissions and limitations under the License. --> -## truncate - ## 描述 + +按照保留小数的位数 d 对 x 进行数值截取。 + ## 语法 -`DOUBLE truncate(DOUBLE x, INT d)` -按照保留小数的位数`d`对`x`进行数值截取。 +```sql +TRUNCATE(<x>, <d>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要被数值截取的值 | +| `<d>` | 保留小数的位数 | + +## 返回值 + +按照保留小数的位数 d 对 x 进行数值截取。截取规则: -规则如下: +如果 `d` 为字面量: -如果 `d` 为字面量: -当`d > 0`时:保留`x`的`d`位小数 -当`d = 0`时:将`x`的小数部分去除,只保留整数部分 -当`d < 0`时:将`x`的小数部分去除,整数部分按照 `d`所指定的位数,采用数字`0`进行替换 +- 当`d > 0`时:保留`x`的`d`位小数 +- 当`d = 0`时:将`x`的小数部分去除,只保留整数部分 +- 当`d < 0`时:将`x`的小数部分去除,整数部分按照 `d`所指定的位数,采用数字`0`进行替换 如果 `d` 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。 ## 举例 + d 为字面量 + +```sql +select truncate(124.3867, 2),truncate(124.3867, 0),truncate(124.3867, -2); +``` + +```text ++-----------------------+-----------------------+------------------------+ +| truncate(124.3867, 2) | truncate(124.3867, 0) | truncate(124.3867, -2) | ++-----------------------+-----------------------+------------------------+ +| 124.38 | 124 | 100 | ++-----------------------+-----------------------+------------------------+ +``` + + d 为一个列 + +```sql +select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.123456" as Decimal(9,6)), number) from numbers("number"="5"); ``` -mysql> select truncate(124.3867, 2); -+-----------------------+ -| truncate(124.3867, 2) | -+-----------------------+ -| 124.38 | -+-----------------------+ -mysql> select truncate(124.3867, 0); -+-----------------------+ -| truncate(124.3867, 0) | -+-----------------------+ -| 124 | -+-----------------------+ -mysql> select truncate(-124.3867, -2); -+-------------------------+ -| truncate(-124.3867, -2) | -+-------------------------+ -| -100 | -+-------------------------+ -mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.123456" as Decimal(9,6)), number) from numbers("number"="5"); --------------- + +```text +---------------------------------------+--------+----------------------------------------------------------------------+ | cast('123.123456' as DECIMALV3(9, 6)) | number | truncate(cast('123.123456' as DECIMALV3(9, 6)), cast(number as INT)) | +---------------------------------------+--------+----------------------------------------------------------------------+ @@ -72,6 +84,3 @@ mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.12 | 123.123456 | 4 | 123.123400 | +---------------------------------------+--------+----------------------------------------------------------------------+ ``` - -### keywords - TRUNCATE diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md index 4a30df17c51..1b723f4977c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md @@ -1,6 +1,6 @@ --- { - "title": "uuid_numeric", + "title": "UUID_NUMERIC", "language": "zh-CN" } --- @@ -24,26 +24,30 @@ specific language governing permissions and limitations under the License. --> -## uuid_numeric ## 描述 + +返回一个 `LARGEINT` 类型的 `uuid` + ## 语法 -`LARGEINT uuid_numeric()` +```sql +UUID_NUMERIC() +``` + +## 返回值 返回一个 `LARGEINT` 类型的 `uuid`。注意 `LARGEINT` 是一个 Int128,所以 `uuid_numeric()` 可能会得到负值。 ## 举例 +```sql +select uuid_numeric() ``` -mysql> select uuid_numeric(); +```text +----------------------------------------+ | uuid_numeric() | +----------------------------------------+ | 82218484683747862468445277894131281464 | +----------------------------------------+ ``` - -### keywords - - UUID UUID-NUMERIC diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md index c8999dfbedb..d9748fb556f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md @@ -24,40 +24,34 @@ specific language governing permissions and limitations under the License. --> -## width_bucket - ## 描述 -构造等宽直方图,其中直方图范围被划分为相同大小的区间,并在计算后返回表达式的值所在的桶号。该函数返回一个整数值或空值(如果任何输入为空值则返回空值)。 +构造等宽直方图,其中直方图范围被划分为相同大小的区间,并在计算后返回表达式的值所在的桶号。特殊情况: + +- 该函数返回一个整数值或空值(如果任何输入为空值则返回空值)。 ## 语法 -`INT width_bucket(Expr expr, T min_value, T max_value, INT num_buckets)` +```sql +WIDTH_BUCKET(<expr>, <min_value>, <max_value>, <num_buckets>) +``` ## 参数 -`expr` - -创建直方图的表达式。此表达式必须计算为数值或可隐式转换为数值的值。 - -此值的范围必须为 `-(2^53 - 1)` 到 `2^53 - 1` (含). - -`min_value` 和 `max_value` - -表达式可接受范围的最低值点和最高值点。这两个参数必须为数值并且不相等。 -最低值点和最高值点的范围必须为 `-(2^53 - 1)` to `2^53 - 1` (含)). 此外,最高值点与最低值点的差必须小于 `2^53` (例如: `abs(max_value - min_value) < 2^53)`. - -`num_buckets` - -分桶的数量,必须是正整数值。将表达式中的一个值分配给每个存储桶,然后该函数返回相应的存储桶编号。 +| 参数 | 说明 | +| -- | -- | +| `<expr>` | 创建直方图的表达式。此表达式必须计算为数值或可隐式转换为数值的值,此值的范围必须为 `-(2^53 - 1)` 到 `2^53 - 1` (含) | +| `<min_value>` | 表达式可接受范围的最低值点。参数必须为数值且不等于`<max_value>`,范围必须为 `-(2^53 - 1)` to `2^53 - 1` (含)). 此外,最高值点与最低值点的差必须小于 `2^53` (例如: `abs(max_value - min_value) < 2^53)` | +| `<max_value>` | 表达式可接受范围的最高值点。参数必须为数值且不等于`<min_value>`,范围必须为 `-(2^53 - 1)` to `2^53 - 1` (含)). 此外,最高值点与最低值点的差必须小于 `2^53` (例如: `abs(max_value - min_value) < 2^53)` | +| `<num_buckets>` | 分桶的数量,必须是正整数值。将表达式中的一个值分配给每个存储桶,然后该函数返回相应的存储桶编号 | ## 返回值 -返回表达式值所在的桶号。 - -当表达式超出范围时,函数返回规则如下: - -如果表达式的值小于`min_value`返回`0`. -如果表达式的值大于或等于`max_value`返回`num_buckets + 1`. +返回表达式值所在的桶号。当表达式超出范围时,函数返回规则如下: -如果任意参数为`null`返回`null`. +- 如果表达式的值小于`min_value`返回`0`. +- 如果表达式的值大于或等于`max_value`返回`num_buckets + 1`. +- 如果任意参数为`null`返回`null`. ## 举例 @@ -65,29 +59,34 @@ under the License. DROP TABLE IF EXISTS width_bucket_test; CREATE TABLE IF NOT EXISTS width_bucket_test ( - `k1` int NULL COMMENT "", - `v1` date NULL COMMENT "", - `v2` double NULL COMMENT "", - `v3` bigint NULL COMMENT "" - ) ENGINE=OLAP - DUPLICATE KEY(`k1`) - DISTRIBUTED BY HASH(`k1`) BUCKETS 1 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1", - "storage_format" = "V2" - ); - -INSERT INTO width_bucket_test VALUES (1, "2022-11-18", 290000.00, 290000), - (2, "2023-11-18", 320000.00, 320000), - (3, "2024-11-18", 399999.99, 399999), - (4, "2025-11-18", 400000.00, 400000), - (5, "2026-11-18", 470000.00, 470000), - (6, "2027-11-18", 510000.00, 510000), - (7, "2028-11-18", 610000.00, 610000), - (8, null, null, null); +`k1` int NULL COMMENT "", +`v1` date NULL COMMENT "", +`v2` double NULL COMMENT "", +`v3` bigint NULL COMMENT "" +) ENGINE=OLAP +DUPLICATE KEY(`k1`) +DISTRIBUTED BY HASH(`k1`) BUCKETS 1 +PROPERTIES ( +"replication_allocation" = "tag.location.default: 1", +"storage_format" = "V2" +); + +INSERT INTO width_bucket_test VALUES +(1, "2022-11-18", 290000.00, 290000), +(2, "2023-11-18", 320000.00, 320000), +(3, "2024-11-18", 399999.99, 399999), +(4, "2025-11-18", 400000.00, 400000), +(5, "2026-11-18", 470000.00, 470000), +(6, "2027-11-18", 510000.00, 510000), +(7, "2028-11-18", 610000.00, 610000), +(8, null, null, null); +``` +```sql SELECT * FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+ | k1 | v1 | v2 | v3 | +------+------------+-----------+--------+ @@ -100,9 +99,13 @@ SELECT * FROM width_bucket_test ORDER BY k1; | 7 | 2028-11-18 | 610000 | 610000 | | 8 | NULL | NULL | NULL | +------+------------+-----------+--------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v1, date('2023-11-18'), date('2027-11-18'), 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -115,9 +118,13 @@ SELECT k1, v1, v2, v3, width_bucket(v1, date('2023-11-18'), date('2027-11-18'), | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v2, 200000, 600000, 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -130,9 +137,13 @@ SELECT k1, v1, v2, v3, width_bucket(v2, 200000, 600000, 4) AS w FROM width_bucke | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v3, 200000, 600000, 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -145,7 +156,4 @@ SELECT k1, v1, v2, v3, width_bucket(v3, 200000, 600000, 4) AS w FROM width_bucke | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ - ``` -### keywords -WIDTH_BUCKET \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md index cf030ea4295..780cbdc33be 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md @@ -22,40 +22,44 @@ specific language governing permissions and limitations under the License. --> -## sqrt - ## 描述 + +返回一个值的平方根,要求输入值大于或等于0。特殊情况: + +- 当参数为小于 0 时,返回 NULL + +## 别名 + +- DSQRT + ## 语法 -`DOUBLE sqrt(DOUBLE x)` -返回`x`的平方根,要求x大于或等于0. +```sql +SQRT(<a>) +``` -:::tip -该函数的另一个别名为 `dsqrt`。 -::: +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<a>` | 需要被计算平方根的值 | + +## 返回值 + +参数 a 的平方根。特殊情况: + +- 当参数为小于 0 时,返回 NULL ## 举例 -``` -mysql> select sqrt(9); -+-----------+ -| sqrt(9.0) | -+-----------+ -| 3 | -+-----------+ -mysql> select sqrt(2); -+--------------------+ -| sqrt(2.0) | -+--------------------+ -| 1.4142135623730951 | -+--------------------+ -mysql> select sqrt(100.0); -+-------------+ -| sqrt(100.0) | -+-------------+ -| 10 | -+-------------+ +```sql +select sqrt(9),sqrt(2),sqrt(-1) ``` -### keywords - SQRT, DSQRT +```text ++-------------------------+-------------------------+--------------------------+ +| sqrt(cast(9 as DOUBLE)) | sqrt(cast(2 as DOUBLE)) | sqrt(cast(-1 as DOUBLE)) | ++-------------------------+-------------------------+--------------------------+ +| 3 | 1.4142135623730951 | NULL | ++-------------------------+-------------------------+--------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md index e57f81c4913..dc2803f63a7 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md @@ -22,30 +22,36 @@ specific language governing permissions and limitations under the License. --> -## tan - ## 描述 + +返回 x 的正切值, x 为弧度值 + ## 语法 -`DOUBLE tan(DOUBLE x)` -返回`x`的正切值,`x`为弧度值. +```sql +TAN(<x>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要被计算正切值的值 | + +## 返回值 + +返回 x 的正切值 ## 举例 -``` -mysql> select tan(0); -+----------+ -| tan(0.0) | -+----------+ -| 0 | -+----------+ -mysql> select tan(1); -+--------------------+ -| tan(1.0) | -+--------------------+ -| 1.5574077246549023 | -+--------------------+ +```sql +select tan(0),tan(1),tan(-1); ``` -### keywords - TAN +```text ++------------------------+------------------------+-------------------------+ +| tan(cast(0 as DOUBLE)) | tan(cast(1 as DOUBLE)) | tan(cast(-1 as DOUBLE)) | ++------------------------+------------------------+-------------------------+ +| 0 | 1.5574077246549023 | -1.5574077246549023 | ++------------------------+------------------------+-------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md index 42ba3457cd7..721f31034ea 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md @@ -22,31 +22,36 @@ specific language governing permissions and limitations under the License. --> -## tanh - ## 描述 + +返回 x 的双曲正切值。 + ## 语法 -`DOUBLE tanh(DOUBLE x)` -返回`x`的双曲正切值,tanh(x) = sinh(x) / cosh(x). +```sql +TANH(<x>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要被计算双曲正切值 | + +## 返回值 + +参数 x 的双曲正切值。 ## 举例 -``` -mysql> select tanh(0); -+---------+ -| tanh(0) | -+---------+ -| 0 | -+---------+ - -mysql> select tanh(1); -+---------------------+ -| tanh(1) | -+---------------------+ -| 0.76159415595576485 | -+---------------------+ +```sql +select tanh(0),tanh(1); ``` -### keywords - TANH +```text ++-------------------------+-------------------------+ +| tanh(cast(0 as DOUBLE)) | tanh(cast(1 as DOUBLE)) | ++-------------------------+-------------------------+ +| 0 | 0.7615941559557649 | ++-------------------------+-------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md index a7a23c427fc..06989e3798d 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md @@ -22,46 +22,58 @@ specific language governing permissions and limitations under the License. --> -## truncate - ## 描述 + +按照保留小数的位数 d 对 x 进行数值截取。 + ## 语法 -`DOUBLE truncate(DOUBLE x, INT d)` -按照保留小数的位数`d`对`x`进行数值截取。 +```sql +TRUNCATE(<x>, <d>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要被数值截取的值 | +| `<d>` | 保留小数的位数 | + +## 返回值 + +按照保留小数的位数 d 对 x 进行数值截取。截取规则: -规则如下: +如果 `d` 为字面量: -如果 `d` 为字面量: -当`d > 0`时:保留`x`的`d`位小数 -当`d = 0`时:将`x`的小数部分去除,只保留整数部分 -当`d < 0`时:将`x`的小数部分去除,整数部分按照 `d`所指定的位数,采用数字`0`进行替换 +- 当`d > 0`时:保留`x`的`d`位小数 +- 当`d = 0`时:将`x`的小数部分去除,只保留整数部分 +- 当`d < 0`时:将`x`的小数部分去除,整数部分按照 `d`所指定的位数,采用数字`0`进行替换 如果 `d` 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。 ## 举例 + d 为字面量 + +```sql +select truncate(124.3867, 2),truncate(124.3867, 0),truncate(124.3867, -2); +``` + +```text ++-----------------------+-----------------------+------------------------+ +| truncate(124.3867, 2) | truncate(124.3867, 0) | truncate(124.3867, -2) | ++-----------------------+-----------------------+------------------------+ +| 124.38 | 124 | 100 | ++-----------------------+-----------------------+------------------------+ +``` + + d 为一个列 + +```sql +select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.123456" as Decimal(9,6)), number) from numbers("number"="5"); ``` -mysql> select truncate(124.3867, 2); -+-----------------------+ -| truncate(124.3867, 2) | -+-----------------------+ -| 124.38 | -+-----------------------+ -mysql> select truncate(124.3867, 0); -+-----------------------+ -| truncate(124.3867, 0) | -+-----------------------+ -| 124 | -+-----------------------+ -mysql> select truncate(-124.3867, -2); -+-------------------------+ -| truncate(-124.3867, -2) | -+-------------------------+ -| -100 | -+-------------------------+ -mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.123456" as Decimal(9,6)), number) from numbers("number"="5"); --------------- + +```text +---------------------------------------+--------+----------------------------------------------------------------------+ | cast('123.123456' as DECIMALV3(9, 6)) | number | truncate(cast('123.123456' as DECIMALV3(9, 6)), cast(number as INT)) | +---------------------------------------+--------+----------------------------------------------------------------------+ @@ -72,6 +84,3 @@ mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.12 | 123.123456 | 4 | 123.123400 | +---------------------------------------+--------+----------------------------------------------------------------------+ ``` - -### keywords - TRUNCATE diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md index 4a30df17c51..1b723f4977c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md @@ -1,6 +1,6 @@ --- { - "title": "uuid_numeric", + "title": "UUID_NUMERIC", "language": "zh-CN" } --- @@ -24,26 +24,30 @@ specific language governing permissions and limitations under the License. --> -## uuid_numeric ## 描述 + +返回一个 `LARGEINT` 类型的 `uuid` + ## 语法 -`LARGEINT uuid_numeric()` +```sql +UUID_NUMERIC() +``` + +## 返回值 返回一个 `LARGEINT` 类型的 `uuid`。注意 `LARGEINT` 是一个 Int128,所以 `uuid_numeric()` 可能会得到负值。 ## 举例 +```sql +select uuid_numeric() ``` -mysql> select uuid_numeric(); +```text +----------------------------------------+ | uuid_numeric() | +----------------------------------------+ | 82218484683747862468445277894131281464 | +----------------------------------------+ ``` - -### keywords - - UUID UUID-NUMERIC diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md index c8999dfbedb..d9748fb556f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md @@ -24,40 +24,34 @@ specific language governing permissions and limitations under the License. --> -## width_bucket - ## 描述 -构造等宽直方图,其中直方图范围被划分为相同大小的区间,并在计算后返回表达式的值所在的桶号。该函数返回一个整数值或空值(如果任何输入为空值则返回空值)。 +构造等宽直方图,其中直方图范围被划分为相同大小的区间,并在计算后返回表达式的值所在的桶号。特殊情况: + +- 该函数返回一个整数值或空值(如果任何输入为空值则返回空值)。 ## 语法 -`INT width_bucket(Expr expr, T min_value, T max_value, INT num_buckets)` +```sql +WIDTH_BUCKET(<expr>, <min_value>, <max_value>, <num_buckets>) +``` ## 参数 -`expr` - -创建直方图的表达式。此表达式必须计算为数值或可隐式转换为数值的值。 - -此值的范围必须为 `-(2^53 - 1)` 到 `2^53 - 1` (含). - -`min_value` 和 `max_value` - -表达式可接受范围的最低值点和最高值点。这两个参数必须为数值并且不相等。 -最低值点和最高值点的范围必须为 `-(2^53 - 1)` to `2^53 - 1` (含)). 此外,最高值点与最低值点的差必须小于 `2^53` (例如: `abs(max_value - min_value) < 2^53)`. - -`num_buckets` - -分桶的数量,必须是正整数值。将表达式中的一个值分配给每个存储桶,然后该函数返回相应的存储桶编号。 +| 参数 | 说明 | +| -- | -- | +| `<expr>` | 创建直方图的表达式。此表达式必须计算为数值或可隐式转换为数值的值,此值的范围必须为 `-(2^53 - 1)` 到 `2^53 - 1` (含) | +| `<min_value>` | 表达式可接受范围的最低值点。参数必须为数值且不等于`<max_value>`,范围必须为 `-(2^53 - 1)` to `2^53 - 1` (含)). 此外,最高值点与最低值点的差必须小于 `2^53` (例如: `abs(max_value - min_value) < 2^53)` | +| `<max_value>` | 表达式可接受范围的最高值点。参数必须为数值且不等于`<min_value>`,范围必须为 `-(2^53 - 1)` to `2^53 - 1` (含)). 此外,最高值点与最低值点的差必须小于 `2^53` (例如: `abs(max_value - min_value) < 2^53)` | +| `<num_buckets>` | 分桶的数量,必须是正整数值。将表达式中的一个值分配给每个存储桶,然后该函数返回相应的存储桶编号 | ## 返回值 -返回表达式值所在的桶号。 - -当表达式超出范围时,函数返回规则如下: - -如果表达式的值小于`min_value`返回`0`. -如果表达式的值大于或等于`max_value`返回`num_buckets + 1`. +返回表达式值所在的桶号。当表达式超出范围时,函数返回规则如下: -如果任意参数为`null`返回`null`. +- 如果表达式的值小于`min_value`返回`0`. +- 如果表达式的值大于或等于`max_value`返回`num_buckets + 1`. +- 如果任意参数为`null`返回`null`. ## 举例 @@ -65,29 +59,34 @@ under the License. DROP TABLE IF EXISTS width_bucket_test; CREATE TABLE IF NOT EXISTS width_bucket_test ( - `k1` int NULL COMMENT "", - `v1` date NULL COMMENT "", - `v2` double NULL COMMENT "", - `v3` bigint NULL COMMENT "" - ) ENGINE=OLAP - DUPLICATE KEY(`k1`) - DISTRIBUTED BY HASH(`k1`) BUCKETS 1 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1", - "storage_format" = "V2" - ); - -INSERT INTO width_bucket_test VALUES (1, "2022-11-18", 290000.00, 290000), - (2, "2023-11-18", 320000.00, 320000), - (3, "2024-11-18", 399999.99, 399999), - (4, "2025-11-18", 400000.00, 400000), - (5, "2026-11-18", 470000.00, 470000), - (6, "2027-11-18", 510000.00, 510000), - (7, "2028-11-18", 610000.00, 610000), - (8, null, null, null); +`k1` int NULL COMMENT "", +`v1` date NULL COMMENT "", +`v2` double NULL COMMENT "", +`v3` bigint NULL COMMENT "" +) ENGINE=OLAP +DUPLICATE KEY(`k1`) +DISTRIBUTED BY HASH(`k1`) BUCKETS 1 +PROPERTIES ( +"replication_allocation" = "tag.location.default: 1", +"storage_format" = "V2" +); + +INSERT INTO width_bucket_test VALUES +(1, "2022-11-18", 290000.00, 290000), +(2, "2023-11-18", 320000.00, 320000), +(3, "2024-11-18", 399999.99, 399999), +(4, "2025-11-18", 400000.00, 400000), +(5, "2026-11-18", 470000.00, 470000), +(6, "2027-11-18", 510000.00, 510000), +(7, "2028-11-18", 610000.00, 610000), +(8, null, null, null); +``` +```sql SELECT * FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+ | k1 | v1 | v2 | v3 | +------+------------+-----------+--------+ @@ -100,9 +99,13 @@ SELECT * FROM width_bucket_test ORDER BY k1; | 7 | 2028-11-18 | 610000 | 610000 | | 8 | NULL | NULL | NULL | +------+------------+-----------+--------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v1, date('2023-11-18'), date('2027-11-18'), 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -115,9 +118,13 @@ SELECT k1, v1, v2, v3, width_bucket(v1, date('2023-11-18'), date('2027-11-18'), | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v2, 200000, 600000, 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -130,9 +137,13 @@ SELECT k1, v1, v2, v3, width_bucket(v2, 200000, 600000, 4) AS w FROM width_bucke | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v3, 200000, 600000, 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -145,7 +156,4 @@ SELECT k1, v1, v2, v3, width_bucket(v3, 200000, 600000, 4) AS w FROM width_bucke | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ - ``` -### keywords -WIDTH_BUCKET \ No newline at end of file diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md index ec3821cd869..c8199940773 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md @@ -22,40 +22,44 @@ specific language governing permissions and limitations under the License. --> -## sqrt +## Description -### description -#### Syntax +Returns the square root of a value, where the input value must be greater than or equal to 0. Special cases: -`DOUBLE sqrt(DOUBLE x)` -Returns the square root of `x`.`x` is required to be greater than or equal to `0`. +- If the parameter is less than 0, returns NULL. -:::tip -Another alias for this function is `dsqrt`. -::: +## Aliases -### example +- DSQRT +## Syntax + +```sql +SQRT(<a>) ``` -mysql> select sqrt(9); -+-----------+ -| sqrt(9.0) | -+-----------+ -| 3 | -+-----------+ -mysql> select sqrt(2); -+--------------------+ -| sqrt(2.0) | -+--------------------+ -| 1.4142135623730951 | -+--------------------+ -mysql> select sqrt(100.0); -+-------------+ -| sqrt(100.0) | -+-------------+ -| 10 | -+-------------+ + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<a>` | The value whose square root is to be calculated | + +## Return Value + +The square root of parameter a. Special cases: + +- If the parameter is less than 0, returns NULL + +## Example + +```sql +select sqrt(9),sqrt(2),sqrt(-1) ``` -### keywords - SQRT, DSQRT +```text ++-------------------------+-------------------------+--------------------------+ +| sqrt(cast(9 as DOUBLE)) | sqrt(cast(2 as DOUBLE)) | sqrt(cast(-1 as DOUBLE)) | ++-------------------------+-------------------------+--------------------------+ +| 3 | 1.4142135623730951 | NULL | ++-------------------------+-------------------------+--------------------------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md index bd95b3b3e7f..95bf2b8abf2 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md @@ -22,30 +22,36 @@ specific language governing permissions and limitations under the License. --> -## tan +## Description -### description -#### Syntax +Returns the tangent of x, where x is the value in radians. -`DOUBLE tan(DOUBLE x)` -Returns the tangent of `x`, where `x` is in radians. - -### example +## Syntax +```sql +TAN(<x>) ``` -mysql> select tan(0); -+----------+ -| tan(0.0) | -+----------+ -| 0 | -+----------+ -mysql> select tan(1); -+--------------------+ -| tan(1.0) | -+--------------------+ -| 1.5574077246549023 | -+--------------------+ + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<x>` | The value for which the tangent is to be calculated | + +## Return Value + +Returns the tangent of x. + +## Example + +```sql +select tan(0),tan(1),tan(-1); ``` -### keywords - TAN +```text ++------------------------+------------------------+-------------------------+ +| tan(cast(0 as DOUBLE)) | tan(cast(1 as DOUBLE)) | tan(cast(-1 as DOUBLE)) | ++------------------------+------------------------+-------------------------+ +| 0 | 1.5574077246549023 | -1.5574077246549023 | ++------------------------+------------------------+-------------------------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md index 81336354895..47c3c087a49 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md @@ -22,31 +22,36 @@ specific language governing permissions and limitations under the License. --> -## tanh +## Description -### description -#### Syntax +Returns the hyperbolic tangent of x. -`DOUBLE tanh(DOUBLE x)` -Returns the hyperbolic tangent of `x`, tanh(x) = sinh(x) / cosh(x). - -### example +## Syntax +```sql +TANH(<x>) ``` -mysql> select tanh(0); -+---------+ -| tanh(0) | -+---------+ -| 0 | -+---------+ - -mysql> select tanh(1); -+---------------------+ -| tanh(1) | -+---------------------+ -| 0.76159415595576485 | -+---------------------+ + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<x>` | The value for which the hyperbolic tangent is to be calculated | + +## Return Value + +The hyperbolic tangent of parameter x. + +## Example + +```sql +select tanh(0),tanh(1); ``` -### keywords - TANH +```text ++-------------------------+-------------------------+ +| tanh(cast(0 as DOUBLE)) | tanh(cast(1 as DOUBLE)) | ++-------------------------+-------------------------+ +| 0 | 0.7615941559557649 | ++-------------------------+-------------------------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md index 79e8de2886a..7d2cedf7d28 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md @@ -22,46 +22,58 @@ specific language governing permissions and limitations under the License. --> -## truncate +## Description -### description -#### Syntax -`DOUBLE truncate(DOUBLE x, INT d)` +Perform numerical truncation on x to the number of decimal places d -Numerically truncate `x` according to the number of decimal places `d`. +## Syntax -The rules are as follows: +```sql +TRUNCATE(<x>, <d>) +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<x>` | The value that needs to be numerically truncated | +| `<d>` | The number of decimal places to retain | + +## Return Value + +Perform numerical truncation on x to the number of decimal places d. Truncation rules: + +If d is a literal: + +- When d > 0: Keep d decimal places of x. +- When d = 0: Remove the decimal part of x and retain only the integer part. +- When d < 0: Remove the decimal part of x and replace the integer part with the number of digits specified by d, using the digit 0. -If `d` is literal: -When `d > 0`: keep `d` decimal places of `x` -When `d = 0`: remove the fractional part of `x` and keep only the integer part -When `d < 0`: Remove the fractional part of `x`, and replace the integer part with the number `0` according to the number of digits specified by `d` +If d is a column, and the first argument is of type Decimal, then the resulting Decimal will have the same number of decimal places as the input Decimal -Else if `d` is a column, and `x` has Decimal type, scale of result Decimal will always be same with input Decimal. +## Example -### example + d is a litera +```sql +select truncate(124.3867, 2),truncate(124.3867, 0),truncate(124.3867, -2); ``` -mysql> select truncate(124.3867, 2); -+-----------------------+ -| truncate(124.3867, 2) | -+-----------------------+ -| 124.38 | -+-----------------------+ -mysql> select truncate(124.3867, 0); -+-----------------------+ -| truncate(124.3867, 0) | -+-----------------------+ -| 124 | -+-----------------------+ -mysql> select truncate(-124.3867, -2); -+-------------------------+ -| truncate(-124.3867, -2) | -+-------------------------+ -| -100 | -+-------------------------+ -mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.123456" as Decimal(9,6)), number) from numbers("number"="5"); --------------- + +```text ++-----------------------+-----------------------+------------------------+ +| truncate(124.3867, 2) | truncate(124.3867, 0) | truncate(124.3867, -2) | ++-----------------------+-----------------------+------------------------+ +| 124.38 | 124 | 100 | ++-----------------------+-----------------------+------------------------+ +``` + + d is a column + +```sql +select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.123456" as Decimal(9,6)), number) from numbers("number"="5"); +``` + +```text +---------------------------------------+--------+----------------------------------------------------------------------+ | cast('123.123456' as DECIMALV3(9, 6)) | number | truncate(cast('123.123456' as DECIMALV3(9, 6)), cast(number as INT)) | +---------------------------------------+--------+----------------------------------------------------------------------+ @@ -72,6 +84,3 @@ mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.12 | 123.123456 | 4 | 123.123400 | +---------------------------------------+--------+----------------------------------------------------------------------+ ``` - -### keywords - TRUNCATE diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md index 07d7ec3f9c5..0908f748f41 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md @@ -1,6 +1,6 @@ --- { - "title": "uuid_numeric", + "title": "UUID_NUMERIC", "language": "en" } --- @@ -24,28 +24,30 @@ specific language governing permissions and limitations under the License. --> -## uuid_numeric -### description -#### Syntax +## Description -`LARGEINT uuid_numeric()` +Return a LARGEINT type uuid -Return a uuid in type `LARGEINT`. +## Syntax -Note that `LARGEINT` has type Int128, so we could get a negative number from `uuid_numeric()`. +```sql +UUID_NUMERIC() +``` + +## Return Value -### example +Return a LARGEINT type uuid. Note that LARGEINT is an Int128, so uuid_numeric() may produce negative values +## Example + +```sql +select uuid_numeric() ``` -mysql> select uuid_numeric(); +```text +----------------------------------------+ | uuid_numeric() | +----------------------------------------+ | 82218484683747862468445277894131281464 | +----------------------------------------+ ``` - -### keywords - - UUID UUID-NUMERIC diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md index 56a2e7ee8fd..0885479f127 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md @@ -24,71 +24,69 @@ specific language governing permissions and limitations under the License. --> -## width_bucket +## Description -### Description +Construct an equal-width histogram, where the histogram range is divided into equal-sized intervals, and after calculation, return the bucket number where the value of the expression falls. Special cases: -Constructs equi-width histograms, in which the histogram range is divided into intervals of identical size, and returns the bucket number into which the value of an expression falls, after it has been evaluated. The function returns an integer value or null (if any input is null). +- The function returns an integer value or NULL (if any input is NULL, it will return NULL) -#### Syntax - -`INT width_bucket(Expr expr, T min_value, T max_value, INT num_buckets)` - -#### Arguments -`expr` - -The expression for which the histogram is created. This expression must evaluate to a numeric value or to a value that can be implicitly converted to a numeric value. - -The value must be within the range of `-(2^53 - 1)` to `2^53 - 1` (inclusive). - -`min_value` and `max_value` - -The low and high end points of the acceptable range for the expression. The end points must also evaluate to numeric values and not be equal. - -The low and high end points must be within the range of `-(2^53 - 1)` to `2^53 - 1` (inclusive). In addition, the difference between these points must be less than `2^53` (i.e. `abs(max_value - min_value) < 2^53)`. - -`num_buckets` - -The desired number of buckets; must be a positive integer value. A value from the expression is assigned to each bucket, and the function then returns the corresponding bucket number. +## Syntax +```sql +WIDTH_BUCKET(<expr>, <min_value>, <max_value>, <num_buckets>) +``` -#### Returned value -It returns the bucket number into which the value of an expression falls. +## Parameters -When an expression falls outside the range, the function returns: +| Parameter | Description | +| -- | -- | +| `<expr>` | The expression for creating the histogram. This expression must evaluate to a numeric value or a value that can be implicitly converted to a numeric value. The value's range must be from `-(2^53 - 1)` to `2^53 - 1` (inclusive) | +| `<min_value>` | The lowest value point of the acceptable range for the expression. The parameter must be numeric and not equal to `<max_value>`. The range must be from `-(2^53 - 1)` to `2^53 - 1` (inclusive). Additionally, the difference between the highest and lowest value points must be less than `2^53` (for example: `abs(max_value - min_value) < 2^53)` | +| `<max_value>` | The highest value point of the acceptable range for the expression. The parameter must be numeric and not equal to `<min_value>`. The range must be from `-(2^53 - 1)` to `2^53 - 1` (inclusive). Additionally, the difference between the highest and lowest value points must be less than `2^53` (for example: `abs(max_value - min_value) < 2^53)` | +| `<num_buckets>` | The number of buckets. It must be a positive integer. The function assigns a value from the expression to each bucket and returns the corresponding bucket number | -`0` if the expression is less than `min_value`. +## Return Value -`num_buckets + 1` if the expression is greater than or equal to `max_value`. +Return the bucket number where the expression value falls. The function returns the following rules when the expression is out of range: -`null` if any input is `null`. +- If the value of the expression is less than `min_value`, return 0. +- If the value of the expression is greater than or equal to max_value, return `num_buckets + 1`. +- If any parameter is `null`, return `null` -### example +## Example ```sql DROP TABLE IF EXISTS width_bucket_test; CREATE TABLE IF NOT EXISTS width_bucket_test ( - `k1` int NULL COMMENT "", - `v1` date NULL COMMENT "", - `v2` double NULL COMMENT "", - `v3` bigint NULL COMMENT "" - ) ENGINE=OLAP - DUPLICATE KEY(`k1`) - DISTRIBUTED BY HASH(`k1`) BUCKETS 1 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1", - "storage_format" = "V2" - ); - -INSERT INTO width_bucket_test VALUES (1, "2022-11-18", 290000.00, 290000), - (2, "2023-11-18", 320000.00, 320000), - (3, "2024-11-18", 399999.99, 399999), - (4, "2025-11-18", 400000.00, 400000), - (5, "2026-11-18", 470000.00, 470000), - (6, "2027-11-18", 510000.00, 510000), - (7, "2028-11-18", 610000.00, 610000), - (8, null, null, null); +`k1` int NULL COMMENT "", +`v1` date NULL COMMENT "", +`v2` double NULL COMMENT "", +`v3` bigint NULL COMMENT "" +) ENGINE=OLAP +DUPLICATE KEY(`k1`) +DISTRIBUTED BY HASH(`k1`) BUCKETS 1 +PROPERTIES ( +"replication_allocation" = "tag.location.default: 1", +"storage_format" = "V2" +); + +INSERT INTO width_bucket_test VALUES +(1, "2022-11-18", 290000.00, 290000), +(2, "2023-11-18", 320000.00, 320000), +(3, "2024-11-18", 399999.99, 399999), +(4, "2025-11-18", 400000.00, 400000), +(5, "2026-11-18", 470000.00, 470000), +(6, "2027-11-18", 510000.00, 510000), +(7, "2028-11-18", 610000.00, 610000), +(8, null, null, null); +``` +```sql SELECT * FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+ | k1 | v1 | v2 | v3 | +------+------------+-----------+--------+ @@ -101,9 +99,13 @@ SELECT * FROM width_bucket_test ORDER BY k1; | 7 | 2028-11-18 | 610000 | 610000 | | 8 | NULL | NULL | NULL | +------+------------+-----------+--------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v1, date('2023-11-18'), date('2027-11-18'), 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -116,9 +118,13 @@ SELECT k1, v1, v2, v3, width_bucket(v1, date('2023-11-18'), date('2027-11-18'), | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v2, 200000, 600000, 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -131,9 +137,13 @@ SELECT k1, v1, v2, v3, width_bucket(v2, 200000, 600000, 4) AS w FROM width_bucke | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v3, 200000, 600000, 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -146,7 +156,4 @@ SELECT k1, v1, v2, v3, width_bucket(v3, 200000, 600000, 4) AS w FROM width_bucke | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ - ``` -### keywords -WIDTH_BUCKET \ No newline at end of file diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md index ec3821cd869..c8199940773 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sqrt.md @@ -22,40 +22,44 @@ specific language governing permissions and limitations under the License. --> -## sqrt +## Description -### description -#### Syntax +Returns the square root of a value, where the input value must be greater than or equal to 0. Special cases: -`DOUBLE sqrt(DOUBLE x)` -Returns the square root of `x`.`x` is required to be greater than or equal to `0`. +- If the parameter is less than 0, returns NULL. -:::tip -Another alias for this function is `dsqrt`. -::: +## Aliases -### example +- DSQRT +## Syntax + +```sql +SQRT(<a>) ``` -mysql> select sqrt(9); -+-----------+ -| sqrt(9.0) | -+-----------+ -| 3 | -+-----------+ -mysql> select sqrt(2); -+--------------------+ -| sqrt(2.0) | -+--------------------+ -| 1.4142135623730951 | -+--------------------+ -mysql> select sqrt(100.0); -+-------------+ -| sqrt(100.0) | -+-------------+ -| 10 | -+-------------+ + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<a>` | The value whose square root is to be calculated | + +## Return Value + +The square root of parameter a. Special cases: + +- If the parameter is less than 0, returns NULL + +## Example + +```sql +select sqrt(9),sqrt(2),sqrt(-1) ``` -### keywords - SQRT, DSQRT +```text ++-------------------------+-------------------------+--------------------------+ +| sqrt(cast(9 as DOUBLE)) | sqrt(cast(2 as DOUBLE)) | sqrt(cast(-1 as DOUBLE)) | ++-------------------------+-------------------------+--------------------------+ +| 3 | 1.4142135623730951 | NULL | ++-------------------------+-------------------------+--------------------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md index bd95b3b3e7f..95bf2b8abf2 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tan.md @@ -22,30 +22,36 @@ specific language governing permissions and limitations under the License. --> -## tan +## Description -### description -#### Syntax +Returns the tangent of x, where x is the value in radians. -`DOUBLE tan(DOUBLE x)` -Returns the tangent of `x`, where `x` is in radians. - -### example +## Syntax +```sql +TAN(<x>) ``` -mysql> select tan(0); -+----------+ -| tan(0.0) | -+----------+ -| 0 | -+----------+ -mysql> select tan(1); -+--------------------+ -| tan(1.0) | -+--------------------+ -| 1.5574077246549023 | -+--------------------+ + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<x>` | The value for which the tangent is to be calculated | + +## Return Value + +Returns the tangent of x. + +## Example + +```sql +select tan(0),tan(1),tan(-1); ``` -### keywords - TAN +```text ++------------------------+------------------------+-------------------------+ +| tan(cast(0 as DOUBLE)) | tan(cast(1 as DOUBLE)) | tan(cast(-1 as DOUBLE)) | ++------------------------+------------------------+-------------------------+ +| 0 | 1.5574077246549023 | -1.5574077246549023 | ++------------------------+------------------------+-------------------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md index 81336354895..47c3c087a49 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/tanh.md @@ -22,31 +22,36 @@ specific language governing permissions and limitations under the License. --> -## tanh +## Description -### description -#### Syntax +Returns the hyperbolic tangent of x. -`DOUBLE tanh(DOUBLE x)` -Returns the hyperbolic tangent of `x`, tanh(x) = sinh(x) / cosh(x). - -### example +## Syntax +```sql +TANH(<x>) ``` -mysql> select tanh(0); -+---------+ -| tanh(0) | -+---------+ -| 0 | -+---------+ - -mysql> select tanh(1); -+---------------------+ -| tanh(1) | -+---------------------+ -| 0.76159415595576485 | -+---------------------+ + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<x>` | The value for which the hyperbolic tangent is to be calculated | + +## Return Value + +The hyperbolic tangent of parameter x. + +## Example + +```sql +select tanh(0),tanh(1); ``` -### keywords - TANH +```text ++-------------------------+-------------------------+ +| tanh(cast(0 as DOUBLE)) | tanh(cast(1 as DOUBLE)) | ++-------------------------+-------------------------+ +| 0 | 0.7615941559557649 | ++-------------------------+-------------------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md index 79e8de2886a..7d2cedf7d28 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/truncate.md @@ -22,46 +22,58 @@ specific language governing permissions and limitations under the License. --> -## truncate +## Description -### description -#### Syntax -`DOUBLE truncate(DOUBLE x, INT d)` +Perform numerical truncation on x to the number of decimal places d -Numerically truncate `x` according to the number of decimal places `d`. +## Syntax -The rules are as follows: +```sql +TRUNCATE(<x>, <d>) +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `<x>` | The value that needs to be numerically truncated | +| `<d>` | The number of decimal places to retain | + +## Return Value + +Perform numerical truncation on x to the number of decimal places d. Truncation rules: + +If d is a literal: + +- When d > 0: Keep d decimal places of x. +- When d = 0: Remove the decimal part of x and retain only the integer part. +- When d < 0: Remove the decimal part of x and replace the integer part with the number of digits specified by d, using the digit 0. -If `d` is literal: -When `d > 0`: keep `d` decimal places of `x` -When `d = 0`: remove the fractional part of `x` and keep only the integer part -When `d < 0`: Remove the fractional part of `x`, and replace the integer part with the number `0` according to the number of digits specified by `d` +If d is a column, and the first argument is of type Decimal, then the resulting Decimal will have the same number of decimal places as the input Decimal -Else if `d` is a column, and `x` has Decimal type, scale of result Decimal will always be same with input Decimal. +## Example -### example + d is a litera +```sql +select truncate(124.3867, 2),truncate(124.3867, 0),truncate(124.3867, -2); ``` -mysql> select truncate(124.3867, 2); -+-----------------------+ -| truncate(124.3867, 2) | -+-----------------------+ -| 124.38 | -+-----------------------+ -mysql> select truncate(124.3867, 0); -+-----------------------+ -| truncate(124.3867, 0) | -+-----------------------+ -| 124 | -+-----------------------+ -mysql> select truncate(-124.3867, -2); -+-------------------------+ -| truncate(-124.3867, -2) | -+-------------------------+ -| -100 | -+-------------------------+ -mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.123456" as Decimal(9,6)), number) from numbers("number"="5"); --------------- + +```text ++-----------------------+-----------------------+------------------------+ +| truncate(124.3867, 2) | truncate(124.3867, 0) | truncate(124.3867, -2) | ++-----------------------+-----------------------+------------------------+ +| 124.38 | 124 | 100 | ++-----------------------+-----------------------+------------------------+ +``` + + d is a column + +```sql +select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.123456" as Decimal(9,6)), number) from numbers("number"="5"); +``` + +```text +---------------------------------------+--------+----------------------------------------------------------------------+ | cast('123.123456' as DECIMALV3(9, 6)) | number | truncate(cast('123.123456' as DECIMALV3(9, 6)), cast(number as INT)) | +---------------------------------------+--------+----------------------------------------------------------------------+ @@ -72,6 +84,3 @@ mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.12 | 123.123456 | 4 | 123.123400 | +---------------------------------------+--------+----------------------------------------------------------------------+ ``` - -### keywords - TRUNCATE diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md index 07d7ec3f9c5..0908f748f41 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric.md @@ -1,6 +1,6 @@ --- { - "title": "uuid_numeric", + "title": "UUID_NUMERIC", "language": "en" } --- @@ -24,28 +24,30 @@ specific language governing permissions and limitations under the License. --> -## uuid_numeric -### description -#### Syntax +## Description -`LARGEINT uuid_numeric()` +Return a LARGEINT type uuid -Return a uuid in type `LARGEINT`. +## Syntax -Note that `LARGEINT` has type Int128, so we could get a negative number from `uuid_numeric()`. +```sql +UUID_NUMERIC() +``` + +## Return Value -### example +Return a LARGEINT type uuid. Note that LARGEINT is an Int128, so uuid_numeric() may produce negative values +## Example + +```sql +select uuid_numeric() ``` -mysql> select uuid_numeric(); +```text +----------------------------------------+ | uuid_numeric() | +----------------------------------------+ | 82218484683747862468445277894131281464 | +----------------------------------------+ ``` - -### keywords - - UUID UUID-NUMERIC diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md index 56a2e7ee8fd..0885479f127 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket.md @@ -24,71 +24,69 @@ specific language governing permissions and limitations under the License. --> -## width_bucket +## Description -### Description +Construct an equal-width histogram, where the histogram range is divided into equal-sized intervals, and after calculation, return the bucket number where the value of the expression falls. Special cases: -Constructs equi-width histograms, in which the histogram range is divided into intervals of identical size, and returns the bucket number into which the value of an expression falls, after it has been evaluated. The function returns an integer value or null (if any input is null). +- The function returns an integer value or NULL (if any input is NULL, it will return NULL) -#### Syntax - -`INT width_bucket(Expr expr, T min_value, T max_value, INT num_buckets)` - -#### Arguments -`expr` - -The expression for which the histogram is created. This expression must evaluate to a numeric value or to a value that can be implicitly converted to a numeric value. - -The value must be within the range of `-(2^53 - 1)` to `2^53 - 1` (inclusive). - -`min_value` and `max_value` - -The low and high end points of the acceptable range for the expression. The end points must also evaluate to numeric values and not be equal. - -The low and high end points must be within the range of `-(2^53 - 1)` to `2^53 - 1` (inclusive). In addition, the difference between these points must be less than `2^53` (i.e. `abs(max_value - min_value) < 2^53)`. - -`num_buckets` - -The desired number of buckets; must be a positive integer value. A value from the expression is assigned to each bucket, and the function then returns the corresponding bucket number. +## Syntax +```sql +WIDTH_BUCKET(<expr>, <min_value>, <max_value>, <num_buckets>) +``` -#### Returned value -It returns the bucket number into which the value of an expression falls. +## Parameters -When an expression falls outside the range, the function returns: +| Parameter | Description | +| -- | -- | +| `<expr>` | The expression for creating the histogram. This expression must evaluate to a numeric value or a value that can be implicitly converted to a numeric value. The value's range must be from `-(2^53 - 1)` to `2^53 - 1` (inclusive) | +| `<min_value>` | The lowest value point of the acceptable range for the expression. The parameter must be numeric and not equal to `<max_value>`. The range must be from `-(2^53 - 1)` to `2^53 - 1` (inclusive). Additionally, the difference between the highest and lowest value points must be less than `2^53` (for example: `abs(max_value - min_value) < 2^53)` | +| `<max_value>` | The highest value point of the acceptable range for the expression. The parameter must be numeric and not equal to `<min_value>`. The range must be from `-(2^53 - 1)` to `2^53 - 1` (inclusive). Additionally, the difference between the highest and lowest value points must be less than `2^53` (for example: `abs(max_value - min_value) < 2^53)` | +| `<num_buckets>` | The number of buckets. It must be a positive integer. The function assigns a value from the expression to each bucket and returns the corresponding bucket number | -`0` if the expression is less than `min_value`. +## Return Value -`num_buckets + 1` if the expression is greater than or equal to `max_value`. +Return the bucket number where the expression value falls. The function returns the following rules when the expression is out of range: -`null` if any input is `null`. +- If the value of the expression is less than `min_value`, return 0. +- If the value of the expression is greater than or equal to max_value, return `num_buckets + 1`. +- If any parameter is `null`, return `null` -### example +## Example ```sql DROP TABLE IF EXISTS width_bucket_test; CREATE TABLE IF NOT EXISTS width_bucket_test ( - `k1` int NULL COMMENT "", - `v1` date NULL COMMENT "", - `v2` double NULL COMMENT "", - `v3` bigint NULL COMMENT "" - ) ENGINE=OLAP - DUPLICATE KEY(`k1`) - DISTRIBUTED BY HASH(`k1`) BUCKETS 1 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1", - "storage_format" = "V2" - ); - -INSERT INTO width_bucket_test VALUES (1, "2022-11-18", 290000.00, 290000), - (2, "2023-11-18", 320000.00, 320000), - (3, "2024-11-18", 399999.99, 399999), - (4, "2025-11-18", 400000.00, 400000), - (5, "2026-11-18", 470000.00, 470000), - (6, "2027-11-18", 510000.00, 510000), - (7, "2028-11-18", 610000.00, 610000), - (8, null, null, null); +`k1` int NULL COMMENT "", +`v1` date NULL COMMENT "", +`v2` double NULL COMMENT "", +`v3` bigint NULL COMMENT "" +) ENGINE=OLAP +DUPLICATE KEY(`k1`) +DISTRIBUTED BY HASH(`k1`) BUCKETS 1 +PROPERTIES ( +"replication_allocation" = "tag.location.default: 1", +"storage_format" = "V2" +); + +INSERT INTO width_bucket_test VALUES +(1, "2022-11-18", 290000.00, 290000), +(2, "2023-11-18", 320000.00, 320000), +(3, "2024-11-18", 399999.99, 399999), +(4, "2025-11-18", 400000.00, 400000), +(5, "2026-11-18", 470000.00, 470000), +(6, "2027-11-18", 510000.00, 510000), +(7, "2028-11-18", 610000.00, 610000), +(8, null, null, null); +``` +```sql SELECT * FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+ | k1 | v1 | v2 | v3 | +------+------------+-----------+--------+ @@ -101,9 +99,13 @@ SELECT * FROM width_bucket_test ORDER BY k1; | 7 | 2028-11-18 | 610000 | 610000 | | 8 | NULL | NULL | NULL | +------+------------+-----------+--------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v1, date('2023-11-18'), date('2027-11-18'), 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -116,9 +118,13 @@ SELECT k1, v1, v2, v3, width_bucket(v1, date('2023-11-18'), date('2027-11-18'), | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v2, 200000, 600000, 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -131,9 +137,13 @@ SELECT k1, v1, v2, v3, width_bucket(v2, 200000, 600000, 4) AS w FROM width_bucke | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ +``` +```sql SELECT k1, v1, v2, v3, width_bucket(v3, 200000, 600000, 4) AS w FROM width_bucket_test ORDER BY k1; +``` +```text +------+------------+-----------+--------+------+ | k1 | v1 | v2 | v3 | w | +------+------------+-----------+--------+------+ @@ -146,7 +156,4 @@ SELECT k1, v1, v2, v3, width_bucket(v3, 200000, 600000, 4) AS w FROM width_bucke | 7 | 2028-11-18 | 610000 | 610000 | 5 | | 8 | NULL | NULL | NULL | NULL | +------+------------+-----------+--------+------+ - ``` -### keywords -WIDTH_BUCKET \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org