@@ -25,12 +25,28 @@ use arrow::datatypes::DataType;
2525use datafusion_common:: cast:: as_int64_array;
2626use datafusion_common:: ScalarValue ;
2727use datafusion_common:: { exec_err, DataFusionError , Result } ;
28- use datafusion_expr:: scalar_doc_sections:: DOC_SECTION_STRING ;
2928use datafusion_expr:: { ColumnarValue , Documentation , TypeSignature , Volatility } ;
3029use datafusion_expr:: { ScalarUDFImpl , Signature } ;
30+ use datafusion_macros:: user_doc;
3131use std:: any:: Any ;
32- use std:: sync:: { Arc , OnceLock } ;
32+ use std:: sync:: Arc ;
3333
34+ #[ user_doc(
35+ doc_section( label = "String Functions" ) ,
36+ description = "Splits a string based on a specified delimiter and returns the substring in the specified position." ,
37+ syntax_example = "split_part(str, delimiter, pos)" ,
38+ sql_example = r#"```sql
39+ > select split_part('1.2.3.4.5', '.', 3);
40+ +--------------------------------------------------+
41+ | split_part(Utf8("1.2.3.4.5"),Utf8("."),Int64(3)) |
42+ +--------------------------------------------------+
43+ | 3 |
44+ +--------------------------------------------------+
45+ ```"# ,
46+ standard_argument( name = "str" , prefix = "String" ) ,
47+ argument( name = "delimiter" , description = "String or character to split on." ) ,
48+ argument( name = "pos" , description = "Position of the part to return." )
49+ ) ]
3450#[ derive( Debug ) ]
3551pub struct SplitPartFunc {
3652 signature : Signature ,
@@ -182,33 +198,10 @@ impl ScalarUDFImpl for SplitPartFunc {
182198 }
183199
184200 fn documentation ( & self ) -> Option < & Documentation > {
185- Some ( get_split_part_doc ( ) )
201+ self . doc ( )
186202 }
187203}
188204
189- static DOCUMENTATION : OnceLock < Documentation > = OnceLock :: new ( ) ;
190-
191- fn get_split_part_doc ( ) -> & ' static Documentation {
192- DOCUMENTATION . get_or_init ( || {
193- Documentation :: builder (
194- DOC_SECTION_STRING ,
195- "Splits a string based on a specified delimiter and returns the substring in the specified position." ,
196- "split_part(str, delimiter, pos)" )
197- . with_sql_example ( r#"```sql
198- > select split_part('1.2.3.4.5', '.', 3);
199- +--------------------------------------------------+
200- | split_part(Utf8("1.2.3.4.5"),Utf8("."),Int64(3)) |
201- +--------------------------------------------------+
202- | 3 |
203- +--------------------------------------------------+
204- ```"# )
205- . with_standard_argument ( "str" , Some ( "String" ) )
206- . with_argument ( "delimiter" , "String or character to split on." )
207- . with_argument ( "pos" , "Position of the part to return." )
208- . build ( )
209- } )
210- }
211-
212205/// impl
213206pub fn split_part_impl < ' a , StringArrType , DelimiterArrType , StringArrayLen > (
214207 string_array : StringArrType ,
0 commit comments