@@ -231,6 +231,12 @@ impl ListVector {
231231 self . entries . as_mut_slice :: < duckdb_list_entry > ( ) [ idx] . length = length as u64 ;
232232 }
233233
234+ /// Get offset and length for the entry at index.
235+ pub fn get_entry ( & self , idx : usize ) -> ( usize , usize ) {
236+ let entry = self . entries . as_slice :: < duckdb_list_entry > ( ) [ idx] ;
237+ ( entry. offset as usize , entry. length as usize )
238+ }
239+
234240 /// Set row as null
235241 pub fn set_null ( & mut self , row : usize ) {
236242 unsafe {
@@ -368,7 +374,7 @@ impl StructVector {
368374#[ cfg( test) ]
369375mod tests {
370376 use super :: * ;
371- use crate :: core:: { DataChunkHandle , LogicalTypeId } ;
377+ use crate :: core:: { DataChunkHandle , LogicalTypeHandle , LogicalTypeId } ;
372378 use std:: ffi:: CString ;
373379
374380 #[ test]
@@ -395,4 +401,21 @@ mod tests {
395401 & vec ! [ 0x68 , 0x65 , 0x6c , 0x6c , 0x6f , 0x20 , 0x77 , 0x6f , 0x72 , 0x6c , 0x64 ] ,
396402 ) ;
397403 }
404+
405+ #[ test]
406+ fn test_list_vector_get_entry ( ) {
407+ let list_type = LogicalTypeHandle :: list ( & LogicalTypeId :: Integer . into ( ) ) ;
408+ let chunk = DataChunkHandle :: new ( & [ list_type] ) ;
409+ chunk. set_len ( 3 ) ;
410+
411+ let mut list_vector = chunk. list_vector ( 0 ) ;
412+
413+ list_vector. set_entry ( 0 , 0 , 2 ) ;
414+ list_vector. set_entry ( 1 , 2 , 1 ) ;
415+ list_vector. set_entry ( 2 , 3 , 2 ) ;
416+
417+ assert_eq ! ( list_vector. get_entry( 0 ) , ( 0 , 2 ) ) ;
418+ assert_eq ! ( list_vector. get_entry( 1 ) , ( 2 , 1 ) ) ;
419+ assert_eq ! ( list_vector. get_entry( 2 ) , ( 3 , 2 ) ) ;
420+ }
398421}
0 commit comments