morrySnow commented on code in PR #1835: URL: https://github.com/apache/doris-website/pull/1835#discussion_r1919509903
########## docs/sql-manual/sql-functions/window-functions/cume-dist.md: ########## @@ -11,17 +11,29 @@ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> -## WINDOW FUNCTION CUME_DIST -### description +## Description -CUME_DIST (Cumulative Distribution) is a window function commonly used to calculate the relative ranking of the current row value within a sorted result set. It returns the percentage ranking of the current row value in the result set, i.e., the ratio of the number of rows less than or equal to the current row value to the total number of rows in the result set after sorting. +CUME_DIST (Cumulative Distribution) is a window function that calculates the relative ranking of the current row value in the sorted result set. It returns the cumulative distribution value of the current row in the result set, ranging from 0 to 1. For a given row, its cumulative distribution value equals: (number of rows less than or equal to the current row value) / (total number of rows in the window partition). + +## Syntax ```sql -CUME_DIST() OVER(partition_by_clause order_by_clause) +CUME_DIST() OVER ( [ PARTITION BY <partition_expr> ] ORDER BY <order_expr> [ ASC | DESC ] ) Review Comment: 窗口函数都有的over里面的参数,我们就不用写了,只写前面函数的。所以语法也把over后面都去掉 ```suggestion CUME_DIST() ``` ########## docs/sql-manual/sql-functions/window-functions/first-value.md: ########## @@ -11,64 +11,56 @@ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> -## WINDOW FUNCTION FIRST_VALUE -### description +## Description -FIRST_VALUE() returns the first value in the window's range , ignore_null determines whether to ignore null values , the ignore_null of default value is false . +FIRST_VALUE() is a window function that returns the first value in an ordered set of values within a window partition. The handling of null values can be controlled using the IGNORE NULLS or RESPECT NULLS options. + +## Syntax ```sql -FIRST_VALUE(expr[, ignore_null]) OVER(partition_by_clause order_by_clause [window_clause]) +FIRST_VALUE( <expr> ) [ { IGNORE | RESPECT } NULLS ] Review Comment: 这里语法是不是有点儿问题。我们是之前那个,ignore_null 作为第二个参数 ########## docs/sql-manual/sql-functions/window-functions/first-value.md: ########## @@ -11,64 +11,56 @@ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> -## WINDOW FUNCTION FIRST_VALUE -### description +## Description -FIRST_VALUE() returns the first value in the window's range , ignore_null determines whether to ignore null values , the ignore_null of default value is false . +FIRST_VALUE() is a window function that returns the first value in an ordered set of values within a window partition. The handling of null values can be controlled using the IGNORE NULLS or RESPECT NULLS options. + +## Syntax ```sql -FIRST_VALUE(expr[, ignore_null]) OVER(partition_by_clause order_by_clause [window_clause]) +FIRST_VALUE( <expr> ) [ { IGNORE | RESPECT } NULLS ] + OVER ( [ PARTITION BY <partition_expr> ] ORDER BY <order_expr> [ ASC | DESC ] [ window_frame ] ) ``` -### example - +## Parameters +| Parameter | Description | +| ------------------- | ------------------------------------------------------------------------------------------------------------------- | +| expr | The expression from which to get the first value | +| partition_by_clause | Optional. Specifies the columns for partitioning, formatted as `PARTITION BY column1, column2, ...` | +| order_by_clause | Required. Specifies the columns for ordering, formatted as `ORDER BY column1 [ASC\|DESC], column2 [ASC\|DESC], ...` | +| IGNORE NULLS | Optional. When set, null values are ignored, returning the first non-null value | +| RESPECT NULLS | Optional. Default value. If the first value is null, returns null | -We have the following data +## Return Value -```sql - select id, myday, time_col, state from t; - - | id | myday | time_col | state | - |------|-------|-------------|-------| - | 3 | 21 | 04-21-13 | 3 | - | 7 | 22 | 04-22-10-24 | NULL | - | 8 | 22 | 04-22-10-25 | 9 | - | 10 | 23 | 04-23-12 | 10 | - | 4 | 22 | 04-22-10-21 | NULL | - | 9 | 23 | 04-23-11 | NULL | - | 1 | 21 | 04-21-11 | NULL | - | 5 | 22 | 04-22-10-22 | NULL | - | 12 | 24 | 02-24-10-21 | NULL | - | 2 | 21 | 04-21-12 | 2 | - | 6 | 22 | 04-22-10-23 | 5 | - | 11 | 23 | 04-23-13 | NULL | -``` +Returns the same data type as the input expression. -Use FIRST_VALUE() to group by myday and return the value of the first state in each group: +## Examples ```sql -select * , -first_value(`state`, 1) over(partition by `myday` order by `time_col` rows between 1 preceding and 1 following) as ignore_null, -first_value(`state`, 0) over(partition by `myday` order by `time_col` rows between 1 preceding and 1 following) as not_ignore_null, -first_value(`state`) over(partition by `myday` order by `time_col` rows between 1 preceding and 1 following) as ignore_null_default -from t order by `id`, `myday`, `time_col`; - -| id | myday | time_col | state | ignore_null | not_ignore_null | ignore_null_default | -|------|-------|-------------|-------|-------------|-----------------|---------------------| -| 1 | 21 | 04-21-11 | NULL | 2 | NULL | NULL | -| 2 | 21 | 04-21-12 | 2 | 2 | NULL | NULL | -| 3 | 21 | 04-21-13 | 3 | 2 | 2 | 2 | -| 4 | 22 | 04-22-10-21 | NULL | NULL | NULL | NULL | -| 5 | 22 | 04-22-10-22 | NULL | 5 | NULL | NULL | -| 6 | 22 | 04-22-10-23 | 5 | 5 | NULL | NULL | -| 7 | 22 | 04-22-10-24 | NULL | 5 | 5 | 5 | -| 8 | 22 | 04-22-10-25 | 9 | 9 | NULL | NULL | -| 9 | 23 | 04-23-11 | NULL | 10 | NULL | NULL | -| 10 | 23 | 04-23-12 | 10 | 10 | NULL | NULL | -| 11 | 23 | 04-23-13 | NULL | 10 | 10 | 10 | -| 12 | 24 | 02-24-10-21 | NULL | NULL | NULL | NULL | +SELECT + column1, + column2, + FIRST_VALUE(column2) OVER ( + PARTITION BY column1 Review Comment: 可以加个 ignore_null 的例子 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org