Add in-place group adoption for arena-resident batches

This commit is contained in:
Dennis Kobert
2026-08-21 20:16:19 +00:00
parent b5c4aa4598
commit f12094ced6
2 changed files with 28 additions and 1 deletions

View File

@@ -74,6 +74,10 @@ impl<'a> RecordBatch<'a> {
self.layout
}
pub(crate) fn frames_ptr(&self) -> *const u8 {
self.frames
}
pub fn get(&self, lane: usize) -> RecordLane<'a> {
assert!(lane < self.len, "lane {lane} out of bounds for a batch of {}", self.len);
RecordLane {
@@ -214,6 +218,10 @@ impl<'a, T> List<'a, T> {
self.batch.is_empty()
}
pub fn batch(&self) -> RecordBatch<'a> {
self.batch
}
pub fn get(&self, index: usize) -> T
where
T: Copy,

View File

@@ -1623,9 +1623,28 @@ impl GroupItem {
&self.layout
}
/// A `GroupItem` over the batch's frames, without copying.
///
/// # Safety
/// The frames must stay valid for the evaluation. Arena-resident batches
/// qualify, caller stack scratch does not.
pub unsafe fn from_resident(batch: crate::node::RecordBatch<'_>) -> Self {
let layout = batch.layout().clone();
assert!(!layout.element.parked || layout.element.content_hash.is_some(), "a parked element adopts only with content glue");
for field in &layout.fields {
assert!(field.repark.is_none() || field.content_hash.is_some(), "a parked field adopts only with content glue");
}
Self {
frames: batch.frames_ptr(),
len: batch.len(),
layout,
}
}
/// A batch view over the stored records.
pub fn lanes(&self) -> crate::node::RecordBatch<'_> {
// SAFETY: `adopt` filled `len` lanes of `layout` at the layout's stride.
// SAFETY: the constructors store `len` lanes of `layout` at the
// layout's stride.
unsafe { crate::node::RecordBatch::new(self.frames, self.len, &self.layout) }
}