@@ -229,26 +229,44 @@ impl VTable for Chunked {
229229 let chunk_offsets = chunk_offsets. as_opt :: < Primitive > ( ) . unwrap_or_else ( || {
230230 vortex_panic ! ( "Chunked array chunk_offsets slot must be primitive" )
231231 } ) ;
232+ let chunk_offsets_buf = chunk_offsets. to_buffer :: < u64 > ( ) ;
232233 debug_assert_eq ! (
233- chunk_offsets . len( ) ,
234+ chunk_offsets_buf . len( ) ,
234235 slots. len( ) ,
235236 "Expected {} chunk offsets, found {}" ,
236237 slots. len( ) ,
237- chunk_offsets. len( ) ,
238+ chunk_offsets_buf. len( ) ,
239+ ) ;
240+ debug_assert_eq ! (
241+ chunk_offsets_buf. last( ) . copied( ) . unwrap_or_default( ) ,
242+ array. len as u64 ,
243+ "Chunked array replacement changed logical len: expected {}, got {}" ,
244+ array. len,
245+ chunk_offsets_buf. last( ) . copied( ) . unwrap_or_default( ) ,
238246 ) ;
239- }
240247
241- #[ cfg( debug_assertions) ]
242- for ( idx, chunk_slot) in slots[ 1 ..] . iter ( ) . enumerate ( ) {
243- let chunk = chunk_slot
244- . as_ref ( )
245- . unwrap_or_else ( || vortex_panic ! ( "Chunked array chunk slot {idx} must be present" ) ) ;
246- debug_assert ! (
247- chunk. dtype( ) == array. dtype( ) ,
248- "Chunked array chunk slot {} has dtype {:?}, expected {:?}" ,
249- idx,
250- chunk. dtype( ) ,
251- array. dtype( ) ,
248+ let mut total_len = 0usize ;
249+
250+ for ( idx, chunk_slot) in slots[ 1 ..] . iter ( ) . enumerate ( ) {
251+ let chunk = chunk_slot. as_ref ( ) . unwrap_or_else ( || {
252+ vortex_panic ! ( "Chunked array chunk slot {idx} must be present" )
253+ } ) ;
254+ debug_assert ! (
255+ chunk. dtype( ) == array. dtype( ) ,
256+ "Chunked array chunk slot {} has dtype {:?}, expected {:?}" ,
257+ idx,
258+ chunk. dtype( ) ,
259+ array. dtype( ) ,
260+ ) ;
261+ total_len = total_len. checked_add ( chunk. len ( ) ) . unwrap_or_else ( || {
262+ vortex_panic ! ( "Chunked array chunk lengths exceed usize range" )
263+ } ) ;
264+ }
265+
266+ debug_assert_eq ! (
267+ total_len, array. len,
268+ "Chunked array replacement changed logical len: expected {}, got {}" ,
269+ array. len, total_len,
252270 ) ;
253271 }
254272
0 commit comments