Skip to content

Commit

Permalink
Issue-New - Add array_empty and list_empty functions support as alias…
Browse files Browse the repository at this point in the history
… for empty function (#9807)
  • Loading branch information
erenavsarogullari committed Mar 26, 2024
1 parent 39f4aaf commit e337832
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 7 deletions.
6 changes: 5 additions & 1 deletion datafusion/functions-array/src/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ impl ArrayEmpty {
pub fn new() -> Self {
Self {
signature: Signature::array(Volatility::Immutable),
aliases: vec![String::from("empty")],
aliases: vec![
"empty".to_string(),
"array_empty".to_string(),
"list_empty".to_string(),
],
}
}
}
Expand Down
71 changes: 70 additions & 1 deletion datafusion/sqllogictest/test_files/array.slt
Original file line number Diff line number Diff line change
Expand Up @@ -6116,7 +6116,7 @@ from fixed_size_flatten_table;
[1, 2, 3] [1, 2, 3, 4, 5, 6] [1, 2, 3] [1.0, 2.1, 2.2, 3.2, 3.3, 3.4]
[1, 2, 3, 4, 5, 6] [8, 9, 10, 11, 12, 13] [1, 2, 3] [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]

## empty
## empty (aliases: `array_empty`, `list_empty`)
# empty scalar function #1
query B
select empty(make_array(1));
Expand Down Expand Up @@ -6207,6 +6207,75 @@ NULL
false
false

## array_empty (aliases: `empty`, `list_empty`)
# array_empty scalar function #1
query B
select array_empty(make_array(1));
----
false

query B
select array_empty(arrow_cast(make_array(1), 'LargeList(Int64)'));
----
false

# array_empty scalar function #2
query B
select array_empty(make_array());
----
true

query B
select array_empty(arrow_cast(make_array(), 'LargeList(Null)'));
----
true

# array_empty scalar function #3
query B
select array_empty(make_array(NULL));
----
false

query B
select array_empty(arrow_cast(make_array(NULL), 'LargeList(Null)'));
----
false

## list_empty (aliases: `empty`, `array_empty`)
# list_empty scalar function #1
query B
select list_empty(make_array(1));
----
false

query B
select list_empty(arrow_cast(make_array(1), 'LargeList(Int64)'));
----
false

# list_empty scalar function #2
query B
select list_empty(make_array());
----
true

query B
select list_empty(arrow_cast(make_array(), 'LargeList(Null)'));
----
true

# list_empty scalar function #3
query B
select list_empty(make_array(NULL));
----
false

query B
select list_empty(arrow_cast(make_array(NULL), 'LargeList(Null)'));
----
false

# string_to_array scalar function
query ?
SELECT string_to_array('abcxxxdef', 'xxx')
----
Expand Down
1 change: 1 addition & 0 deletions docs/source/user-guide/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ select log(-1), log(0), sqrt(-1);
| array_dims(array) | Returns an array of the array's dimensions. `array_dims([[1, 2, 3], [4, 5, 6]]) -> [2, 3]` |
| array_distinct(array) | Returns distinct values from the array after removing duplicates. `array_distinct([1, 3, 2, 3, 1, 2, 4]) -> [1, 2, 3, 4]` |
| array_element(array, index) | Extracts the element with the index n from the array `array_element([1, 2, 3, 4], 3) -> 3` |
| empty(array) | Returns true for an empty array or false for a non-empty array. `empty([1]) -> false` |
| flatten(array) | Converts an array of arrays to a flat array `flatten([[1], [2, 3], [4, 5, 6]]) -> [1, 2, 3, 4, 5, 6]` |
| array_length(array, dimension) | Returns the length of the array dimension. `array_length([1, 2, 3, 4, 5]) -> 5` |
| array_ndims(array) | Returns the number of dimensions of the array. `array_ndims([[1, 2, 3], [4, 5, 6]]) -> 2` |
Expand Down
24 changes: 19 additions & 5 deletions docs/source/user-guide/sql/scalar_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,7 @@ from_unixtime(expression)
- [array_has_all](#array_has_all)
- [array_has_any](#array_has_any)
- [array_element](#array_element)
- [array_empty](#array_empty)
- [array_except](#array_except)
- [array_extract](#array_extract)
- [array_fill](#array_fill)
Expand Down Expand Up @@ -3009,6 +3010,11 @@ empty(array)
+------------------+
```

#### Aliases

- array_empty,
- list_empty

### `generate_series`

Similar to the range function, but it includes the upper bound.
Expand Down Expand Up @@ -3038,10 +3044,6 @@ generate_series(start, stop, step)

_Alias of [array_append](#array_append)._

### `list_sort`

_Alias of [array_sort](#array_sort)._

### `list_cat`

_Alias of [array_concat](#array_concat)._
Expand All @@ -3062,6 +3064,10 @@ _Alias of [array_dims](#array_distinct)._

_Alias of [array_element](#array_element)._

### `list_empty`

_Alias of [empty](#empty)._

### `list_except`

_Alias of [array_element](#array_except)._
Expand Down Expand Up @@ -3170,13 +3176,17 @@ _Alias of [array_reverse](#array_reverse)._

_Alias of [array_slice](#array_slice)._

### `list_sort`

_Alias of [array_sort](#array_sort)._

### `list_to_string`

_Alias of [array_to_string](#array_to_string)._

### `list_union`

_Alias of [array_to_string](#array_union)._
_Alias of [array_union](#array_union)._

### `make_array`

Expand All @@ -3186,6 +3196,10 @@ Returns an Arrow array using the specified input expressions.
make_array(expression1[, ..., expression_n])
```

### `array_empty`

_Alias of [empty](#empty)._

#### Arguments

- **expression_n**: Expression to include in the output array.
Expand Down

0 comments on commit e337832

Please sign in to comment.