Skip to content

Commit a078cd2

Browse files
mattmatraversalamb
andauthored
Fix window_functions docs formatting (apache#17005)
* Fix window_functions docs formatting * Fix the source and make the docs consistent --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent 1a575a0 commit a078cd2

File tree

7 files changed

+123
-145
lines changed

7 files changed

+123
-145
lines changed

datafusion/functions-window/src/cume_dist.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,22 @@ define_udwf_and_expr!(
4646
doc_section(label = "Ranking Functions"),
4747
description = "Relative rank of the current row: (number of rows preceding or peer with the current row) / (total rows).",
4848
syntax_example = "cume_dist()",
49-
sql_example = r#"```sql
50-
--Example usage of the cume_dist window function:
51-
SELECT salary,
52-
cume_dist() OVER (ORDER BY salary) AS cume_dist
53-
FROM employees;
54-
```
49+
sql_example = r#"
5550
```sql
51+
-- Example usage of the cume_dist window function:
52+
SELECT salary,
53+
cume_dist() OVER (ORDER BY salary) AS cume_dist
54+
FROM employees;
55+
5656
+--------+-----------+
5757
| salary | cume_dist |
5858
+--------+-----------+
5959
| 30000 | 0.33 |
6060
| 50000 | 0.67 |
6161
| 70000 | 1.00 |
6262
+--------+-----------+
63-
```"#
63+
```
64+
"#
6465
)]
6566
#[derive(Debug)]
6667
pub struct CumeDist {

datafusion/functions-window/src/lead_lag.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,14 @@ static LAG_DOCUMENTATION: LazyLock<Documentation> = LazyLock::new(|| {
159159
the value of expression should be retrieved. Defaults to 1.")
160160
.with_argument("default", "The default value if the offset is \
161161
not within the partition. Must be of the same type as expression.")
162-
.with_sql_example(r#"```sql
163-
--Example usage of the lag window function:
164-
SELECT employee_id,
165-
salary,
166-
lag(salary, 1, 0) OVER (ORDER BY employee_id) AS prev_salary
167-
FROM employees;
168-
```
169-
162+
.with_sql_example(r#"
170163
```sql
164+
-- Example usage of the lag window function:
165+
SELECT employee_id,
166+
salary,
167+
lag(salary, 1, 0) OVER (ORDER BY employee_id) AS prev_salary
168+
FROM employees;
169+
171170
+-------------+--------+-------------+
172171
| employee_id | salary | prev_salary |
173172
+-------------+--------+-------------+
@@ -176,7 +175,8 @@ static LAG_DOCUMENTATION: LazyLock<Documentation> = LazyLock::new(|| {
176175
| 3 | 70000 | 50000 |
177176
| 4 | 60000 | 70000 |
178177
+-------------+--------+-------------+
179-
```"#)
178+
```
179+
"#)
180180
.build()
181181
});
182182

@@ -195,17 +195,16 @@ static LEAD_DOCUMENTATION: LazyLock<Documentation> = LazyLock::new(|| {
195195
forward the value of expression should be retrieved. Defaults to 1.")
196196
.with_argument("default", "The default value if the offset is \
197197
not within the partition. Must be of the same type as expression.")
198-
.with_sql_example(r#"```sql
199-
-- Example usage of lead() :
198+
.with_sql_example(r#"
199+
```sql
200+
-- Example usage of lead window function:
200201
SELECT
201202
employee_id,
202203
department,
203204
salary,
204205
lead(salary, 1, 0) OVER (PARTITION BY department ORDER BY salary) AS next_salary
205206
FROM employees;
206-
```
207207
208-
```sql
209208
+-------------+-------------+--------+--------------+
210209
| employee_id | department | salary | next_salary |
211210
+-------------+-------------+--------+--------------+
@@ -215,7 +214,8 @@ FROM employees;
215214
| 4 | Engineering | 40000 | 60000 |
216215
| 5 | Engineering | 60000 | 0 |
217216
+-------------+-------------+--------+--------------+
218-
```"#)
217+
```
218+
"#)
219219
.build()
220220
});
221221

datafusion/functions-window/src/nth_value.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,16 @@ static FIRST_VALUE_DOCUMENTATION: LazyLock<Documentation> = LazyLock::new(|| {
136136
"first_value(expression)",
137137
)
138138
.with_argument("expression", "Expression to operate on")
139-
.with_sql_example(r#"```sql
140-
--Example usage of the first_value window function:
141-
SELECT department,
142-
employee_id,
143-
salary,
144-
first_value(salary) OVER (PARTITION BY department ORDER BY salary DESC) AS top_salary
145-
FROM employees;
146-
```
147-
139+
.with_sql_example(
140+
r#"
148141
```sql
142+
-- Example usage of the first_value window function:
143+
SELECT department,
144+
employee_id,
145+
salary,
146+
first_value(salary) OVER (PARTITION BY department ORDER BY salary DESC) AS top_salary
147+
FROM employees;
148+
149149
+-------------+-------------+--------+------------+
150150
| department | employee_id | salary | top_salary |
151151
+-------------+-------------+--------+------------+
@@ -155,7 +155,9 @@ static FIRST_VALUE_DOCUMENTATION: LazyLock<Documentation> = LazyLock::new(|| {
155155
| Engineering | 4 | 90000 | 90000 |
156156
| Engineering | 5 | 80000 | 90000 |
157157
+-------------+-------------+--------+------------+
158-
```"#)
158+
```
159+
"#,
160+
)
159161
.build()
160162
});
161163

@@ -178,9 +180,7 @@ SELECT department,
178180
salary,
179181
last_value(salary) OVER (PARTITION BY department ORDER BY salary) AS running_last_salary
180182
FROM employees;
181-
```
182183
183-
```sql
184184
+-------------+-------------+--------+---------------------+
185185
| department | employee_id | salary | running_last_salary |
186186
+-------------+-------------+--------+---------------------+
@@ -190,7 +190,8 @@ FROM employees;
190190
| Engineering | 4 | 40000 | 40000 |
191191
| Engineering | 5 | 60000 | 60000 |
192192
+-------------+-------------+--------+---------------------+
193-
```"#)
193+
```
194+
"#)
194195
.build()
195196
});
196197

@@ -214,7 +215,8 @@ static NTH_VALUE_DOCUMENTATION: LazyLock<Documentation> = LazyLock::new(|| {
214215
"Integer. Specifies the row number (starting from 1) in the window frame.",
215216
)
216217
.with_sql_example(
217-
r#"```sql
218+
r#"
219+
```sql
218220
-- Sample employees table:
219221
CREATE TABLE employees (id INT, salary INT);
220222
INSERT INTO employees (id, salary) VALUES
@@ -230,9 +232,7 @@ SELECT nth_value(salary, 2) OVER (
230232
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
231233
) AS nth_value
232234
FROM employees;
233-
```
234235
235-
```text
236236
+-----------+
237237
| nth_value |
238238
+-----------+
@@ -242,7 +242,8 @@ FROM employees;
242242
| 40000 |
243243
| 40000 |
244244
+-----------+
245-
```"#,
245+
```
246+
"#,
246247
)
247248
.build()
248249
});

datafusion/functions-window/src/ntile.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,14 @@ pub fn ntile(arg: Expr) -> Expr {
5353
name = "expression",
5454
description = "An integer describing the number groups the partition should be split into"
5555
),
56-
sql_example = r#"```sql
57-
--Example usage of the ntile window function:
58-
SELECT employee_id,
59-
salary,
60-
ntile(4) OVER (ORDER BY salary DESC) AS quartile
61-
FROM employees;
62-
```
63-
56+
sql_example = r#"
6457
```sql
58+
-- Example usage of the ntile window function:
59+
SELECT employee_id,
60+
salary,
61+
ntile(4) OVER (ORDER BY salary DESC) AS quartile
62+
FROM employees;
63+
6564
+-------------+--------+----------+
6665
| employee_id | salary | quartile |
6766
+-------------+--------+----------+
@@ -74,7 +73,8 @@ pub fn ntile(arg: Expr) -> Expr {
7473
| 7 | 40000 | 4 |
7574
| 8 | 30000 | 4 |
7675
+-------------+--------+----------+
77-
```"#
76+
```
77+
"#
7878
)]
7979
#[derive(Debug)]
8080
pub struct Ntile {

datafusion/functions-window/src/rank.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,14 @@ static RANK_DOCUMENTATION: LazyLock<Documentation> = LazyLock::new(|| {
111111
skips ranks for identical values.",
112112

113113
"rank()")
114-
.with_sql_example(r#"```sql
115-
--Example usage of the rank window function:
116-
SELECT department,
117-
salary,
118-
rank() OVER (PARTITION BY department ORDER BY salary DESC) AS rank
119-
FROM employees;
120-
```
121-
114+
.with_sql_example(r#"
122115
```sql
116+
-- Example usage of the rank window function:
117+
SELECT department,
118+
salary,
119+
rank() OVER (PARTITION BY department ORDER BY salary DESC) AS rank
120+
FROM employees;
121+
123122
+-------------+--------+------+
124123
| department | salary | rank |
125124
+-------------+--------+------+
@@ -130,7 +129,8 @@ static RANK_DOCUMENTATION: LazyLock<Documentation> = LazyLock::new(|| {
130129
| Engineering | 90000 | 1 |
131130
| Engineering | 80000 | 2 |
132131
+-------------+--------+------+
133-
```"#)
132+
```
133+
"#)
134134
.build()
135135
});
136136

@@ -142,15 +142,14 @@ static DENSE_RANK_DOCUMENTATION: LazyLock<Documentation> = LazyLock::new(|| {
142142
Documentation::builder(DOC_SECTION_RANKING, "Returns the rank of the current row without gaps. This function ranks \
143143
rows in a dense manner, meaning consecutive ranks are assigned even for identical \
144144
values.", "dense_rank()")
145-
.with_sql_example(r#"```sql
146-
--Example usage of the dense_rank window function:
147-
SELECT department,
148-
salary,
149-
dense_rank() OVER (PARTITION BY department ORDER BY salary DESC) AS dense_rank
150-
FROM employees;
151-
```
152-
145+
.with_sql_example(r#"
153146
```sql
147+
-- Example usage of the dense_rank window function:
148+
SELECT department,
149+
salary,
150+
dense_rank() OVER (PARTITION BY department ORDER BY salary DESC) AS dense_rank
151+
FROM employees;
152+
154153
+-------------+--------+------------+
155154
| department | salary | dense_rank |
156155
+-------------+--------+------------+
@@ -173,14 +172,12 @@ static PERCENT_RANK_DOCUMENTATION: LazyLock<Documentation> = LazyLock::new(|| {
173172
Documentation::builder(DOC_SECTION_RANKING, "Returns the percentage rank of the current row within its partition. \
174173
The value ranges from 0 to 1 and is computed as `(rank - 1) / (total_rows - 1)`.", "percent_rank()")
175174
.with_sql_example(r#"```sql
176-
--Example usage of the percent_rank window function:
177-
SELECT employee_id,
178-
salary,
179-
percent_rank() OVER (ORDER BY salary) AS percent_rank
180-
FROM employees;
181-
```
175+
-- Example usage of the percent_rank window function:
176+
SELECT employee_id,
177+
salary,
178+
percent_rank() OVER (ORDER BY salary) AS percent_rank
179+
FROM employees;
182180
183-
```sql
184181
+-------------+--------+---------------+
185182
| employee_id | salary | percent_rank |
186183
+-------------+--------+---------------+

datafusion/functions-window/src/row_number.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ define_udwf_and_expr!(
4646
doc_section(label = "Ranking Functions"),
4747
description = "Number of the current row within its partition, counting from 1.",
4848
syntax_example = "row_number()",
49-
sql_example = r"```sql
50-
--Example usage of the row_number window function:
51-
SELECT department,
52-
salary,
53-
row_number() OVER (PARTITION BY department ORDER BY salary DESC) AS row_num
54-
FROM employees;
55-
```
56-
49+
sql_example = r"
5750
```sql
51+
-- Example usage of the row_number window function:
52+
SELECT department,
53+
salary,
54+
row_number() OVER (PARTITION BY department ORDER BY salary DESC) AS row_num
55+
FROM employees;
56+
5857
+-------------+--------+---------+
5958
| department | salary | row_num |
6059
+-------------+--------+---------+
@@ -65,7 +64,8 @@ define_udwf_and_expr!(
6564
| Engineering | 90000 | 1 |
6665
| Engineering | 80000 | 2 |
6766
+-------------+--------+---------+
68-
```#"
67+
```
68+
#"
6969
)]
7070
#[derive(Debug)]
7171
pub struct RowNumber {

0 commit comments

Comments
 (0)