Skip to content
Merged
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
17 changes: 9 additions & 8 deletions encodings/zstd/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,15 @@ impl VTable for Zstd {
{
return result;
}
// The two arms here are every builder a `Utf8`/`Binary` dtype has: all four
// `VarBinBuilder` widths above, and `VarBinViewBuilder` below. There is deliberately no
// canonicalize-then-append fallback — it would decompress to a `VarBinView` only for
// `VarBinView::append_to_builder` to reject the same remainder.
let Some(builder) = builder.as_any_mut().downcast_mut::<VarBinViewBuilder>() else {
vortex_bail!("append_to_builder for Zstd requires a variable-binary builder")
};
append_to_varbinview(array, builder, ctx)
if let Some(builder) = builder.as_any_mut().downcast_mut::<VarBinViewBuilder>() {
return append_to_varbinview(array, builder, ctx);
}
array
.array()
.clone()
.execute::<Canonical>(ctx)?
.into_array()
.append_to_builder(builder, ctx)
}

fn reduce_parent(
Expand Down
47 changes: 32 additions & 15 deletions encodings/zstd/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ use vortex_array::assert_arrays_eq;
use vortex_array::assert_nth_scalar;
use vortex_array::builders::VarBinBuilder;
use vortex_array::builders::VarBinViewBuilder;
use vortex_array::builders::builder_with_capacity_in;
use vortex_array::dtype::DType;
use vortex_array::dtype::Nullability;
use vortex_array::dtype::PType;
use vortex_array::validity::Validity;
use vortex_buffer::Alignment;
use vortex_buffer::Buffer;
use vortex_buffer::BufferAllocatorRef;
use vortex_buffer::ByteBuffer;
use vortex_error::VortexResult;
use vortex_mask::Mask;
Expand Down Expand Up @@ -217,7 +219,28 @@ fn test_zstd_var_bin_view() {
}

#[test]
fn test_zstd_append_to_offset_builder() {
fn test_zstd_append_to_primitive_builder() -> VortexResult<()> {
let mut ctx = array_session().create_execution_ctx();
let array = PrimitiveArray::from_option_iter([Some(1_i32), None, Some(3), Some(4), Some(5)]);
let compressed = Zstd::from_primitive(&array, 0, 3, &mut ctx)?.slice(1..4)?;
let mut builder = builder_with_capacity_in(
compressed.dtype(),
compressed.len(),
BufferAllocatorRef::static_ref(),
);
compressed.append_to_builder(builder.as_mut(), &mut ctx)?;
assert_arrays_eq!(builder.finish(), array.into_array().slice(1..4)?, &mut ctx);
Ok(())
}

#[rstest]
fn test_zstd_append_to_offset_builder(
#[values(
DType::Utf8(Nullability::Nullable),
DType::Binary(Nullability::Nullable)
)]
dtype: DType,
) {
let mut ctx = array_session().create_execution_ctx();
let array = VarBinViewArray::from_iter(
[
Expand All @@ -227,7 +250,7 @@ fn test_zstd_append_to_offset_builder() {
Some(b"Lorem ipsum dolor sit amet".as_slice()),
Some(b"baz".as_slice()),
],
DType::Utf8(Nullability::Nullable),
dtype,
);
let compressed = Zstd::from_var_bin_view(&array, 0, 3, &mut ctx)
.unwrap()
Expand All @@ -236,7 +259,7 @@ fn test_zstd_append_to_offset_builder() {
let mut builder = VarBinBuilder::<i32>::with_capacity_in(
compressed.dtype().clone(),
compressed.len(),
vortex_buffer::BufferAllocatorRef::static_ref(),
BufferAllocatorRef::static_ref(),
);
compressed
.append_to_builder(&mut builder, &mut ctx)
Expand Down Expand Up @@ -267,7 +290,7 @@ fn test_zstd_append_to_view_builder_keeps_only_the_sliced_bytes() -> VortexResul
let mut builder = VarBinViewBuilder::with_capacity_in(
compressed.dtype().clone(),
9,
vortex_buffer::BufferAllocatorRef::statically_allocated(),
BufferAllocatorRef::statically_allocated(),
);
builder.append_value(&values[0]);
compressed.append_to_builder(&mut builder, &mut ctx)?;
Expand Down Expand Up @@ -383,7 +406,7 @@ fn test_zstd_rejects_corrupt_frame_metadata(
let mut builder = VarBinBuilder::<i32>::with_capacity_in(
compressed.dtype().clone(),
compressed.len(),
vortex_buffer::BufferAllocatorRef::static_ref(),
BufferAllocatorRef::static_ref(),
);
assert!(
compressed
Expand Down Expand Up @@ -424,17 +447,11 @@ fn test_zstd_rejects_a_frame_ending_in_a_dangling_length_prefix() -> VortexResul
)?;

assert!(Zstd::decompress(&compressed, &mut ctx).is_err());
let mut varbin = VarBinBuilder::<i32>::with_capacity_in(
dtype.clone(),
2,
vortex_buffer::BufferAllocatorRef::static_ref(),
);
let mut varbin =
VarBinBuilder::<i32>::with_capacity_in(dtype.clone(), 2, BufferAllocatorRef::static_ref());
assert!(compressed.append_to_builder(&mut varbin, &mut ctx).is_err());
let mut views = VarBinViewBuilder::with_capacity_in(
dtype,
2,
vortex_buffer::BufferAllocatorRef::statically_allocated(),
);
let mut views =
VarBinViewBuilder::with_capacity_in(dtype, 2, BufferAllocatorRef::statically_allocated());
assert!(compressed.append_to_builder(&mut views, &mut ctx).is_err());
Ok(())
}
Expand Down
Loading