Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(arrow-select): concat kernel will merge dictionary values for list of dictionaries #6893

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

rluvaton
Copy link
Contributor

@rluvaton rluvaton commented Dec 17, 2024

Which issue does this PR close?

Closes #6888

What changes are included in this PR?

  1. Updated concat kernel to merge dictionary values for list of dictionary
  2. Created merge function in BufferOffset for merging multiple BuffersOffset into one (which needed for the concat merge)

Are there any user-facing changes?

Yes, the merge function in the BufferOffset struct

TODO:
- [ ] Add support to nested lists
- [ ] Add more tests
- [ ] Fix failing test
@github-actions github-actions bot added the arrow Changes to the arrow crate label Dec 17, 2024
arrow-select/src/concat.rs Outdated Show resolved Hide resolved
arrow-select/src/concat.rs Outdated Show resolved Hide resolved
@rluvaton rluvaton changed the title feat(arrow-select): make list of dictionary merge dictionary keys feat(arrow-select): concat kernel will merge dictionary values for list of dictionaries Dec 17, 2024
arrow-select/src/concat.rs Outdated Show resolved Hide resolved
@@ -129,12 +130,106 @@ fn concat_dictionaries<K: ArrowDictionaryKeyType>(
Ok(Arc::new(array))
}

fn concat_list_of_dictionaries<OffsetSize: OffsetSizeTrait, K: ArrowDictionaryKeyType>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would significantly reduce the codegen to instead split concatenating the dictionary values, from re-encoding the offsets. As an added bonus this could also be done recursively.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, please let me know it that was what you meant, I think it will be slower this way, no?

Copy link
Contributor

@tustvold tustvold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've taken a quick look and left some suggestions on how to simplify this, in particular separating the concatenation of the list values and the list offsets will result in less code, require less codegen, and likely perform better.

i.e. something like (not tested)


DataType::List(f) => {
    let values: Vec<_> = arrays.iter().map(|x| x.as_list::<i32>().values()).collect();
    let new_values = concat(&values)?;
    let offsets = OffsetBuffer::from_lengths(
        arrays.iter().flat_map(|x| x.as_list::<i32>().offsets()
             .windows(2).map(|w| w[1].as_usize() - w[0].as_usize()))
    );
    let nulls = ...
    ListArray::new(f, offsets, new_values, nulls)
}

@tustvold tustvold marked this pull request as draft December 18, 2024 10:51
@rluvaton rluvaton marked this pull request as ready for review December 21, 2024 16:39
Copy link
Contributor

@tustvold tustvold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking very promising, just a small comment r.e. avoiding ArrayData

I'll try to find some time for a more thorough review in the next few days if nobody else gets there first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

arrow::compute::concat should merge dictionary type when concatenating list of dictionaries
2 participants