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

Fix concat for sliced ListArrays #7037

Merged
merged 4 commits into from
Jan 29, 2025
Merged

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Jan 28, 2025

Which issue does this PR close?

Rationale for this change

Fixes a regression introduced in

What changes are included in this PR?

  1. Add a test
  2. Fix the issue

I also tested that this fixes the issue I found downstream in

Are there any user-facing changes?

Fix a bug

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jan 28, 2025
@alamb alamb changed the title Fix concatenating sliced ListArrays Fix concat for sliced ListArrays Jan 28, 2025
let offsets = x.offsets();
let start_offset = offsets[0].as_usize();
let end_offset = offsets[offsets.len() - 1].as_usize();
x.values().slice(start_offset, end_offset - start_offset)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is that the values of sliced ListArrays do not necessairly start at zero

For the test in this PR, the offsets are:

concat_lists offsets: OffsetBuffer(ScalarBuffer([5, 5, 5]))
concat_lists offsets: OffsetBuffer(ScalarBuffer([0, 0, 3, 4]))

.collect::<Vec<_>>();
// If any of the lists have slices, we need to slice the values
// to ensure that the offsets are correct
let mut sliced_values;
Copy link
Contributor Author

@alamb alamb Jan 28, 2025

Choose a reason for hiding this comment

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

While I was futzing with this, I figured I would avoid slice on the values unless it was necessary.

I can make this code simpler if we always slice but that will always make an ArrayRef clone

Copy link
Contributor

@rluvaton rluvaton Jan 28, 2025

Choose a reason for hiding this comment

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

Is slice really expensive? Isn't it zero copy as the actual values (everything that is using Buffer) are behind arc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think they are very expensive (they are several Arc::clone)

Copy link
Contributor

Choose a reason for hiding this comment

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

Given this isn't a hot loop, it is invoked once per input array, I suspect the overheads of slice would likely be irrelevant, but this is also fine

@alamb
Copy link
Contributor Author

alamb commented Jan 28, 2025

@rluvaton and @tustvold can you please review?

Some(vec![Some(10)]),
];
let list1_array = ListArray::from_iter_primitive::<Int64Type, _, _>(list1.clone());
let list1_array = list1_array.slice(1, 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add assertion here that the offsets really don't start from 0 to make sure we actually cover that case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Thank you for the suggestion. done in e22760e 👍

Copy link
Contributor

@rluvaton rluvaton left a comment

Choose a reason for hiding this comment

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

Thank you!

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.

Looks good to me, thank you

.collect::<Vec<_>>();
// If any of the lists have slices, we need to slice the values
// to ensure that the offsets are correct
let mut sliced_values;
Copy link
Contributor

Choose a reason for hiding this comment

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

Given this isn't a hot loop, it is invoked once per input array, I suspect the overheads of slice would likely be irrelevant, but this is also fine

@alamb
Copy link
Contributor Author

alamb commented Jan 28, 2025

Thank you @tustvold and @rluvaton

I also made a small follow on PR to try and improve the documentation about ListArray and offsets / values

@alamb
Copy link
Contributor Author

alamb commented Jan 28, 2025

I plan to merge this tomorrow morning and make a 54.1.0 release candidate

@alamb
Copy link
Contributor Author

alamb commented Jan 29, 2025

Merging and will make a release candidate shortly

@alamb alamb merged commit b1bfa0f into apache:main Jan 29, 2025
26 checks passed
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.

Regression: Concatenating sliced ListArrays is broken
3 participants