Skip to content

Commit 6ac1999

Browse files
authored
doc-gen: migrate window functions documentation to attribute based (#13739)
* doc-gen: migrate window functions documentation Signed-off-by: zjregee <[email protected]> * fix: update Cargo.lock --------- Signed-off-by: zjregee <[email protected]>
1 parent 4148729 commit 6ac1999

File tree

5 files changed

+44
-54
lines changed

5 files changed

+44
-54
lines changed

datafusion-cli/Cargo.lock

Lines changed: 15 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/functions-window/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ path = "src/lib.rs"
3939

4040
[dependencies]
4141
datafusion-common = { workspace = true }
42+
datafusion-doc = { workspace = true }
4243
datafusion-expr = { workspace = true }
4344
datafusion-functions-window-common = { workspace = true }
45+
datafusion-macros = { workspace = true }
4446
datafusion-physical-expr = { workspace = true }
4547
datafusion-physical-expr-common = { workspace = true }
4648
log = { workspace = true }

datafusion/functions-window/src/cume_dist.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ use datafusion_common::arrow::array::{ArrayRef, Float64Array};
2121
use datafusion_common::arrow::datatypes::DataType;
2222
use datafusion_common::arrow::datatypes::Field;
2323
use datafusion_common::Result;
24-
use datafusion_expr::window_doc_sections::DOC_SECTION_RANKING;
2524
use datafusion_expr::{
2625
Documentation, PartitionEvaluator, Signature, Volatility, WindowUDFImpl,
2726
};
2827
use datafusion_functions_window_common::field;
2928
use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
29+
use datafusion_macros::user_doc;
3030
use field::WindowUDFFieldArgs;
3131
use std::any::Any;
3232
use std::fmt::Debug;
3333
use std::iter;
3434
use std::ops::Range;
35-
use std::sync::{Arc, OnceLock};
35+
use std::sync::Arc;
3636

3737
define_udwf_and_expr!(
3838
CumeDist,
@@ -41,6 +41,11 @@ define_udwf_and_expr!(
4141
);
4242

4343
/// CumeDist calculates the cume_dist in the window function with order by
44+
#[user_doc(
45+
doc_section(label = "Ranking Functions"),
46+
description = "Relative rank of the current row: (number of rows preceding or peer with current row) / (total rows).",
47+
syntax_example = "cume_dist()"
48+
)]
4449
#[derive(Debug)]
4550
pub struct CumeDist {
4651
signature: Signature,
@@ -86,19 +91,10 @@ impl WindowUDFImpl for CumeDist {
8691
}
8792

8893
fn documentation(&self) -> Option<&Documentation> {
89-
Some(get_cume_dist_doc())
94+
self.doc()
9095
}
9196
}
9297

93-
static DOCUMENTATION: OnceLock<Documentation> = OnceLock::new();
94-
95-
fn get_cume_dist_doc() -> &'static Documentation {
96-
DOCUMENTATION.get_or_init(|| {
97-
Documentation::builder(DOC_SECTION_RANKING, "Relative rank of the current row: (number of rows preceding or peer with current row) / (total rows).", "cume_dist()")
98-
.build()
99-
})
100-
}
101-
10298
#[derive(Debug, Default)]
10399
pub(crate) struct CumeDistEvaluator;
104100

datafusion/functions-window/src/ntile.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@
1919
2020
use std::any::Any;
2121
use std::fmt::Debug;
22-
use std::sync::{Arc, OnceLock};
22+
use std::sync::Arc;
2323

2424
use crate::utils::{
2525
get_scalar_value_from_args, get_signed_integer, get_unsigned_integer,
2626
};
2727
use datafusion_common::arrow::array::{ArrayRef, UInt64Array};
2828
use datafusion_common::arrow::datatypes::{DataType, Field};
2929
use datafusion_common::{exec_err, DataFusionError, Result};
30-
use datafusion_expr::window_doc_sections::DOC_SECTION_RANKING;
3130
use datafusion_expr::{
3231
Documentation, Expr, PartitionEvaluator, Signature, Volatility, WindowUDFImpl,
3332
};
3433
use datafusion_functions_window_common::field;
3534
use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
35+
use datafusion_macros::user_doc;
3636
use field::WindowUDFFieldArgs;
3737

3838
get_or_init_udwf!(
@@ -45,6 +45,15 @@ pub fn ntile(arg: Expr) -> Expr {
4545
ntile_udwf().call(vec![arg])
4646
}
4747

48+
#[user_doc(
49+
doc_section(label = "Ranking Functions"),
50+
description = "Integer ranging from 1 to the argument value, dividing the partition as equally as possible",
51+
syntax_example = "ntile(expression)",
52+
argument(
53+
name = "expression",
54+
description = "An integer describing the number groups the partition should be split into"
55+
)
56+
)]
4857
#[derive(Debug)]
4958
pub struct Ntile {
5059
signature: Signature,
@@ -78,16 +87,6 @@ impl Default for Ntile {
7887
}
7988
}
8089

81-
static DOCUMENTATION: OnceLock<Documentation> = OnceLock::new();
82-
83-
fn get_ntile_doc() -> &'static Documentation {
84-
DOCUMENTATION.get_or_init(|| {
85-
Documentation::builder(DOC_SECTION_RANKING, "Integer ranging from 1 to the argument value, dividing the partition as equally as possible", "ntile(expression)")
86-
.with_argument("expression","An integer describing the number groups the partition should be split into")
87-
.build()
88-
})
89-
}
90-
9190
impl WindowUDFImpl for Ntile {
9291
fn as_any(&self) -> &dyn Any {
9392
self
@@ -135,7 +134,7 @@ impl WindowUDFImpl for Ntile {
135134
}
136135

137136
fn documentation(&self) -> Option<&Documentation> {
138-
Some(get_ntile_doc())
137+
self.doc()
139138
}
140139
}
141140

datafusion/functions-window/src/row_number.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,16 @@ use datafusion_common::arrow::compute::SortOptions;
2323
use datafusion_common::arrow::datatypes::DataType;
2424
use datafusion_common::arrow::datatypes::Field;
2525
use datafusion_common::{Result, ScalarValue};
26-
use datafusion_expr::window_doc_sections::DOC_SECTION_RANKING;
2726
use datafusion_expr::{
2827
Documentation, PartitionEvaluator, Signature, Volatility, WindowUDFImpl,
2928
};
3029
use datafusion_functions_window_common::field;
3130
use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
31+
use datafusion_macros::user_doc;
3232
use field::WindowUDFFieldArgs;
3333
use std::any::Any;
3434
use std::fmt::Debug;
3535
use std::ops::Range;
36-
use std::sync::OnceLock;
3736

3837
define_udwf_and_expr!(
3938
RowNumber,
@@ -42,6 +41,11 @@ define_udwf_and_expr!(
4241
);
4342

4443
/// row_number expression
44+
#[user_doc(
45+
doc_section(label = "Ranking Functions"),
46+
description = "Number of the current row within its partition, counting from 1.",
47+
syntax_example = "row_number()"
48+
)]
4549
#[derive(Debug)]
4650
pub struct RowNumber {
4751
signature: Signature,
@@ -62,19 +66,6 @@ impl Default for RowNumber {
6266
}
6367
}
6468

65-
static DOCUMENTATION: OnceLock<Documentation> = OnceLock::new();
66-
67-
fn get_row_number_doc() -> &'static Documentation {
68-
DOCUMENTATION.get_or_init(|| {
69-
Documentation::builder(
70-
DOC_SECTION_RANKING,
71-
"Number of the current row within its partition, counting from 1.",
72-
"row_number()",
73-
)
74-
.build()
75-
})
76-
}
77-
7869
impl WindowUDFImpl for RowNumber {
7970
fn as_any(&self) -> &dyn Any {
8071
self
@@ -107,7 +98,7 @@ impl WindowUDFImpl for RowNumber {
10798
}
10899

109100
fn documentation(&self) -> Option<&Documentation> {
110-
Some(get_row_number_doc())
101+
self.doc()
111102
}
112103
}
113104

0 commit comments

Comments
 (0)