@@ -25,17 +25,17 @@ use arrow_buffer::BooleanBuffer;
2525use datafusion_common:: cast:: as_generic_list_array;
2626use datafusion_common:: utils:: string_utils:: string_array_to_vec;
2727use datafusion_common:: { exec_err, Result , ScalarValue } ;
28- use datafusion_expr:: scalar_doc_sections:: DOC_SECTION_ARRAY ;
2928use datafusion_expr:: {
3029 ColumnarValue , Documentation , ScalarUDFImpl , Signature , Volatility ,
3130} ;
31+ use datafusion_macros:: user_doc;
3232use datafusion_physical_expr_common:: datum:: compare_with_eq;
3333use itertools:: Itertools ;
3434
3535use crate :: utils:: make_scalar_function;
3636
3737use std:: any:: Any ;
38- use std:: sync:: { Arc , OnceLock } ;
38+ use std:: sync:: Arc ;
3939
4040// Create static instances of ScalarUDFs for each function
4141make_udf_expr_and_func ! ( ArrayHas ,
@@ -57,6 +57,27 @@ make_udf_expr_and_func!(ArrayHasAny,
5757 array_has_any_udf // internal function name
5858) ;
5959
60+ #[ user_doc(
61+ doc_section( label = "Array Functions" ) ,
62+ description = "Returns true if the array contains the element." ,
63+ syntax_example = "array_has(array, element)" ,
64+ sql_example = r#"```sql
65+ > select array_has([1, 2, 3], 2);
66+ +-----------------------------+
67+ | array_has(List([1,2,3]), 2) |
68+ +-----------------------------+
69+ | true |
70+ +-----------------------------+
71+ ```"# ,
72+ argument(
73+ name = "array" ,
74+ description = "Array expression. Can be a constant, column, or function, and any combination of array operators."
75+ ) ,
76+ argument(
77+ name = "element" ,
78+ description = "Scalar or Array expression. Can be a constant, column, or function, and any combination of array operators."
79+ )
80+ ) ]
6081#[ derive( Debug ) ]
6182pub struct ArrayHas {
6283 signature : Signature ,
@@ -138,41 +159,10 @@ impl ScalarUDFImpl for ArrayHas {
138159 }
139160
140161 fn documentation ( & self ) -> Option < & Documentation > {
141- Some ( get_array_has_doc ( ) )
162+ self . doc ( )
142163 }
143164}
144165
145- static DOCUMENTATION : OnceLock < Documentation > = OnceLock :: new ( ) ;
146-
147- fn get_array_has_doc ( ) -> & ' static Documentation {
148- DOCUMENTATION . get_or_init ( || {
149- Documentation :: builder (
150- DOC_SECTION_ARRAY ,
151- "Returns true if the array contains the element." ,
152-
153- "array_has(array, element)" )
154- . with_sql_example (
155- r#"```sql
156- > select array_has([1, 2, 3], 2);
157- +-----------------------------+
158- | array_has(List([1,2,3]), 2) |
159- +-----------------------------+
160- | true |
161- +-----------------------------+
162- ```"# ,
163- )
164- . with_argument (
165- "array" ,
166- "Array expression. Can be a constant, column, or function, and any combination of array operators." ,
167- )
168- . with_argument (
169- "element" ,
170- "Scalar or Array expression. Can be a constant, column, or function, and any combination of array operators." ,
171- )
172- . build ( )
173- } )
174- }
175-
176166fn array_has_inner_for_scalar (
177167 haystack : & ArrayRef ,
178168 needle : & dyn Datum ,
@@ -287,6 +277,27 @@ fn array_has_any_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
287277 }
288278}
289279
280+ #[ user_doc(
281+ doc_section( label = "Array Functions" ) ,
282+ description = "Returns true if all elements of sub-array exist in array." ,
283+ syntax_example = "array_has_all(array, sub-array)" ,
284+ sql_example = r#"```sql
285+ > select array_has_all([1, 2, 3, 4], [2, 3]);
286+ +--------------------------------------------+
287+ | array_has_all(List([1,2,3,4]), List([2,3])) |
288+ +--------------------------------------------+
289+ | true |
290+ +--------------------------------------------+
291+ ```"# ,
292+ argument(
293+ name = "array" ,
294+ description = "Array expression. Can be a constant, column, or function, and any combination of array operators."
295+ ) ,
296+ argument(
297+ name = "sub-array" ,
298+ description = "Array expression. Can be a constant, column, or function, and any combination of array operators."
299+ )
300+ ) ]
290301#[ derive( Debug ) ]
291302pub struct ArrayHasAll {
292303 signature : Signature ,
@@ -337,39 +348,31 @@ impl ScalarUDFImpl for ArrayHasAll {
337348 }
338349
339350 fn documentation ( & self ) -> Option < & Documentation > {
340- Some ( get_array_has_all_doc ( ) )
351+ self . doc ( )
341352 }
342353}
343354
344- fn get_array_has_all_doc ( ) -> & ' static Documentation {
345- DOCUMENTATION . get_or_init ( || {
346- Documentation :: builder (
347- DOC_SECTION_ARRAY ,
348- "Returns true if all elements of sub-array exist in array." ,
349-
350- "array_has_all(array, sub-array)" )
351- . with_sql_example (
352- r#"```sql
353- > select array_has_all([1, 2, 3, 4], [2, 3]);
354- +--------------------------------------------+
355- | array_has_all(List([1,2,3,4]), List([2,3])) |
356- +--------------------------------------------+
357- | true |
358- +--------------------------------------------+
355+ #[ user_doc(
356+ doc_section( label = "Array Functions" ) ,
357+ description = "Returns true if any elements exist in both arrays." ,
358+ syntax_example = "array_has_any(array, sub-array)" ,
359+ sql_example = r#"```sql
360+ > select array_has_any([1, 2, 3], [3, 4]);
361+ +------------------------------------------+
362+ | array_has_any(List([1,2,3]), List([3,4])) |
363+ +------------------------------------------+
364+ | true |
365+ +------------------------------------------+
359366```"# ,
360- )
361- . with_argument (
362- "array" ,
363- "Array expression. Can be a constant, column, or function, and any combination of array operators." ,
364- )
365- . with_argument (
366- "sub-array" ,
367- "Array expression. Can be a constant, column, or function, and any combination of array operators." ,
368- )
369- . build ( )
370- } )
371- }
372-
367+ argument(
368+ name = "array" ,
369+ description = "Array expression. Can be a constant, column, or function, and any combination of array operators."
370+ ) ,
371+ argument(
372+ name = "sub-array" ,
373+ description = "Array expression. Can be a constant, column, or function, and any combination of array operators."
374+ )
375+ ) ]
373376#[ derive( Debug ) ]
374377pub struct ArrayHasAny {
375378 signature : Signature ,
@@ -420,39 +423,10 @@ impl ScalarUDFImpl for ArrayHasAny {
420423 }
421424
422425 fn documentation ( & self ) -> Option < & Documentation > {
423- Some ( get_array_has_any_doc ( ) )
426+ self . doc ( )
424427 }
425428}
426429
427- fn get_array_has_any_doc ( ) -> & ' static Documentation {
428- DOCUMENTATION . get_or_init ( || {
429- Documentation :: builder (
430- DOC_SECTION_ARRAY ,
431- "Returns true if any elements exist in both arrays." ,
432-
433- "array_has_any(array, sub-array)" )
434- . with_sql_example (
435- r#"```sql
436- > select array_has_any([1, 2, 3], [3, 4]);
437- +------------------------------------------+
438- | array_has_any(List([1,2,3]), List([3,4])) |
439- +------------------------------------------+
440- | true |
441- +------------------------------------------+
442- ```"# ,
443- )
444- . with_argument (
445- "array" ,
446- "Array expression. Can be a constant, column, or function, and any combination of array operators." ,
447- )
448- . with_argument (
449- "sub-array" ,
450- "Array expression. Can be a constant, column, or function, and any combination of array operators." ,
451- )
452- . build ( )
453- } )
454- }
455-
456430/// Represents the type of comparison for array_has.
457431#[ derive( Debug , PartialEq , Clone , Copy ) ]
458432enum ComparisonType {
0 commit comments