Skip to content

Commit

Permalink
fix: import doc and macro, fix typo and update function docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheng-Yuan-Lai committed Dec 29, 2024
1 parent 31ed23b commit 6d98bb9
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 65 deletions.
2 changes: 2 additions & 0 deletions datafusion-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions datafusion/functions-nested/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ arrow-buffer = { workspace = true }
arrow-ord = { workspace = true }
arrow-schema = { workspace = true }
datafusion-common = { workspace = true }
datafusion-doc = { workspace = true }
datafusion-execution = { workspace = true }
datafusion-expr = { workspace = true }
datafusion-functions = { workspace = true }
datafusion-functions-aggregate = { workspace = true }
datafusion-macros = { workspace = true }
datafusion-physical-expr-common = { workspace = true }
itertools = { workspace = true, features = ["use_std"] }
log = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions datafusion/functions-nested/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ make_udf_expr_and_func!(
```"#,
argument(
name = "start",
description = "Start of the range. Ints, timestamps, dates or string types that can be coerced to Date32 are supported."
description = "Start of the series. Ints, timestamps, dates or string types that can be coerced to Date32 are supported."
),
argument(
name = "end",
description = "End of the range (not included). Type must be the same as start."
description = "End of the series (included). Type must be the same as start."
),
argument(
name = "step",
description = "Increase by step (cannot be 0). Steps less than a day are supported only for timestamp ranges."
description = "Increase by step (can not be 0). Steps less than a day are supported only for timestamp ranges."
)
)]
#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions datafusion/functions-nested/src/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ make_udf_expr_and_func!(

#[user_doc(
doc_section(label = "Array Functions"),
description = "Removes the first `max` elements from the array equal to the given value.",
description = "Removes all elements from the array equal to the given value.",
syntax_example = "array_remove_all(array, element)",
sql_example = r#"```sql
> select array_remove_all([1, 2, 2, 3, 2, 1, 4], 2);
Expand All @@ -213,7 +213,7 @@ make_udf_expr_and_func!(
```"#,
argument(
name = "array",
description = "Removes all elements from the array equal to the given value."
description = "Array expression. Can be a constant, column, or function, and any combination of array operators."
),
argument(
name = "element",
Expand Down
4 changes: 2 additions & 2 deletions datafusion/functions-nested/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ make_udf_expr_and_func!(
),
argument(
name = "desc",
description = "Whether to sort in descending order(`ASC` or `DESC"
description = "Whether to sort in descending order(`ASC` or `DESC`)."
),
argument(
name = "null_first",
name = "nulls_first",
description = "Whether to sort nulls first(`NULLS FIRST` or `NULLS LAST`)."
)
)]
Expand Down
6 changes: 3 additions & 3 deletions datafusion/functions-nested/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ make_udf_expr_and_func!(
| ['abc', NULL] |
+---------------------------------------------+
```"#,
argument(name = "string", description = "String expression to split."),
argument(name = "delimiter", description = "Array element separator."),
argument(name = "str", description = "String expression to split."),
argument(name = "delimiter", description = "Delimiter string to split on."),
argument(
name = "null_string",
name = "null_str",
description = "Substring values to be replaced with `NULL`."
)
)]
Expand Down
123 changes: 68 additions & 55 deletions docs/source/user-guide/sql/scalar_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2939,25 +2939,32 @@ _Alias of [array_position](#array_position)._

### `array_intersect`

Returns distinct values from the array after removing duplicates.
Returns an array of elements in the intersection of array1 and array2.

```
array_distinct(array)
array_intersect(array1, array2)
```

#### Arguments

- **array**: Array expression. Can be a constant, column, or function, and any combination of array operators.
- **array1**: Array expression. Can be a constant, column, or function, and any combination of array operators.
- **array2**: Array expression. Can be a constant, column, or function, and any combination of array operators.

#### Example

```sql
> select array_distinct([1, 3, 2, 3, 1, 2, 4]);
+---------------------------------+
| array_distinct(List([1,2,3,4])) |
+---------------------------------+
| [1, 2, 3, 4] |
+---------------------------------+
> select array_intersect([1, 2, 3, 4], [5, 6, 3, 4]);
+----------------------------------------------------+
| array_intersect([1, 2, 3, 4], [5, 6, 3, 4]); |
+----------------------------------------------------+
| [3, 4] |
+----------------------------------------------------+
> select array_intersect([1, 2, 3, 4], [5, 6, 7, 8]);
+----------------------------------------------------+
| array_intersect([1, 2, 3, 4], [5, 6, 7, 8]); |
+----------------------------------------------------+
| [] |
+----------------------------------------------------+
```

#### Aliases
Expand Down Expand Up @@ -3221,10 +3228,10 @@ array_remove(array, element)

### `array_remove_all`

Removes the first element from the array equal to the given value.
Removes all elements from the array equal to the given value.

```
array_remove(array, element)
array_remove_all(array, element)
```

#### Arguments
Expand All @@ -3235,12 +3242,12 @@ array_remove(array, element)
#### Example

```sql
> select array_remove([1, 2, 2, 3, 2, 1, 4], 2);
+----------------------------------------------+
| array_remove(List([1,2,2,3,2,1,4]),Int64(2)) |
+----------------------------------------------+
| [1, 2, 3, 2, 1, 4] |
+----------------------------------------------+
> select array_remove_all([1, 2, 2, 3, 2, 1, 4], 2);
+--------------------------------------------------+
| array_remove_all(List([1,2,2,3,2,1,4]),Int64(2)) |
+--------------------------------------------------+
| [1, 3, 1, 4] |
+--------------------------------------------------+
```

#### Aliases
Expand All @@ -3249,26 +3256,27 @@ array_remove(array, element)

### `array_remove_n`

Removes the first element from the array equal to the given value.
Removes the first `max` elements from the array equal to the given value.

```
array_remove(array, element)
array_remove_n(array, element, max))
```

#### Arguments

- **array**: Array expression. Can be a constant, column, or function, and any combination of array operators.
- **element**: Element to be removed from the array.
- **max**: Number of first occurrences to remove.

#### Example

```sql
> select array_remove([1, 2, 2, 3, 2, 1, 4], 2);
+----------------------------------------------+
| array_remove(List([1,2,2,3,2,1,4]),Int64(2)) |
+----------------------------------------------+
| [1, 2, 3, 2, 1, 4] |
+----------------------------------------------+
> select array_remove_n([1, 2, 2, 3, 2, 1, 4], 2, 2);
+---------------------------------------------------------+
| array_remove_n(List([1,2,2,3,2,1,4]),Int64(2),Int64(2)) |
+---------------------------------------------------------+
| [1, 3, 2, 1, 4] |
+---------------------------------------------------------+
```

#### Aliases
Expand Down Expand Up @@ -3311,28 +3319,27 @@ array_repeat(element, count)

### `array_replace`

Replaces the first `max` occurrences of the specified element with another specified element.
Replaces the first occurrence of the specified element with another specified element.

```
array_replace_n(array, from, to, max)
array_replace(array, from, to)
```

#### Arguments

- **array**: Array expression. Can be a constant, column, or function, and any combination of array operators.
- **from**: Initial element.
- **to**: Final element.
- **max**: Number of first occurrences to replace.

#### Example

```sql
> select array_replace_n([1, 2, 2, 3, 2, 1, 4], 2, 5, 2);
+-------------------------------------------------------------------+
| array_replace_n(List([1,2,2,3,2,1,4]),Int64(2),Int64(5),Int64(2)) |
+-------------------------------------------------------------------+
| [1, 5, 5, 3, 2, 1, 4] |
+-------------------------------------------------------------------+
> select array_replace([1, 2, 2, 3, 2, 1, 4], 2, 5);
+--------------------------------------------------------+
| array_replace(List([1,2,2,3,2,1,4]),Int64(2),Int64(5)) |
+--------------------------------------------------------+
| [1, 5, 2, 3, 2, 1, 4] |
+--------------------------------------------------------+
```

#### Aliases
Expand All @@ -3341,28 +3348,27 @@ array_replace_n(array, from, to, max)

### `array_replace_all`

Replaces the first `max` occurrences of the specified element with another specified element.
Replaces all occurrences of the specified element with another specified element.

```
array_replace_n(array, from, to, max)
array_replace_all(array, from, to)
```

#### Arguments

- **array**: Array expression. Can be a constant, column, or function, and any combination of array operators.
- **from**: Initial element.
- **to**: Final element.
- **max**: Number of first occurrences to replace.

#### Example

```sql
> select array_replace_n([1, 2, 2, 3, 2, 1, 4], 2, 5, 2);
+-------------------------------------------------------------------+
| array_replace_n(List([1,2,2,3,2,1,4]),Int64(2),Int64(5),Int64(2)) |
+-------------------------------------------------------------------+
| [1, 5, 5, 3, 2, 1, 4] |
+-------------------------------------------------------------------+
> select array_replace_all([1, 2, 2, 3, 2, 1, 4], 2, 5);
+------------------------------------------------------------+
| array_replace_all(List([1,2,2,3,2,1,4]),Int64(2),Int64(5)) |
+------------------------------------------------------------+
| [1, 5, 5, 3, 5, 1, 4] |
+------------------------------------------------------------+
```

#### Aliases
Expand Down Expand Up @@ -3545,25 +3551,32 @@ array_to_string(array, delimiter[, null_string])

### `array_union`

Returns distinct values from the array after removing duplicates.
Returns an array of elements that are present in both arrays (all elements from both arrays) with out duplicates.

```
array_distinct(array)
array_union(array1, array2)
```

#### Arguments

- **array**: Array expression. Can be a constant, column, or function, and any combination of array operators.
- **array1**: Array expression. Can be a constant, column, or function, and any combination of array operators.
- **array2**: Array expression. Can be a constant, column, or function, and any combination of array operators.

#### Example

```sql
> select array_distinct([1, 3, 2, 3, 1, 2, 4]);
+---------------------------------+
| array_distinct(List([1,2,3,4])) |
+---------------------------------+
| [1, 2, 3, 4] |
+---------------------------------+
> select array_union([1, 2, 3, 4], [5, 6, 3, 4]);
+----------------------------------------------------+
| array_union([1, 2, 3, 4], [5, 6, 3, 4]); |
+----------------------------------------------------+
| [1, 2, 3, 4, 5, 6] |
+----------------------------------------------------+
> select array_union([1, 2, 3, 4], [5, 6, 7, 8]);
+----------------------------------------------------+
| array_union([1, 2, 3, 4], [5, 6, 7, 8]); |
+----------------------------------------------------+
| [1, 2, 3, 4, 5, 6, 7, 8] |
+----------------------------------------------------+
```

#### Aliases
Expand Down Expand Up @@ -3659,9 +3672,9 @@ generate_series(start, stop, step)

#### Arguments

- **start**: start of the series. Ints, timestamps, dates or string types that can be coerced to Date32 are supported.
- **end**: end of the series (included). Type must be the same as start.
- **step**: increase by step (can not be 0). Steps less than a day are supported only for timestamp ranges.
- **start**: Start of the series. Ints, timestamps, dates or string types that can be coerced to Date32 are supported.
- **end**: End of the series (included). Type must be the same as start.
- **step**: Increase by step (can not be 0). Steps less than a day are supported only for timestamp ranges.

#### Example

Expand Down

0 comments on commit 6d98bb9

Please sign in to comment.