Skip to content

Commit

Permalink
fix docs (#13397)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanc-n authored Nov 14, 2024
1 parent ccf6258 commit 2d86725
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
14 changes: 10 additions & 4 deletions datafusion/functions-nested/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ impl ScalarUDFImpl for ArrayToString {
}
}

static DOCUMENTATION: OnceLock<Documentation> = OnceLock::new();
static DOCUMENTATION_ARRAY_TO_STRING: OnceLock<Documentation> = 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]], ',');
Expand All @@ -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()
})
Expand Down Expand Up @@ -274,8 +278,10 @@ impl ScalarUDFImpl for StringToArray {
}
}

static DOCUMENTATION_STRING_TO_ARRAY: OnceLock<Documentation> = 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(
Expand Down
30 changes: 19 additions & 11 deletions docs/source/user-guide/sql/scalar_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3469,13 +3469,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

Expand Down Expand Up @@ -3850,26 +3851,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
Expand Down

0 comments on commit 2d86725

Please sign in to comment.