Skip to content

Commit ba50f52

Browse files
authored
Support FixedSizeList for array_slice via coercion to List (#17667)
1 parent 68bc0ce commit ba50f52

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

datafusion/functions-nested/src/extract.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl ArraySlice {
337337
ArrayFunctionArgument::Index,
338338
ArrayFunctionArgument::Index,
339339
],
340-
array_coercion: None,
340+
array_coercion: Some(ListCoercion::FixedSizedListToList),
341341
}),
342342
TypeSignature::ArraySignature(ArrayFunctionSignature::Array {
343343
arguments: vec![
@@ -346,7 +346,7 @@ impl ArraySlice {
346346
ArrayFunctionArgument::Index,
347347
ArrayFunctionArgument::Index,
348348
],
349-
array_coercion: None,
349+
array_coercion: Some(ListCoercion::FixedSizedListToList),
350350
}),
351351
],
352352
Volatility::Immutable,
@@ -672,15 +672,7 @@ pub(super) struct ArrayPopFront {
672672
impl ArrayPopFront {
673673
pub fn new() -> Self {
674674
Self {
675-
signature: Signature {
676-
type_signature: TypeSignature::ArraySignature(
677-
ArrayFunctionSignature::Array {
678-
arguments: vec![ArrayFunctionArgument::Array],
679-
array_coercion: Some(ListCoercion::FixedSizedListToList),
680-
},
681-
),
682-
volatility: Volatility::Immutable,
683-
},
675+
signature: Signature::array(Volatility::Immutable),
684676
aliases: vec![String::from("list_pop_front")],
685677
}
686678
}
@@ -776,15 +768,7 @@ pub(super) struct ArrayPopBack {
776768
impl ArrayPopBack {
777769
pub fn new() -> Self {
778770
Self {
779-
signature: Signature {
780-
type_signature: TypeSignature::ArraySignature(
781-
ArrayFunctionSignature::Array {
782-
arguments: vec![ArrayFunctionArgument::Array],
783-
array_coercion: Some(ListCoercion::FixedSizedListToList),
784-
},
785-
),
786-
volatility: Volatility::Immutable,
787-
},
771+
signature: Signature::array(Volatility::Immutable),
788772
aliases: vec![String::from("list_pop_back")],
789773
}
790774
}

datafusion/sqllogictest/test_files/array.slt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,12 @@ select array_slice(arrow_cast(make_array(1, 2, 3, 4, 5), 'LargeList(Int64)'), 2,
19481948
----
19491949
[2, 3, 4] [h, e]
19501950

1951+
query ??
1952+
select array_slice(arrow_cast(make_array(1, 2, 3, 4, 5), 'FixedSizeList(5, Int64)'), 2, 4),
1953+
array_slice(arrow_cast(make_array('h', 'e', 'l', 'l', 'o'), 'FixedSizeList(5, Utf8)'), 1, 2);
1954+
----
1955+
[2, 3, 4] [h, e]
1956+
19511957
# array_slice scalar function #2 (with positive indexes; full array)
19521958
query ??
19531959
select array_slice(make_array(1, 2, 3, 4, 5), 0, 6), array_slice(make_array('h', 'e', 'l', 'l', 'o'), 0, 5);
@@ -1959,6 +1965,12 @@ select array_slice(arrow_cast(make_array(1, 2, 3, 4, 5), 'LargeList(Int64)'), 0,
19591965
----
19601966
[1, 2, 3, 4, 5] [h, e, l, l, o]
19611967

1968+
query ??
1969+
select array_slice(arrow_cast(make_array(1, 2, 3, 4, 5), 'FixedSizeList(5, Int64)'), 0, 6),
1970+
array_slice(arrow_cast(make_array('h', 'e', 'l', 'l', 'o'), 'FixedSizeList(5, Utf8)'), 0, 5);
1971+
----
1972+
[1, 2, 3, 4, 5] [h, e, l, l, o]
1973+
19621974
# array_slice scalar function #3 (with positive indexes; first index = second index)
19631975
query ??
19641976
select array_slice(make_array(1, 2, 3, 4, 5), 4, 4), array_slice(make_array('h', 'e', 'l', 'l', 'o'), 3, 3);

0 commit comments

Comments
 (0)