Skip to content

chore: use new OffsetBuffer::subtract helper#23424

Open
rluvaton wants to merge 3 commits into
apache:mainfrom
rluvaton:use-arrow-subtract
Open

chore: use new OffsetBuffer::subtract helper#23424
rluvaton wants to merge 3 commits into
apache:mainfrom
rluvaton:use-arrow-subtract

Conversation

@rluvaton

@rluvaton rluvaton commented Jul 9, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A

Rationale for this change

Replace manually written code with the newly added helper I added to arrow-rs in:

What changes are included in this PR?

use OffsetBuffer::subtract

Are these changes tested?

Existing tests

Are there any user-facing changes?

No

@github-actions github-actions Bot added common Related to common crate functions Changes to functions implementation labels Jul 9, 2026
Comment on lines -1239 to -1248
if let (Some(first), Some(last)) = (offsets.first(), offsets.last())
&& (!first.is_zero() || last.as_usize() != list.values().len())
{
let offsets = offsets.iter().map(|offset| *offset - *first).collect();

//todo: use unsafe Offset::new_unchecked?
return OffsetBuffer::new(offsets);
}

offsets.clone()

@rluvaton rluvaton Jul 9, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Even though this code has last != list.values().len() and the subtract doesn't have that check, that check is not needed as we don't use the last values at all

}

offsets.clone()
offsets.clone().subtract(offsets[0])

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.

For a prefix slice where the first offset is zero but the last visible offset is before the end of the original child values, subtract(0) returns a clone sharing the original allocation. The previous
Implementation created a compact offset buffer in this case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I'm willing to sacrifice that in favor of avoiding copy and because this was not guaranteed

@xudong963 xudong963 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.

Other places look good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to common crate functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants