Skip to content

Commit 8a88fdc

Browse files
authored
update docs (#13395)
1 parent 4b5e374 commit 8a88fdc

File tree

4 files changed

+110
-313
lines changed

4 files changed

+110
-313
lines changed

dev/update_function_docs.sh

+2-8
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ npx [email protected] --write "$TARGET_FILE"
113113

114114
echo "'$TARGET_FILE' successfully updated!"
115115

116-
TARGET_FILE="docs/source/user-guide/sql/window_functions_new.md"
116+
TARGET_FILE="docs/source/user-guide/sql/window_functions.md"
117117
PRINT_WINDOW_FUNCTION_DOCS_COMMAND="cargo run --manifest-path datafusion/core/Cargo.toml --bin print_functions_docs -- window"
118118

119119
echo "Inserting header"
@@ -146,13 +146,7 @@ dev/update_function_docs.sh file for updating surrounding text.
146146
-->
147147
148148
149-
# Window Functions (NEW)
150-
151-
Note: this documentation is in the process of being migrated to be [automatically created from the codebase].
152-
Please see the [Window Functions (Old)](window_functions.md) page for
153-
the rest of the documentation.
154-
155-
[automatically created from the codebase]: https://github.com/apache/datafusion/issues/12740
149+
# Window Functions
156150
157151
A _window function_ performs a calculation across a set of table rows that are somehow related to the current row.
158152
This is comparable to the type of calculation that can be done with an aggregate function.

docs/source/user-guide/sql/index.rst

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ SQL Reference
3131
operators
3232
aggregate_functions
3333
window_functions
34-
window_functions_new
3534
scalar_functions
3635
special_functions
3736
sql_status

docs/source/user-guide/sql/window_functions.md

+108-14
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,25 @@
1212
Unless required by applicable law or agreed to in writing,
1313
software distributed under the License is distributed on an
1414
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15-
KIND, either expressioness or implied. See the License for the
15+
KIND, either express or implied. See the License for the
1616
specific language governing permissions and limitations
1717
under the License.
1818
-->
1919

20+
<!---
21+
This file was generated by the dev/update_function_docs.sh script.
22+
Do not edit it manually as changes will be overwritten.
23+
Instead, edit the WindowUDFImpl's documentation() function to
24+
update documentation for an individual UDF or the
25+
dev/update_function_docs.sh file for updating surrounding text.
26+
-->
27+
2028
# Window Functions
2129

2230
A _window function_ performs a calculation across a set of table rows that are somehow related to the current row.
23-
24-
Note: this documentation is in the process of being migrated to be [automatically created from the codebase].
25-
Please see the [Window Functions (new)](window_functions_new.md) page for
26-
the rest of the documentation.
27-
28-
[automatically created from the codebase]: https://github.com/apache/datafusion/issues/12740
29-
30-
Window functions are comparable to the type of calculation that can be done with an aggregate function. However, window functions do not cause rows to become grouped into a single output row like non-window aggregate calls would. Instead, the rows retain their separate identities. Behind the scenes, the window function is able to access more than just the current row of the query result
31+
This is comparable to the type of calculation that can be done with an aggregate function.
32+
However, window functions do not cause rows to become grouped into a single output row like non-window aggregate calls would.
33+
Instead, the rows retain their separate identities. Behind the scenes, the window function is able to access more than just the current row of the query result
3134

3235
Here is an example that shows how to compare each employee's salary with the average salary in his or her department:
3336

@@ -146,45 +149,136 @@ RANGE and GROUPS modes require an ORDER BY clause (with RANGE the ORDER BY must
146149

147150
All [aggregate functions](aggregate_functions.md) can be used as window functions.
148151

149-
## Analytical functions
152+
## Ranking Functions
153+
154+
- [cume_dist](#cume_dist)
155+
- [dense_rank](#dense_rank)
156+
- [ntile](#ntile)
157+
- [percent_rank](#percent_rank)
158+
- [rank](#rank)
159+
- [row_number](#row_number)
160+
161+
### `cume_dist`
162+
163+
Relative rank of the current row: (number of rows preceding or peer with current row) / (total rows).
164+
165+
```
166+
cume_dist()
167+
```
168+
169+
### `dense_rank`
170+
171+
Returns the rank of the current row without gaps. This function ranks rows in a dense manner, meaning consecutive ranks are assigned even for identical values.
172+
173+
```
174+
dense_rank()
175+
```
176+
177+
### `ntile`
178+
179+
Integer ranging from 1 to the argument value, dividing the partition as equally as possible
180+
181+
```
182+
ntile(expression)
183+
```
184+
185+
#### Arguments
186+
187+
- **expression**: An integer describing the number groups the partition should be split into
188+
189+
### `percent_rank`
190+
191+
Returns the percentage rank of the current row within its partition. The value ranges from 0 to 1 and is computed as `(rank - 1) / (total_rows - 1)`.
192+
193+
```
194+
percent_rank()
195+
```
196+
197+
### `rank`
198+
199+
Returns the rank of the current row within its partition, allowing gaps between ranks. This function provides a ranking similar to `row_number`, but skips ranks for identical values.
200+
201+
```
202+
rank()
203+
```
204+
205+
### `row_number`
206+
207+
Number of the current row within its partition, counting from 1.
208+
209+
```
210+
row_number()
211+
```
212+
213+
## Analytical Functions
150214

151215
- [first_value](#first_value)
216+
- [lag](#lag)
152217
- [last_value](#last_value)
218+
- [lead](#lead)
153219
- [nth_value](#nth_value)
154220

155221
### `first_value`
156222

157223
Returns value evaluated at the row that is the first row of the window frame.
158224

159-
```sql
225+
```
160226
first_value(expression)
161227
```
162228

163229
#### Arguments
164230

165231
- **expression**: Expression to operate on
166232

233+
### `lag`
234+
235+
Returns value evaluated at the row that is offset rows before the current row within the partition; if there is no such row, instead return default (which must be of the same type as value).
236+
237+
```
238+
lag(expression, offset, default)
239+
```
240+
241+
#### Arguments
242+
243+
- **expression**: Expression to operate on
244+
- **offset**: Integer. Specifies how many rows back the value of expression should be retrieved. Defaults to 1.
245+
- **default**: The default value if the offset is not within the partition. Must be of the same type as expression.
246+
167247
### `last_value`
168248

169249
Returns value evaluated at the row that is the last row of the window frame.
170250

171-
```sql
251+
```
172252
last_value(expression)
173253
```
174254

175255
#### Arguments
176256

177257
- **expression**: Expression to operate on
178258

259+
### `lead`
260+
261+
Returns value evaluated at the row that is offset rows after the current row within the partition; if there is no such row, instead return default (which must be of the same type as value).
262+
263+
```
264+
lead(expression, offset, default)
265+
```
266+
267+
#### Arguments
268+
269+
- **expression**: Expression to operate on
270+
- **offset**: Integer. Specifies how many rows forward the value of expression should be retrieved. Defaults to 1.
271+
- **default**: The default value if the offset is not within the partition. Must be of the same type as expression.
272+
179273
### `nth_value`
180274

181275
Returns value evaluated at the row that is the nth row of the window frame (counting from 1); null if no such row.
182276

183-
```sql
277+
```
184278
nth_value(expression, n)
185279
```
186280

187281
#### Arguments
188282

189283
- **expression**: The name the column of which nth value to retrieve
190-
- **n**: Integer. Specifies the _n_ in nth
284+
- **n**: Integer. Specifies the n in nth

0 commit comments

Comments
 (0)