Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Additional operations on MutableListArray #1268

Closed
TethysSvensson opened this issue Oct 5, 2022 · 3 comments · Fixed by #1278
Closed

Additional operations on MutableListArray #1268

TethysSvensson opened this issue Oct 5, 2022 · 3 comments · Fixed by #1278
Assignees
Labels
no-changelog Issues whose changes are covered by a PR and thus should not be shown in the changelog

Comments

@TethysSvensson
Copy link

It would be nice if there was a way to append one MutableListArray into another, which seems hard to do with the current API. This would ideally be both possible and efficient.

It would probably also be nice to be able to iterate over the values in the MutableListArray.

@TethysSvensson
Copy link
Author

In case anybody else is looking for this, my current work-around is this:

fn extend<T: NativeType>(
    left: &mut MutableListArray<i64, MutablePrimitiveArray<T>>,
    right: &MutableListArray<i64, MutablePrimitiveArray<T>>,
) {
    left.mut_values().reserve(right.values().len());
    left.reserve(right.len());

    for offsets in ZipValidity::new(
        right.offsets().windows(2),
        right.validity().map(|v| v.iter()),
    ) {
        left.try_push(offsets.map(|offsets| {
            right
                .values()
                .iter()
                .skip(offsets[0] as usize)
                .take((offsets[1] - offsets[0]) as usize)
                .map(|v| v.copied())
        }))
        .unwrap();
    }
}

@jorgecarleitao jorgecarleitao self-assigned this Oct 6, 2022
@jorgecarleitao
Copy link
Owner

I will try to find a way to address this. The root cause is that Rust without GAT is not particularly helpful for declaring variations of Vec (e.g. iter vs into_iter, TrustedLen), requiring some boilerplate to address all variations.

@jorgecarleitao
Copy link
Owner

@TethysSvensson , tried to address this in #1278.

@jorgecarleitao jorgecarleitao added the no-changelog Issues whose changes are covered by a PR and thus should not be shown in the changelog label Dec 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
no-changelog Issues whose changes are covered by a PR and thus should not be shown in the changelog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@jorgecarleitao @TethysSvensson and others