Skip to content

Fix concat for sliced ListArrays - #7037

Merged
alamb merged 4 commits into
apache:mainfrom
alamb:alamb/list_array_sliced
Jan 29, 2025
Merged

Fix concat for sliced ListArrays#7037
alamb merged 4 commits into
apache:mainfrom
alamb:alamb/list_array_sliced

Conversation

@alamb

@alamb alamb commented Jan 28, 2025

Copy link
Copy Markdown
Contributor

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
Comment thread arrow-select/src/concat.rs Outdated

Copy link
Copy Markdown
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]))

Comment thread arrow-select/src/concat.rs Outdated

@alamb alamb Jan 28, 2025

Copy link
Copy Markdown
Contributor Author

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

@rluvaton rluvaton Jan 28, 2025

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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

alamb commented Jan 28, 2025

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
Member

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
Copy Markdown
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 👍

@rluvaton rluvaton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@tustvold tustvold left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread arrow-select/src/concat.rs Outdated

Copy link
Copy Markdown
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

alamb commented Jan 28, 2025

Copy link
Copy Markdown
Contributor Author

Thank you @tustvold and @rluvaton

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

Comment thread arrow-select/src/concat.rs Outdated
Co-authored-by: Raz Luvaton <16746759+rluvaton@users.noreply.github.com>
@alamb

alamb commented Jan 28, 2025

Copy link
Copy Markdown
Contributor Author

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

@alamb

alamb commented Jan 29, 2025

Copy link
Copy Markdown
Contributor Author

Merging and will make a release candidate shortly

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