Skip to content

chore: use new OffsetBuffer::subtract helper#23424

Merged
rluvaton merged 3 commits into
apache:mainfrom
rluvaton:use-arrow-subtract
Jul 13, 2026
Merged

chore: use new OffsetBuffer::subtract helper#23424
rluvaton merged 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

@Weijun-H Weijun-H 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.

LGTM. Thanks @rluvaton

let offsets = string_array
.offsets()
.clone()
.subtract(string_array.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.

Nice cleanup — this also replaces the unsafe new_unchecked path with the checked subtract. Since the subtrahend is offsets()[0], the internal self[0] >= rhs assert can never fire, so the safety upgrade is free.

@rluvaton
rluvaton added this pull request to the merge queue Jul 13, 2026
Merged via the queue into apache:main with commit 13a6e30 Jul 13, 2026
36 checks passed
@rluvaton
rluvaton deleted the use-arrow-subtract branch July 13, 2026 10:52
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.

3 participants