This is an automated email from the ASF dual-hosted git repository.

zhangstar333 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 6417a8d0f96 [doc](agg) support percentile_reservoir agg function 
(#2736)
6417a8d0f96 is described below

commit 6417a8d0f966430a95fbb889f66ab85cb6db72b4
Author: zhangstar333 <[email protected]>
AuthorDate: Fri Oct 24 14:22:27 2025 +0800

    [doc](agg) support percentile_reservoir agg function (#2736)
    
    ## Versions
    
    - [x] dev
    - [ ] 3.0
    - [ ] 2.1
    - [ ] 2.0
    
    ## Languages
    
    - [x] Chinese
    - [x] English
    
    ## Docs Checklist
    
    - [ ] Checked by AI
    - [ ] Test Cases Built
---
 .../aggregate-functions/percentile_reservoir.md    | 89 +++++++++++++++++++++
 .../aggregate-functions/percentile_reservoir.md    | 91 ++++++++++++++++++++++
 sidebars.json                                      |  1 +
 3 files changed, 181 insertions(+)

diff --git 
a/docs/sql-manual/sql-functions/aggregate-functions/percentile_reservoir.md 
b/docs/sql-manual/sql-functions/aggregate-functions/percentile_reservoir.md
new file mode 100644
index 00000000000..3d2b562adcb
--- /dev/null
+++ b/docs/sql-manual/sql-functions/aggregate-functions/percentile_reservoir.md
@@ -0,0 +1,89 @@
+---
+{
+    "title": "PERCENTILE_RESERVOIR",
+    "language": "en"
+}
+---
+
+## Description
+
+This function applies [reservoir 
sampling](https://en.wikipedia.org/wiki/Reservoir_sampling) with a reservoir 
size up to 8192 and a random number generator for sampling. This used to 
calculate approximate percentiles at position `p`.
+The value of `p` is between `0` and `1`.
+Note that this is not the average of the two numbers.
+
+## Syntax
+
+```sql
+PERCENTILE_RESERVOIR(<col>, <p>)
+```
+
+## Parameters
+
+| Parameter | Description |
+| -- | -- |
+| `<col>` | The column to be calculated as the approximate percentile, 
Supported types: Double |
+| `<p>` | The approximate percentile to be calculated, a constant value, 
Supported types: Double with a value range of `[0.0, 1.0]`. |
+
+## Return Value
+
+Return the approximate percentile of the specified column, with a return type 
of `DOUBLE`.
+- Returns `NULL` when the input column is `NULL`
+
+## Examples
+
+```sql
+-- Create sample table
+CREATE TABLE sales_data
+(
+    product_id INT,
+    sale_price DECIMAL(10, 2)
+) DUPLICATE KEY(`product_id`)
+DISTRIBUTED BY HASH(`product_id`) BUCKETS AUTO
+PROPERTIES (
+    "replication_allocation" = "tag.location.default: 1"
+);
+
+-- Insert sample data
+INSERT INTO sales_data VALUES
+(1, 10.00),
+(1, 15.00),
+(1, 20.00),
+(1, 25.00),
+(1, 30.00),
+(1, 35.00),
+(1, 40.00),
+(1, 45.00),
+(1, 50.00),
+(1, 100.00);
+
+-- Calculate different percentiles of sales prices
+SELECT 
+    percentile_reservoir(sale_price, 0.5)  as median_price,     -- Median
+    percentile_reservoir(sale_price, 0.75) as p75_price,        -- 75th 
percentile
+    percentile_reservoir(sale_price, 0.90) as p90_price,        -- 90th 
percentile
+    percentile_reservoir(sale_price, 0.95) as p95_price,        -- 95th 
percentile
+    percentile_reservoir(null, 0.99)       as p99_null          -- Null value 
at 99th percentile
+FROM sales_data;
+```
+
+```text
++--------------+-----------+-------------------+-------------------+----------+
+| median_price | p75_price | p90_price         | p95_price         | p99_null |
++--------------+-----------+-------------------+-------------------+----------+
+|         32.5 |     43.75 | 54.99999999999998 | 77.49999999999994 |     NULL |
++--------------+-----------+-------------------+-------------------+----------+
+```
+
+```sql
+select percentile(sale_price, NULL) from sales_data;
+```
+
+If all input values are NULL, returns NULL.
+
+```text
++------------------------------+
+| percentile(sale_price, NULL) |
++------------------------------+
+|                         NULL |
++------------------------------+
+```
\ No newline at end of file
diff --git 
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/percentile_reservoir.md
 
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/percentile_reservoir.md
new file mode 100644
index 00000000000..e6ab7245b5c
--- /dev/null
+++ 
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/percentile_reservoir.md
@@ -0,0 +1,91 @@
+---
+{
+    "title": "PERCENTILE_RESERVOIR",
+    "language": "zh-CN"
+}
+---
+
+## 描述
+
+计算近似的第 `p` 位百分数。
+该函数采用[reservoir 
sampling](https://en.wikipedia.org/wiki/Reservoir_sampling)算法,reservoir最大容量为8192,并使用随机数生成器进行抽样,结果是非确定性的。适用于大数据量下。
+`p` 的值介于 `0` 到 `1` 之间,并注意这不是两数字的平均数.
+
+
+## 语法
+
+```sql
+PERCENTILE_RESERVOIR(<col>, <p>)
+```
+
+## 参数
+
+| 参数 | 说明 |
+| -- | -- |
+| `<col>` | 需要被计算近似的百分位数的列,支持类型: DOUBLE类型。 |
+| `<p>` | 需要近似的百分位数,常量,支持类型: DOUBLE类型,取值为 `[0.0, 1.0]`。 |
+
+## 返回值
+
+返回指定列的近似的百分位数,类型为 `DOUBLE`。
+如果组内没有合法数据,则返回 NULL 。
+
+## 举例
+
+```sql
+-- 创建示例表
+CREATE TABLE sales_data
+(
+    product_id INT,
+    sale_price DECIMAL(10, 2)
+) DUPLICATE KEY(`product_id`)
+DISTRIBUTED BY HASH(`product_id`) BUCKETS AUTO
+PROPERTIES (
+    "replication_allocation" = "tag.location.default: 1"
+);
+
+-- 插入示例数据
+INSERT INTO sales_data VALUES
+(1, 10.00),
+(1, 15.00),
+(1, 20.00),
+(1, 25.00),
+(1, 30.00),
+(1, 35.00),
+(1, 40.00),
+(1, 45.00),
+(1, 50.00),
+(1, 100.00);
+
+-- 计算不同百分位的销售价格
+SELECT 
+    percentile_reservoir(sale_price, 0.5)  as median_price,     -- 中位数
+    percentile_reservoir(sale_price, 0.75) as p75_price,        -- 75 分位数
+    percentile_reservoir(sale_price, 0.90) as p90_price,        -- 90 分位数
+    percentile_reservoir(sale_price, 0.95) as p95_price,        -- 95 分位数
+    percentile_reservoir(null, 0.99)       as p99_null          -- null 的 99 
分位数
+FROM sales_data;
+```
+
+```text
++--------------+-----------+-------------------+-------------------+----------+
+| median_price | p75_price | p90_price         | p95_price         | p99_null |
++--------------+-----------+-------------------+-------------------+----------+
+|         32.5 |     43.75 | 54.99999999999998 | 77.49999999999994 |     NULL |
++--------------+-----------+-------------------+-------------------+----------+
+```
+
+
+```sql
+select percentile_reservoir(sale_price, NULL) from sales_data;
+```
+
+如果输入数据均为 NULL,则返回NULL。
+
+```text
++----------------------------------------+
+| percentile_reservoir(sale_price, NULL) |
++----------------------------------------+
+|                                   NULL |
++----------------------------------------+
+```
diff --git a/sidebars.json b/sidebars.json
index a36df116179..090e96b436d 100644
--- a/sidebars.json
+++ b/sidebars.json
@@ -1844,6 +1844,7 @@
                                 
"sql-manual/sql-functions/aggregate-functions/percentile-approx",
                                 
"sql-manual/sql-functions/aggregate-functions/percentile-array",
                                 
"sql-manual/sql-functions/aggregate-functions/percentile-approx-weighted",
+                                
"sql-manual/sql-functions/aggregate-functions/percentile_reservoir",
                                 
"sql-manual/sql-functions/aggregate-functions/quantile-union",
                                 
"sql-manual/sql-functions/aggregate-functions/regr-intercept",
                                 
"sql-manual/sql-functions/aggregate-functions/regr-slope",


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to