File tree Expand file tree Collapse file tree 2 files changed +9
-9
lines changed
Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -331,10 +331,6 @@ impl ZstdArray {
331331 . copied ( )
332332 . unwrap_or ( value_bytes. len ( ) ) ;
333333
334- // Use slice_unaligned instead of slice to handle cases where frame boundaries
335- // don't align with the buffer's alignment requirements (e.g., 64-byte aligned
336- // buffers with 1-byte frame boundaries). ZSTD compression works on raw bytes
337- // and doesn't require memory alignment.
338334 let uncompressed = & value_bytes. slice ( frame_byte_starts[ i] ..frame_byte_end) ;
339335 let compressed = compressor
340336 . compress ( uncompressed)
@@ -371,8 +367,12 @@ impl ZstdArray {
371367 } ;
372368
373369 let value_bytes = values. byte_buffer ( ) ;
370+ // Align frames to buffer alignment. This is necessary for overaligned buffers.
371+ let alignment = * value_bytes. alignment ( ) ;
372+ let step_width = ( values_per_frame * byte_width) . div_ceil ( alignment) * alignment;
373+
374374 let frame_byte_starts = ( 0 ..n_values * byte_width)
375- . step_by ( values_per_frame * byte_width )
375+ . step_by ( step_width )
376376 . collect :: < Vec < _ > > ( ) ;
377377 let Frames {
378378 dictionary,
Original file line number Diff line number Diff line change @@ -204,13 +204,13 @@ fn test_sliced_array_children() {
204204 sliced. children ( ) ;
205205}
206206
207+ /// Tests that each beginning of a frame in ZSTD matches
208+ /// the buffer alignment when compressing primitive arrays.
207209#[ test]
208- fn test_zstd_alignment_issue ( ) {
209- // Scenario where a u8 array has a 64-byte alignment.
210- // See: https://github.com/vortex-data/vortex/issues/5715
210+ fn test_zstd_frame_start_buffer_alignment ( ) {
211211 let data = vec ! [ 0u8 ; 2 ] ;
212-
213212 let aligned_buffer = Buffer :: copy_from_aligned ( & data, Alignment :: new ( 8 ) ) ;
213+ // u8 array now has a 8-byte alignment.
214214 let array = PrimitiveArray :: new ( aligned_buffer, Validity :: NonNullable ) ;
215215 let compressed = ZstdArray :: from_primitive ( & array, 0 , 1 ) ;
216216
You can’t perform that action at this time.
0 commit comments