From 830736c0deaa9fae50da5321cc87e39c7f039406 Mon Sep 17 00:00:00 2001 From: Jonathan Chen Date: Wed, 13 Nov 2024 12:36:40 -0500 Subject: [PATCH] fix docs --- datafusion/functions-nested/src/string.rs | 14 ++++++--- .../source/user-guide/sql/scalar_functions.md | 30 ++++++++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/datafusion/functions-nested/src/string.rs b/datafusion/functions-nested/src/string.rs index 30f3845215fc..ce555c36274e 100644 --- a/datafusion/functions-nested/src/string.rs +++ b/datafusion/functions-nested/src/string.rs @@ -168,16 +168,16 @@ impl ScalarUDFImpl for ArrayToString { } } -static DOCUMENTATION: OnceLock = OnceLock::new(); +static DOCUMENTATION_ARRAY_TO_STRING: OnceLock = OnceLock::new(); fn get_array_to_string_doc() -> &'static Documentation { - DOCUMENTATION.get_or_init(|| { + DOCUMENTATION_ARRAY_TO_STRING.get_or_init(|| { Documentation::builder() .with_doc_section(DOC_SECTION_ARRAY) .with_description( "Converts each element to its text representation.", ) - .with_syntax_example("array_to_string(array, delimiter)") + .with_syntax_example("array_to_string(array, delimiter[, null_string])") .with_sql_example( r#"```sql > select array_to_string([[1, 2, 3, 4], [5, 6, 7, 8]], ','); @@ -196,6 +196,10 @@ fn get_array_to_string_doc() -> &'static Documentation { "delimiter", "Array element separator.", ) + .with_argument( + "null_string", + "Optional. String to replace null values in the array. If not provided, nulls will be handled by default behavior.", + ) .build() .unwrap() }) @@ -274,8 +278,10 @@ impl ScalarUDFImpl for StringToArray { } } +static DOCUMENTATION_STRING_TO_ARRAY: OnceLock = OnceLock::new(); + fn get_string_to_array_doc() -> &'static Documentation { - DOCUMENTATION.get_or_init(|| { + DOCUMENTATION_STRING_TO_ARRAY.get_or_init(|| { Documentation::builder() .with_doc_section(DOC_SECTION_ARRAY) .with_description( diff --git a/docs/source/user-guide/sql/scalar_functions.md b/docs/source/user-guide/sql/scalar_functions.md index e9cd2bba7d11..3cf103b6f789 100644 --- a/docs/source/user-guide/sql/scalar_functions.md +++ b/docs/source/user-guide/sql/scalar_functions.md @@ -3443,13 +3443,14 @@ array_sort(array, desc, nulls_first) Converts each element to its text representation. ``` -array_to_string(array, delimiter) +array_to_string(array, delimiter[, null_string]) ``` #### Arguments - **array**: Array expression. Can be a constant, column, or function, and any combination of array operators. - **delimiter**: Array element separator. +- **null_string**: Optional. String to replace null values in the array. If not provided, nulls will be handled by default behavior. #### Example @@ -3824,26 +3825,33 @@ range(start, stop, step) ### `string_to_array` -Converts each element to its text representation. +Splits a string into an array of substrings based on a delimiter. Any substrings matching the optional `null_str` argument are replaced with NULL. ``` -array_to_string(array, delimiter) +string_to_array(str, delimiter[, null_str]) ``` #### Arguments -- **array**: Array expression. Can be a constant, column, or function, and any combination of array operators. -- **delimiter**: Array element separator. +- **str**: String expression to split. +- **delimiter**: Delimiter string to split on. +- **null_str**: Substring values to be replaced with `NULL`. #### Example ```sql -> select array_to_string([[1, 2, 3, 4], [5, 6, 7, 8]], ','); -+----------------------------------------------------+ -| array_to_string(List([1,2,3,4,5,6,7,8]),Utf8(",")) | -+----------------------------------------------------+ -| 1,2,3,4,5,6,7,8 | -+----------------------------------------------------+ +> select string_to_array('abc##def', '##'); ++-----------------------------------+ +| string_to_array(Utf8('abc##def')) | ++-----------------------------------+ +| ['abc', 'def'] | ++-----------------------------------+ +> select string_to_array('abc def', ' ', 'def'); ++---------------------------------------------+ +| string_to_array(Utf8('abc def'), Utf8(' '), Utf8('def')) | ++---------------------------------------------+ +| ['abc', NULL] | ++---------------------------------------------+ ``` #### Aliases