Skip to content

Commit f26138c

Browse files
committed
Support LargeList for ListIndex
Signed-off-by: Chojan Shang <[email protected]>
1 parent 2a490e4 commit f26138c

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

datafusion/expr/src/field_util.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,19 @@ impl GetFieldAccessSchema {
7878
Self::ListIndex{ key_dt } => {
7979
match (data_type, key_dt) {
8080
(DataType::List(lt), DataType::Int64) => Ok(Field::new("list", lt.data_type().clone(), true)),
81-
(DataType::List(_), _) => plan_err!(
82-
"Only ints are valid as an indexed field in a list"
81+
(DataType::LargeList(lt), DataType::Int64) => Ok(Field::new("large_list", lt.data_type().clone(), true)),
82+
(DataType::List(_), _) | (DataType::LargeList(_), _) => plan_err!(
83+
"Only ints are valid as an indexed field in a List/LargeList"
8384
),
84-
(other, _) => plan_err!("The expression to get an indexed field is only valid for `List` or `Struct` types, got {other}"),
85+
(other, _) => plan_err!("The expression to get an indexed field is only valid for `List`, `LargeList` or `Struct` types, got {other}"),
8586
}
8687
}
8788
Self::ListRange { start_dt, stop_dt, stride_dt } => {
8889
match (data_type, start_dt, stop_dt, stride_dt) {
8990
(DataType::List(_), DataType::Int64, DataType::Int64, DataType::Int64) => Ok(Field::new("list", data_type.clone(), true)),
9091
(DataType::LargeList(_), DataType::Int64, DataType::Int64, DataType::Int64) => Ok(Field::new("large_list", data_type.clone(), true)),
9192
(DataType::List(_), _, _, _) | (DataType::LargeList(_), _, _, _)=> plan_err!(
92-
"Only ints are valid as an indexed field in a list"
93+
"Only ints are valid as an indexed field in a List/LargeList"
9394
),
9495
(other, _, _, _) => plan_err!("The expression to get an indexed field is only valid for `List`, `LargeList` or `Struct` types, got {other}"),
9596
}

datafusion/physical-expr/src/expressions/get_indexed_field.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,14 @@ impl PhysicalExpr for GetIndexedFieldExpr {
252252
GetFieldAccessExpr::ListIndex{key} => {
253253
let key = key.evaluate(batch)?.into_array(batch.num_rows())?;
254254
match (array.data_type(), key.data_type()) {
255-
(DataType::List(_), DataType::Int64) => Ok(ColumnarValue::Array(array_element(&[
255+
(DataType::List(_), DataType::Int64) | (DataType::LargeList(_), DataType::Int64) => Ok(ColumnarValue::Array(array_element(&[
256256
array, key
257257
])?)),
258-
(DataType::List(_), key) => exec_err!(
259-
"get indexed field is only possible on lists with int64 indexes. \
258+
(DataType::List(_), key) | (DataType::LargeList(_), key) => exec_err!(
259+
"get indexed field is only possible on List/LargeList with int64 indexes. \
260260
Tried with {key:?} index"),
261261
(dt, key) => exec_err!(
262-
"get indexed field is only possible on lists with int64 indexes or struct \
262+
"get indexed field is only possible on List/LargeList with int64 indexes or struct \
263263
with utf8 indexes. Tried {dt:?} with {key:?} index"),
264264
}
265265
},

datafusion/sqllogictest/test_files/array.slt

+5
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,11 @@ select arrow_cast([1, 2, 3], 'LargeList(Int64)')[0:0],
883883
----
884884
[] [1, 2] [h, e, l, l, o]
885885

886+
query I
887+
select arrow_cast([1, 2, 3], 'LargeList(Int64)')[1];
888+
----
889+
1
890+
886891
# TODO: support multiple negative index
887892
# multiple index with columns #3 (negative index)
888893
# query II

0 commit comments

Comments
 (0)