Unnest a list array according the target length array. Consider a list array like this: ```ignore [1], [2, 3, 4], null, [5], [], ``` and the length array is: ```ignore [2, 3, 2, 1, 2] ``` If the length of a certain list is less than the target length, pad with NULLs. So the unnested array will look like this: ```ignore [1, null, 2, 3, 4, null, null, 5, null, null] ```
(
list_array: &dyn ListArrayType,
length_array: &PrimitiveArray<Int64Type>,
capacity: usize,
)
| 924 | /// [1, null, 2, 3, 4, null, null, 5, null, null] |
| 925 | /// ``` |
| 926 | fn unnest_list_array( |
| 927 | list_array: &dyn ListArrayType, |
| 928 | length_array: &PrimitiveArray<Int64Type>, |
| 929 | capacity: usize, |
| 930 | ) -> Result<ArrayRef> { |
| 931 | let values = list_array.values(); |
| 932 | let mut take_indices_builder = PrimitiveArray::<Int64Type>::builder(capacity); |
| 933 | for row in 0..list_array.len() { |
| 934 | let mut value_length = 0; |
| 935 | if !list_array.is_null(row) { |
| 936 | let (start, end) = list_array.value_offsets(row); |
| 937 | value_length = end - start; |
| 938 | for i in start..end { |
| 939 | take_indices_builder.append_value(i) |
| 940 | } |
| 941 | } |
| 942 | let target_length = length_array.value(row); |
| 943 | debug_assert!( |
| 944 | value_length <= target_length, |
| 945 | "value length is beyond the longest length" |
| 946 | ); |
| 947 | // Pad with NULL values |
| 948 | for _ in value_length..target_length { |
| 949 | take_indices_builder.append_null(); |
| 950 | } |
| 951 | } |
| 952 | Ok(kernels::take::take( |
| 953 | &values, |
| 954 | &take_indices_builder.finish(), |
| 955 | None, |
| 956 | )?) |
| 957 | } |
| 958 | |
| 959 | /// Creates take indices that will be used to expand all columns except for the list type |
| 960 | /// [`columns`](UnnestExec::list_column_indices) that is being unnested. |
no test coverage detected
searching dependent graphs…