You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by da...@apache.org on 2023/04/02 08:35:18 UTC
[doris] branch master updated: [fix](doc) suggest use window function to replace running_difference (#18281)
This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 04929ff6d4 [fix](doc) suggest use window function to replace running_difference (#18281)
04929ff6d4 is described below
commit 04929ff6d4f7b5bd671eed626ee51e0ad346a54a
Author: morrySnow <10...@users.noreply.github.com>
AuthorDate: Sun Apr 2 16:35:10 2023 +0800
[fix](doc) suggest use window function to replace running_difference (#18281)
---
.../sql-functions/math-functions/running_difference.md | 9 ++++++++-
.../sql-functions/math-functions/running_difference.md | 12 ++++++++++--
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/docs/en/docs/sql-manual/sql-functions/math-functions/running_difference.md b/docs/en/docs/sql-manual/sql-functions/math-functions/running_difference.md
index fd19f187a5..30bd00eee3 100644
--- a/docs/en/docs/sql-manual/sql-functions/math-functions/running_difference.md
+++ b/docs/en/docs/sql-manual/sql-functions/math-functions/running_difference.md
@@ -32,7 +32,14 @@ under the License.
Calculates the difference between successive row values in the data block.
The result of the function depends on the affected data blocks and the order of data in the block.
-The rows order used during the calculation of running_difference can differ from the order of rows returned to the user. To prevent that you can make a subquery with **ORDER BY** and call the function from outside the subquery.
+The rows order used during the calculation of running_difference can differ from the order of rows returned to the user. The function will be deprecated in the future. Please use window function instead, below is the example:
+```sql
+-- running difference(x)
+SELECT running_difference(x) FROM t ORDER BY k;
+
+-- window function
+SELECT x - lag(x, 1, 0) OVER (ORDER BY k) FROM t;
+```
#### Arguments
`x` - A list of data.TINYINT,SMALLINT,INT,BIGINT,LARGEINT,FLOAT,DOUBLE,DATE,DATETIME,DECIMAL
diff --git a/docs/zh-CN/docs/sql-manual/sql-functions/math-functions/running_difference.md b/docs/zh-CN/docs/sql-manual/sql-functions/math-functions/running_difference.md
index c9f3f00306..2b4c5987ef 100644
--- a/docs/zh-CN/docs/sql-manual/sql-functions/math-functions/running_difference.md
+++ b/docs/zh-CN/docs/sql-manual/sql-functions/math-functions/running_difference.md
@@ -29,12 +29,20 @@ under the License.
`running_difference(x);`
计算数据块中连续行值的差值。该函数的结果取决于受影响的数据块和块中数据的顺序。
-计算 running_difference 期间使用的行顺序可能与返回给用户的行顺序不同。为防止您可以使用 **ORDER BY** 进行子查询并从子查询外部调用该函数。
+计算 running_difference 期间使用的行顺序可能与返回给用户的行顺序不同。所以结果是不稳定的。**此函数会在后续版本中废弃**。
+推荐使用窗口函数完成预期功能。举例如下:
+```sql
+-- running difference(x)
+SELECT running_difference(x) FROM t ORDER BY k;
+
+-- 窗口函数
+SELECT x - lag(x, 1, 0) OVER (ORDER BY k) FROM t;
+```
#### Arguments
`x` - 一列数据.数据类型可以是TINYINT,SMALLINT,INT,BIGINT,LARGEINT,FLOAT,DOUBLE,DATE,DATETIME,DECIMAL
-##### Returned value
+#### Returned value
第一行返回 0,随后的每一行返回与前一行的差值。
### example
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org