Skip to content

Commit

Permalink
Fix: array list values are leaked on nested unnest operators (apach…
Browse files Browse the repository at this point in the history
…e#10689)

* chore: fix issue + add test

* simplify test case
  • Loading branch information
duongcongtoai committed May 28, 2024
1 parent a51d025 commit 9fba34d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
14 changes: 4 additions & 10 deletions datafusion/physical-plan/src/unnest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,16 +515,10 @@ fn unnest_list_arrays(
})
.collect::<Result<Vec<_>>>()?;

// If there is only one list column to unnest and it doesn't contain any NULL lists,
// we can return the values array directly without any copying.
if typed_arrays.len() == 1 && typed_arrays[0].null_count() == 0 {
Ok(vec![typed_arrays[0].values().clone()])
} else {
typed_arrays
.iter()
.map(|list_array| unnest_list_array(*list_array, length_array, capacity))
.collect::<Result<_>>()
}
typed_arrays
.iter()
.map(|list_array| unnest_list_array(*list_array, length_array, capacity))
.collect::<Result<_>>()
}

/// Unnest a list array according the target length array.
Expand Down
9 changes: 9 additions & 0 deletions datafusion/sqllogictest/test_files/unnest.slt
Original file line number Diff line number Diff line change
Expand Up @@ -449,5 +449,14 @@ select sum(unnest(generate_series(1,10)));
query error DataFusion error: Internal error: unnest on struct can ony be applied at the root level of select expression
select arrow_typeof(unnest(column5)) from unnest_table;


## unnest from a result of a logical plan with limit and offset
query I
select unnest(column1) from (select * from (values([1,2,3]), ([4,5,6])) limit 1 offset 1);
----
4
5
6

statement ok
drop table unnest_table;

0 comments on commit 9fba34d

Please sign in to comment.