Skip to content

Commit d220bf4

Browse files
authored
support LargeList in array_positions (#8571)
1 parent 1935c58 commit d220bf4

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

datafusion/physical-expr/src/array_expressions.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,12 +1289,23 @@ fn general_position<OffsetSize: OffsetSizeTrait>(
12891289

12901290
/// Array_positions SQL function
12911291
pub fn array_positions(args: &[ArrayRef]) -> Result<ArrayRef> {
1292-
let arr = as_list_array(&args[0])?;
12931292
let element = &args[1];
12941293

1295-
check_datatypes("array_positions", &[arr.values(), element])?;
1296-
1297-
general_positions::<i32>(arr, element)
1294+
match &args[0].data_type() {
1295+
DataType::List(_) => {
1296+
let arr = as_list_array(&args[0])?;
1297+
check_datatypes("array_positions", &[arr.values(), element])?;
1298+
general_positions::<i32>(arr, element)
1299+
}
1300+
DataType::LargeList(_) => {
1301+
let arr = as_large_list_array(&args[0])?;
1302+
check_datatypes("array_positions", &[arr.values(), element])?;
1303+
general_positions::<i64>(arr, element)
1304+
}
1305+
array_type => {
1306+
not_impl_err!("array_positions does not support type '{array_type:?}'.")
1307+
}
1308+
}
12981309
}
12991310

13001311
fn general_positions<OffsetSize: OffsetSizeTrait>(

datafusion/sqllogictest/test_files/array.slt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,18 +1832,33 @@ select array_positions(['h', 'e', 'l', 'l', 'o'], 'l'), array_positions([1, 2, 3
18321832
----
18331833
[3, 4] [5] [1, 2, 3]
18341834

1835+
query ???
1836+
select array_positions(arrow_cast(['h', 'e', 'l', 'l', 'o'], 'LargeList(Utf8)'), 'l'), array_positions(arrow_cast([1, 2, 3, 4, 5], 'LargeList(Int64)'), 5), array_positions(arrow_cast([1, 1, 1], 'LargeList(Int64)'), 1);
1837+
----
1838+
[3, 4] [5] [1, 2, 3]
1839+
18351840
# array_positions scalar function #2 (element is list)
18361841
query ?
18371842
select array_positions(make_array([1, 2, 3], [2, 1, 3], [1, 5, 6], [2, 1, 3], [4, 5, 6]), [2, 1, 3]);
18381843
----
18391844
[2, 4]
18401845

1846+
query ?
1847+
select array_positions(arrow_cast(make_array([1, 2, 3], [2, 1, 3], [1, 5, 6], [2, 1, 3], [4, 5, 6]), 'LargeList(List(Int64))'), [2, 1, 3]);
1848+
----
1849+
[2, 4]
1850+
18411851
# list_positions scalar function #3 (function alias `array_positions`)
18421852
query ???
18431853
select list_positions(['h', 'e', 'l', 'l', 'o'], 'l'), list_positions([1, 2, 3, 4, 5], 5), list_positions([1, 1, 1], 1);
18441854
----
18451855
[3, 4] [5] [1, 2, 3]
18461856

1857+
query ???
1858+
select list_positions(arrow_cast(['h', 'e', 'l', 'l', 'o'], 'LargeList(Utf8)'), 'l'), list_positions(arrow_cast([1, 2, 3, 4, 5], 'LargeList(Int64)'), 5), list_positions(arrow_cast([1, 1, 1], 'LargeList(Int64)'), 1);
1859+
----
1860+
[3, 4] [5] [1, 2, 3]
1861+
18471862
# array_positions with columns #1
18481863
query ?
18491864
select array_positions(column1, column2) from arrays_values_without_nulls;
@@ -1853,13 +1868,27 @@ select array_positions(column1, column2) from arrays_values_without_nulls;
18531868
[3]
18541869
[4]
18551870

1871+
query ?
1872+
select array_positions(arrow_cast(column1, 'LargeList(Int64)'), column2) from arrays_values_without_nulls;
1873+
----
1874+
[1]
1875+
[2]
1876+
[3]
1877+
[4]
1878+
18561879
# array_positions with columns #2 (element is list)
18571880
query ?
18581881
select array_positions(column1, column2) from nested_arrays;
18591882
----
18601883
[3]
18611884
[2, 5]
18621885

1886+
query ?
1887+
select array_positions(arrow_cast(column1, 'LargeList(List(Int64))'), column2) from nested_arrays;
1888+
----
1889+
[3]
1890+
[2, 5]
1891+
18631892
# array_positions with columns and scalars #1
18641893
query ??
18651894
select array_positions(column1, 4), array_positions(array[1, 2, 23, 13, 33, 45], column2) from arrays_values_without_nulls;
@@ -1869,13 +1898,27 @@ select array_positions(column1, 4), array_positions(array[1, 2, 23, 13, 33, 45],
18691898
[] [3]
18701899
[] []
18711900

1901+
query ??
1902+
select array_positions(arrow_cast(column1, 'LargeList(Int64)'), 4), array_positions(array[1, 2, 23, 13, 33, 45], column2) from arrays_values_without_nulls;
1903+
----
1904+
[4] [1]
1905+
[] []
1906+
[] [3]
1907+
[] []
1908+
18721909
# array_positions with columns and scalars #2 (element is list)
18731910
query ??
18741911
select array_positions(column1, make_array(4, 5, 6)), array_positions(make_array([1, 2, 3], [11, 12, 13], [4, 5, 6]), column2) from nested_arrays;
18751912
----
18761913
[6] []
18771914
[1] []
18781915

1916+
query ??
1917+
select array_positions(arrow_cast(column1, 'LargeList(List(Int64))'), make_array(4, 5, 6)), array_positions(arrow_cast(make_array([1, 2, 3], [11, 12, 13], [4, 5, 6]), 'LargeList(List(Int64))'), column2) from nested_arrays;
1918+
----
1919+
[6] []
1920+
[1] []
1921+
18791922
## array_replace (aliases: `list_replace`)
18801923

18811924
# array_replace scalar function #1

0 commit comments

Comments
 (0)