Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion encodings/experimental/onpair/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ impl VTable for OnPair {
.clone()
.execute::<Canonical>(ctx)?
.into_array(),
);
ctx,
)?;
return Ok(());
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ mod test {

let mut primitive_builder =
PrimitiveBuilder::<i32>::with_capacity(chunked.dtype().nullability(), 10 * 100);
primitive_builder.extend_from_array(&chunked);
primitive_builder.extend_from_array(&chunked, &mut ctx)?;
let ca_into = primitive_builder.finish();

assert_arrays_eq!(into_ca, ca_into);
Expand Down
3 changes: 2 additions & 1 deletion encodings/fsst/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ impl VTable for FSST {
.clone()
.execute::<Canonical>(ctx)?
.into_array(),
);
ctx,
)?;
return Ok(());
};

Expand Down
21 changes: 15 additions & 6 deletions encodings/sparse/src/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,15 @@ fn execute_sparse_lists_inner<I: IntegerPType, O: IntegerPType>(
&mut builder,
fill_elements.as_ref(),
sparse_idx - next_index,
ctx,
);

if patch_valid {
let patch_list = patch_values
.list_elements_at(patch_idx)
.vortex_expect("list_elements_at");
builder
.append_array_as_list(&patch_list)
.append_array_as_list(&patch_list, ctx)
.vortex_expect("Failed to append sparse value");
} else {
builder.append_null();
Expand All @@ -255,7 +256,7 @@ fn execute_sparse_lists_inner<I: IntegerPType, O: IntegerPType>(
next_index = sparse_idx + 1;
}

append_list_fill(&mut builder, fill_elements.as_ref(), len - next_index);
append_list_fill(&mut builder, fill_elements.as_ref(), len - next_index, ctx);

builder.finish()
}
Expand Down Expand Up @@ -328,6 +329,7 @@ fn execute_sparse_fixed_size_list_inner<I: IntegerPType>(
&mut builder,
fill_elements.as_ref(),
sparse_idx - next_index,
ctx,
);

// Append the patch value, handling null patches by appending defaults.
Expand All @@ -336,7 +338,7 @@ fn execute_sparse_fixed_size_list_inner<I: IntegerPType>(
.fixed_size_list_elements_at(patch_idx)
.vortex_expect("fixed_size_list_elements_at");
builder
.append_array_as_list(&patch_list)
.append_array_as_list(&patch_list, ctx)
.vortex_expect("Failed to append sparse fixed-size-list value");
} else {
builder.append_null();
Expand All @@ -346,7 +348,12 @@ fn execute_sparse_fixed_size_list_inner<I: IntegerPType>(
}

// Fill remaining positions after last patch.
append_fixed_size_list_fill(&mut builder, fill_elements.as_ref(), array_len - next_index);
append_fixed_size_list_fill(
&mut builder,
fill_elements.as_ref(),
array_len - next_index,
ctx,
);

builder.finish_into_fixed_size_list()
}
Expand All @@ -367,11 +374,12 @@ fn append_list_fill<O: IntegerPType, S: IntegerPType>(
builder: &mut ListViewBuilder<O, S>,
fill_elements: Option<&ArrayRef>,
count: usize,
ctx: &mut ExecutionCtx,
) {
if let Some(fill_elements) = fill_elements {
for _ in 0..count {
builder
.append_array_as_list(fill_elements)
.append_array_as_list(fill_elements, ctx)
.vortex_expect("Failed to append sparse fill value");
}
} else {
Expand All @@ -383,11 +391,12 @@ fn append_fixed_size_list_fill(
builder: &mut FixedSizeListBuilder,
fill_elements: Option<&ArrayRef>,
count: usize,
ctx: &mut ExecutionCtx,
) {
if let Some(fill_elements) = fill_elements {
for _ in 0..count {
builder
.append_array_as_list(fill_elements)
.append_array_as_list(fill_elements, ctx)
.vortex_expect("Failed to append sparse fixed-size-list fill value");
}
} else {
Expand Down
11 changes: 9 additions & 2 deletions vortex-array/benches/listview_builder_extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::sync::Arc;

use divan::Bencher;
use vortex_array::IntoArray;
use vortex_array::LEGACY_SESSION;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::ListViewArray;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::builders::ArrayBuilder;
Expand All @@ -18,6 +20,7 @@ use vortex_array::dtype::Nullability::Nullable;
use vortex_array::dtype::PType::I32;
use vortex_array::validity::Validity;
use vortex_buffer::Buffer;
use vortex_error::VortexExpect;

fn main() {
divan::main();
Expand Down Expand Up @@ -69,7 +72,9 @@ fn extend_from_array_zctl(bencher: Bencher, (num_lists, list_size): (usize, usiz
num_lists * list_size,
num_lists,
);
builder.extend_from_array(source);
builder
.extend_from_array(source, &mut LEGACY_SESSION.create_execution_ctx())
.vortex_expect("extend_from_array");
divan::black_box(builder.finish_into_listview())
});
}
Expand All @@ -91,7 +96,9 @@ fn extend_from_array_non_zctl_overlapping(
num_lists * list_size,
num_lists,
);
builder.extend_from_array(source);
builder
.extend_from_array(source, &mut LEGACY_SESSION.create_execution_ctx())
.vortex_expect("extend_from_array");
divan::black_box(builder.finish_into_listview())
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,11 @@ mod tests {

fn materialized_uncompressed_size_in_bytes(array: &ArrayRef) -> u64 {
let mut builder = builder_with_capacity(array.dtype(), array.len());
let mut ctx = LEGACY_SESSION.create_execution_ctx();
unsafe {
builder.extend_from_array_unchecked(array);
builder
.extend_from_array_unchecked(array, &mut ctx)
.unwrap();
}
builder.finish().nbytes()
}
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/array/vtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub trait VTable: 'static + Clone + Sized + Send + Sync + Debug {
.clone()
.execute::<Canonical>(ctx)?
.into_array();
builder.extend_from_array(&canonical);
builder.extend_from_array(&canonical, ctx)?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/arrays/constant/vtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl VTable for Constant {
.clone()
.execute::<Canonical>(ctx)?
.into_array();
builder.extend_from_array(&canonical);
builder.extend_from_array(&canonical, ctx)?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/arrays/listview/rebuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl ListViewArray {

new_offsets.push(n_elements);
new_sizes.push(size);
new_elements_builder.extend_from_array(&elements_canonical.slice(start..stop)?);
new_elements_builder.extend_from_array(&elements_canonical.slice(start..stop)?, ctx)?;

n_elements += num_traits::cast(size).vortex_expect("Cast failed");
}
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/arrays/patched/vtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl VTable for Patched {
.clone()
.execute::<Canonical>(ctx)?
.into_array();
builder.extend_from_array(&canonical);
builder.extend_from_array(&canonical, ctx)?;
return Ok(());
}

Expand Down
5 changes: 4 additions & 1 deletion vortex-array/src/arrays/varbinview/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ impl VarBinViewArray {
self.len(),
buffer_utilization_threshold,
);
builder.extend_from_array(&self.clone().into_array());
// This array is already canonical, so executing it through the builder is cheap; we only
// need a context to satisfy the `extend_from_array` signature.
let mut ctx = LEGACY_SESSION.create_execution_ctx();
builder.extend_from_array(&self.clone().into_array(), &mut ctx)?;
Ok(builder.finish_into_varbinview())
}
}
Expand Down
26 changes: 11 additions & 15 deletions vortex-array/src/builders/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@ use std::any::Any;
use std::mem;

use vortex_buffer::BitBufferMut;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::vortex_ensure;
use vortex_mask::Mask;

use crate::ArrayRef;
use crate::ExecutionCtx;
use crate::IntoArray;
use crate::LEGACY_SESSION;
use crate::VortexSessionExecute;
use crate::arrays::BoolArray;
use crate::arrays::bool::BoolArrayExt;
use crate::builders::ArrayBuilder;
use crate::builders::DEFAULT_BUILDER_CAPACITY;
use crate::builders::LazyBitBufferBuilder;
use crate::canonical::Canonical;
#[expect(deprecated)]
use crate::canonical::ToCanonical as _;
use crate::dtype::DType;
use crate::dtype::Nullability;
use crate::scalar::Scalar;
Expand Down Expand Up @@ -115,22 +111,22 @@ impl ArrayBuilder for BoolBuilder {
Ok(())
}

unsafe fn extend_from_array_unchecked(&mut self, array: &ArrayRef) {
#[expect(deprecated)]
let bool_array = array.to_bool();
unsafe fn extend_from_array_unchecked(
&mut self,
array: &ArrayRef,
ctx: &mut ExecutionCtx,
) -> VortexResult<()> {
let bool_array = array.clone().execute::<BoolArray>(ctx)?;

self.inner.append_buffer(&bool_array.to_bit_buffer());
self.nulls.append_validity_mask(
&bool_array
.as_ref()
.validity()
.vortex_expect("validity_mask")
.execute_mask(
bool_array.as_ref().len(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.vortex_expect("Failed to compute validity mask"),
.validity()?
.execute_mask(bool_array.as_ref().len(), ctx)?,
);

Ok(())
}

fn reserve_exact(&mut self, additional: usize) {
Expand Down
29 changes: 14 additions & 15 deletions vortex-array/src/builders/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ use vortex_error::vortex_panic;
use vortex_mask::Mask;

use crate::ArrayRef;
use crate::ExecutionCtx;
use crate::IntoArray;
use crate::LEGACY_SESSION;
#[expect(deprecated)]
use crate::ToCanonical as _;
use crate::VortexSessionExecute;
use crate::arrays::DecimalArray;
use crate::builders::ArrayBuilder;
use crate::builders::DEFAULT_BUILDER_CAPACITY;
Expand Down Expand Up @@ -195,9 +192,12 @@ impl ArrayBuilder for DecimalBuilder {
Ok(())
}

unsafe fn extend_from_array_unchecked(&mut self, array: &ArrayRef) {
#[expect(deprecated)]
let decimal_array = array.to_decimal();
unsafe fn extend_from_array_unchecked(
&mut self,
array: &ArrayRef,
ctx: &mut ExecutionCtx,
) -> VortexResult<()> {
let decimal_array = array.clone().execute::<DecimalArray>(ctx)?;

match_each_decimal_value_type!(decimal_array.values_type(), |D| {
// Extends the values buffer from another buffer of type D where D can be coerced to the
Expand All @@ -209,14 +209,11 @@ impl ArrayBuilder for DecimalBuilder {
self.nulls.append_validity_mask(
&decimal_array
.as_ref()
.validity()
.vortex_expect("validity_mask")
.execute_mask(
decimal_array.as_ref().len(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.vortex_expect("Failed to compute validity mask"),
.validity()?
.execute_mask(decimal_array.as_ref().len(), ctx)?,
);

Ok(())
}

fn reserve_exact(&mut self, additional: usize) {
Expand Down Expand Up @@ -328,7 +325,9 @@ mod tests {
let i8s = i8s.finish();

let mut i128s = DecimalBuilder::new::<i128>(DecimalDType::new(2, 1), false.into());
i128s.extend_from_array(&i8s);
i128s
.extend_from_array(&i8s, &mut LEGACY_SESSION.create_execution_ctx())
.unwrap();
let i128s = i128s.finish();

for i in 0..i8s.len() {
Expand Down
15 changes: 9 additions & 6 deletions vortex-array/src/builders/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ use vortex_error::vortex_ensure;
use vortex_mask::Mask;

use crate::ArrayRef;
use crate::ExecutionCtx;
use crate::IntoArray;
use crate::arrays::ExtensionArray;
use crate::arrays::extension::ExtensionArrayExt;
use crate::builders::ArrayBuilder;
use crate::builders::DEFAULT_BUILDER_CAPACITY;
use crate::builders::builder_with_capacity;
use crate::canonical::Canonical;
#[expect(deprecated)]
use crate::canonical::ToCanonical as _;
use crate::dtype::DType;
use crate::dtype::extension::ExtDTypeRef;
use crate::scalar::ExtScalar;
Expand Down Expand Up @@ -99,10 +98,14 @@ impl ArrayBuilder for ExtensionBuilder {
self.append_value(scalar.as_extension())
}

unsafe fn extend_from_array_unchecked(&mut self, array: &ArrayRef) {
#[expect(deprecated)]
let ext_array = array.to_extension();
self.storage.extend_from_array(ext_array.storage_array())
unsafe fn extend_from_array_unchecked(
&mut self,
array: &ArrayRef,
ctx: &mut ExecutionCtx,
) -> VortexResult<()> {
let ext_array = array.clone().execute::<ExtensionArray>(ctx)?;
self.storage
.extend_from_array(ext_array.storage_array(), ctx)
}

fn reserve_exact(&mut self, capacity: usize) {
Expand Down
Loading
Loading