@@ -37,16 +37,16 @@ use datafusion_common::cast::{
3737use datafusion_common:: {
3838 exec_datafusion_err, exec_err, internal_err, not_impl_datafusion_err, Result ,
3939} ;
40- use datafusion_expr:: scalar_doc_sections:: DOC_SECTION_ARRAY ;
4140use datafusion_expr:: {
4241 ColumnarValue , Documentation , ScalarUDFImpl , Signature , Volatility ,
4342} ;
43+ use datafusion_macros:: user_doc;
4444use itertools:: Itertools ;
4545use std:: any:: Any ;
4646use std:: cmp:: Ordering ;
4747use std:: iter:: from_fn;
4848use std:: str:: FromStr ;
49- use std:: sync:: { Arc , OnceLock } ;
49+ use std:: sync:: Arc ;
5050
5151make_udf_expr_and_func ! (
5252 Range ,
@@ -55,6 +55,39 @@ make_udf_expr_and_func!(
5555 "create a list of values in the range between start and stop" ,
5656 range_udf
5757) ;
58+
59+ #[ user_doc(
60+ doc_section( label = "Array Functions" ) ,
61+ description = "Returns an Arrow array between start and stop with step. The range start..end contains all values with start <= x < end. It is empty if start >= end. Step cannot be 0." ,
62+ syntax_example = "range(start, stop, step)" ,
63+ sql_example = r#"```sql
64+ > select range(2, 10, 3);
65+ +-----------------------------------+
66+ | range(Int64(2),Int64(10),Int64(3))|
67+ +-----------------------------------+
68+ | [2, 5, 8] |
69+ +-----------------------------------+
70+
71+ > select range(DATE '1992-09-01', DATE '1993-03-01', INTERVAL '1' MONTH);
72+ +--------------------------------------------------------------+
73+ | range(DATE '1992-09-01', DATE '1993-03-01', INTERVAL '1' MONTH) |
74+ +--------------------------------------------------------------+
75+ | [1992-09-01, 1992-10-01, 1992-11-01, 1992-12-01, 1993-01-01, 1993-02-01] |
76+ +--------------------------------------------------------------+
77+ ```"# ,
78+ argument(
79+ name = "start" ,
80+ description = "Start of the range. Ints, timestamps, dates or string types that can be coerced to Date32 are supported."
81+ ) ,
82+ argument(
83+ name = "end" ,
84+ description = "End of the range (not included). Type must be the same as start."
85+ ) ,
86+ argument(
87+ name = "step" ,
88+ description = "Increase by step (cannot be 0). Steps less than a day are supported only for timestamp ranges."
89+ )
90+ ) ]
5891#[ derive( Debug ) ]
5992pub ( super ) struct Range {
6093 signature : Signature ,
@@ -141,59 +174,43 @@ impl ScalarUDFImpl for Range {
141174 }
142175
143176 fn documentation ( & self ) -> Option < & Documentation > {
144- Some ( get_range_doc ( ) )
177+ self . doc ( )
145178 }
146179}
147180
148- static DOCUMENTATION : OnceLock < Documentation > = OnceLock :: new ( ) ;
149-
150- fn get_range_doc ( ) -> & ' static Documentation {
151- DOCUMENTATION . get_or_init ( || {
152- Documentation :: builder (
153- DOC_SECTION_ARRAY ,
154- "Returns an Arrow array between start and stop with step. The range start..end contains all values with start <= x < end. It is empty if start >= end. Step cannot be 0." ,
155-
156- "range(start, stop, step)" )
157- . with_sql_example (
158- r#"```sql
159- > select range(2, 10, 3);
160- +-----------------------------------+
161- | range(Int64(2),Int64(10),Int64(3))|
162- +-----------------------------------+
163- | [2, 5, 8] |
164- +-----------------------------------+
165-
166- > select range(DATE '1992-09-01', DATE '1993-03-01', INTERVAL '1' MONTH);
167- +--------------------------------------------------------------+
168- | range(DATE '1992-09-01', DATE '1993-03-01', INTERVAL '1' MONTH) |
169- +--------------------------------------------------------------+
170- | [1992-09-01, 1992-10-01, 1992-11-01, 1992-12-01, 1993-01-01, 1993-02-01] |
171- +--------------------------------------------------------------+
172- ```"# ,
173- )
174- . with_argument (
175- "start" ,
176- "Start of the range. Ints, timestamps, dates or string types that can be coerced to Date32 are supported." ,
177- )
178- . with_argument (
179- "end" ,
180- "End of the range (not included). Type must be the same as start." ,
181- )
182- . with_argument (
183- "step" ,
184- "Increase by step (cannot be 0). Steps less than a day are supported only for timestamp ranges." ,
185- )
186- . build ( )
187- } )
188- }
189-
190181make_udf_expr_and_func ! (
191182 GenSeries ,
192183 gen_series,
193184 start stop step,
194185 "create a list of values in the range between start and stop, include upper bound" ,
195186 gen_series_udf
196187) ;
188+
189+ #[ user_doc(
190+ doc_section( label = "Array Functions" ) ,
191+ description = "Similar to the range function, but it includes the upper bound." ,
192+ syntax_example = "generate_series(start, stop, step)" ,
193+ sql_example = r#"```sql
194+ > select generate_series(1,3);
195+ +------------------------------------+
196+ | generate_series(Int64(1),Int64(3)) |
197+ +------------------------------------+
198+ | [1, 2, 3] |
199+ +------------------------------------+
200+ ```"# ,
201+ argument(
202+ name = "start" ,
203+ description = "Start of the series. Ints, timestamps, dates or string types that can be coerced to Date32 are supported."
204+ ) ,
205+ argument(
206+ name = "end" ,
207+ description = "End of the series (included). Type must be the same as start."
208+ ) ,
209+ argument(
210+ name = "step" ,
211+ description = "Increase by step (can not be 0). Steps less than a day are supported only for timestamp ranges."
212+ )
213+ ) ]
197214#[ derive( Debug ) ]
198215pub ( super ) struct GenSeries {
199216 signature : Signature ,
@@ -283,45 +300,10 @@ impl ScalarUDFImpl for GenSeries {
283300 }
284301
285302 fn documentation ( & self ) -> Option < & Documentation > {
286- Some ( get_generate_series_doc ( ) )
303+ self . doc ( )
287304 }
288305}
289306
290- static GENERATE_SERIES_DOCUMENTATION : OnceLock < Documentation > = OnceLock :: new ( ) ;
291-
292- fn get_generate_series_doc ( ) -> & ' static Documentation {
293- GENERATE_SERIES_DOCUMENTATION . get_or_init ( || {
294- Documentation :: builder (
295- DOC_SECTION_ARRAY ,
296- "Similar to the range function, but it includes the upper bound." ,
297-
298- "generate_series(start, stop, step)" )
299- . with_sql_example (
300- r#"```sql
301- > select generate_series(1,3);
302- +------------------------------------+
303- | generate_series(Int64(1),Int64(3)) |
304- +------------------------------------+
305- | [1, 2, 3] |
306- +------------------------------------+
307- ```"# ,
308- )
309- . with_argument (
310- "start" ,
311- "start of the series. Ints, timestamps, dates or string types that can be coerced to Date32 are supported." ,
312- )
313- . with_argument (
314- "end" ,
315- "end of the series (included). Type must be the same as start." ,
316- )
317- . with_argument (
318- "step" ,
319- "increase by step (can not be 0). Steps less than a day are supported only for timestamp ranges." ,
320- )
321- . build ( )
322- } )
323- }
324-
325307/// Generates an array of integers from start to stop with a given step.
326308///
327309/// This function takes 1 to 3 ArrayRefs as arguments, representing start, stop, and step values.
0 commit comments