Skip to content

[C++] ListArray's Flatten function should support recursive flattening of nested lists #41055

@ZhangHuiGui

Description

@ZhangHuiGui

Describe the enhancement requested

The function FlattenListArray seems only support flat the list array like list(int32),

std::vector<std::shared_ptr<Array>> non_null_fragments;
int64_t valid_begin = 0;
while (valid_begin < list_array_length) {
int64_t valid_end = valid_begin;
while (valid_end < list_array_length &&
(list_array.IsValid(valid_end) || list_array.value_length(valid_end) == 0)) {
++valid_end;
}
if (valid_begin < valid_end) {
non_null_fragments.push_back(
SliceArrayWithOffsets(*value_array, list_array.value_offset(valid_begin),
list_array.value_offset(valid_end)));
}
valid_begin = valid_end + 1; // skip null entry
}

Users need to flatten nested list-arrays( list(list(int32)) ), and then the upper layer needs to implement recursive flatten, which seems inconvenient for them.

@felipecrv do you think we should implement this internally(and also for ListViewArray)?

Component(s)

C++

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions