This is an automated email from the ASF dual-hosted git repository.
yiguolei 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 e5df8f4b3a6 feat: add UNIFORM function docs (#2853)
e5df8f4b3a6 is described below
commit e5df8f4b3a6bda2b77e5b0103836900b404f4bb6
Author: zclllyybb <[email protected]>
AuthorDate: Tue Sep 9 12:12:18 2025 +0800
feat: add UNIFORM function docs (#2853)
doc of https://github.com/apache/doris/pull/55789
## Versions
- [x] dev
- [ ] 3.0
- [ ] 2.1
- [ ] 2.0
## Languages
- [x] Chinese
- [x] English
## Docs Checklist
- [ ] Checked by AI
- [ ] Test Cases Built
---
.../scalar-functions/numeric-functions/uniform.md | 161 +++++++++++++++++++++
.../scalar-functions/numeric-functions/uniform.md | 161 +++++++++++++++++++++
sidebars.json | 1 +
3 files changed, 323 insertions(+)
diff --git
a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/uniform.md
b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/uniform.md
new file mode 100644
index 00000000000..87277e2a6aa
--- /dev/null
+++
b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/uniform.md
@@ -0,0 +1,161 @@
+---
+{
+ "title": "UNIFORM",
+ "language": "en"
+}
+---
+
+## Description
+
+Using the given random seed, uniformly sample and generate random numbers
within a specific range.
+
+## Syntax
+
+```sql
+UNIFORM( <min> , <max> , <gen> )
+```
+
+## Parameters
+
+| Parameter | Description |
+|-----------|------------|
+| `<min>` | The lower limit of the random number, accepts numeric type, must
be a literal |
+| `<max>` | The upper limit of the random number, accepts numeric type, must
be a literal |
+| `<gen>` | Integer, random seed, commonly generated by the
[RANDOM](./random.md) function randomly. |
+
+## Return value
+
+Return a random number within `[<min>, <max>]`. If both `<min>` and `<max>`
are integers, the return value type is `BIGINT`, otherwise it is `DOUBLE`.
+
+Note that unlike Snowflake's [common
usage](https://docs.snowflake.com/en/sql-reference/functions/uniform), because
the RANDOM function in Doris returns a floating-point number between 0 and 1 by
default, if you use `RANDOM()` as a random seed, you should attach a multiplier
to make the result distributed within an integer range. See the examples for
details.
+
+## Example
+
+When all input parameters are integers, return an integer:
+
+```sql
+select uniform(-100, 100, random() * 10000) as result from numbers("number" =
"10");
+```
+
+```text
++--------+
+| result |
++--------+
+| -82 |
+| -79 |
+| 21 |
+| 19 |
+| 50 |
+| 53 |
+| -100 |
+| -67 |
+| 46 |
+| 40 |
++--------+
+```
+
+When input parameters are not all integers, return the double type:
+
+```sql
+select uniform(1, 100., random() * 10000) as result from numbers("number" =
"10");
+```
+
+```text
++-------------------+
+| result |
++-------------------+
+| 84.25057360297031 |
+| 63.34296160793329 |
+| 81.8770598286311 |
+| 26.53334147605743 |
+| 17.42787914185705 |
+| 2.532901549399078 |
+| 63.72223367924216 |
+| 78.42165786093118 |
+| 18.913688179943 |
+| 41.73057334477316 |
++-------------------+
+```
+
+Must be literal parameters:
+
+```sql
+select uniform(1, unix_timestamp(), random() * 10000) as result from
numbers("number" = "10");
+```
+
+```text
+ERROR 1105 (HY000): errCode = 2, detailMessage = The second parameter (max) of
uniform function must be literal
+```
+
+Must be literal parameters:
+
+```sql
+select uniform(1, ksint, random()) from fn_test;
+```
+
+```text
+ERROR 1105 (HY000): errCode = 2, detailMessage = The second parameter (max) of
uniform function must be literal
+```
+
+Fixed seeds will produce fixed results (the result of `random()` is
distributed between 0 and 1, and when used directly, the seed parameter of
`uniform` is always `0`):
+
+```sql
+select uniform(-100, 100, random()) as result from numbers("number" = "10");
+```
+
+```text
++--------+
+| result |
++--------+
+| -68 |
+| -68 |
+| -68 |
+| -68 |
+| -68 |
+| -68 |
+| -68 |
+| -68 |
+| -68 |
+| -68 |
++--------+
+```
+
+When any input is NULL, the output is also NULL:
+
+```sql
+select uniform(-100, NULL, random() * 10000) as result from numbers("number" =
"10");
+```
+
+```text
++--------+
+| result |
++--------+
+| NULL |
+| NULL |
+| NULL |
+| NULL |
+| NULL |
+| NULL |
+| NULL |
+| NULL |
+| NULL |
+| NULL |
++--------+
+```
+
+```sql
+select k0, uniform(0, 1000, k0) from it order by k0;
+```
+
+```text
++------+----------------------+
+| k0 | uniform(0, 1000, k0) |
++------+----------------------+
+| NULL | NULL |
+| 1 | 134 |
+| 2 | 904 |
+| 3 | 559 |
+| 4 | 786 |
+| 5 | 673 |
++------+----------------------+
+```
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/uniform.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/uniform.md
new file mode 100644
index 00000000000..6e680d17c9d
--- /dev/null
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/uniform.md
@@ -0,0 +1,161 @@
+---
+{
+ "title": "UNIFORM",
+ "language": "zh-CN"
+}
+---
+
+## 描述
+
+使用给定的随机数种子,在特定范围内均匀采样生成随机数。
+
+## 语法
+
+```sql
+UNIFORM( <min> , <max> , <gen> )
+```
+
+## 参数
+
+| 参数 | 说明 |
+| -- | -- |
+| `<min>` | 随机数的下限,接受数字类型,必须为字面量 |
+| `<max>` | 随机数的上限,接受数字类型,必须为字面量 |
+| `<gen>` | 整数,随机数种子,常用 [RANDOM](./random.md) 函数随机生成 |
+
+## 返回值
+
+返回在 `[<min>, <max>]` 范围内的随机数。如果 `<min>` 和 `<max>` 均为整数,则返回值类型为
`BIGINT`,否则返回值类型为 `DOUBLE`。
+
+注意与 Snowflake
的[常见用法](https://docs.snowflake.com/en/sql-reference/functions/uniform)不同,由于
Doris 中 RANDOM 的函数返回值默认为 0-1 之间的浮点数,因此如果使用 `RANDOM()`
作为随机种子,应当附加乘数使其结果一个整数范围内分布。详情见示例。
+
+## 举例
+
+输入参数全为整数时,返回整数:
+
+```sql
+select uniform(-100, 100, random() * 10000) as result from numbers("number" =
"10");
+```
+
+```text
++--------+
+| result |
++--------+
+| -82 |
+| -79 |
+| 21 |
+| 19 |
+| 50 |
+| 53 |
+| -100 |
+| -67 |
+| 46 |
+| 40 |
++--------+
+```
+
+输入参数有非整数时,返回 double 类型:
+
+```sql
+select uniform(1, 100., random() * 10000) as result from numbers("number" =
"10");
+```
+
+```text
++-------------------+
+| result |
++-------------------+
+| 84.25057360297031 |
+| 63.34296160793329 |
+| 81.8770598286311 |
+| 26.53334147605743 |
+| 17.42787914185705 |
+| 2.532901549399078 |
+| 63.72223367924216 |
+| 78.42165786093118 |
+| 18.913688179943 |
+| 41.73057334477316 |
++-------------------+
+```
+
+必须为字面量:
+
+```sql
+select uniform(1, unix_timestamp(), random() * 10000) as result from
numbers("number" = "10");
+```
+
+```text
+ERROR 1105 (HY000): errCode = 2, detailMessage = The second parameter (max) of
uniform function must be literal
+```
+
+必须为字面量:
+
+```sql
+select uniform(1, ksint, random()) from fn_test;
+```
+
+```text
+ERROR 1105 (HY000): errCode = 2, detailMessage = The second parameter (max) of
uniform function must be literal
+```
+
+固定的种子将产生固定的结果(`random()` 的结果在 0-1 之间分布,直接使用时 `uniform` 的种子参数始终为 `0`):
+
+```sql
+select uniform(-100, 100, random()) as result from numbers("number" = "10");
+```
+
+```text
++--------+
+| result |
++--------+
+| -68 |
+| -68 |
+| -68 |
+| -68 |
+| -68 |
+| -68 |
+| -68 |
+| -68 |
+| -68 |
+| -68 |
++--------+
+```
+
+当任意输入为 NULL 时,输出也为 NULL:
+
+```sql
+select uniform(-100, NULL, random() * 10000) as result from numbers("number" =
"10");
+```
+
+```text
++--------+
+| result |
++--------+
+| NULL |
+| NULL |
+| NULL |
+| NULL |
+| NULL |
+| NULL |
+| NULL |
+| NULL |
+| NULL |
+| NULL |
++--------+
+```
+
+```sql
+select k0, uniform(0, 1000, k0) from it order by k0;
+```
+
+```text
++------+----------------------+
+| k0 | uniform(0, 1000, k0) |
++------+----------------------+
+| NULL | NULL |
+| 1 | 134 |
+| 2 | 904 |
+| 3 | 559 |
+| 4 | 786 |
+| 5 | 673 |
++------+----------------------+
+```
diff --git a/sidebars.json b/sidebars.json
index 9e38f27c999..2599e2cad2e 100644
--- a/sidebars.json
+++ b/sidebars.json
@@ -1220,6 +1220,7 @@
"sql-manual/sql-functions/scalar-functions/numeric-functions/tan",
"sql-manual/sql-functions/scalar-functions/numeric-functions/tanh",
"sql-manual/sql-functions/scalar-functions/numeric-functions/truncate",
+
"sql-manual/sql-functions/scalar-functions/numeric-functions/uniform",
"sql-manual/sql-functions/scalar-functions/numeric-functions/uuid_numeric",
"sql-manual/sql-functions/scalar-functions/numeric-functions/width-bucket",
"sql-manual/sql-functions/scalar-functions/numeric-functions/even",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]