@@ -144,6 +144,12 @@ impl Inserter<&str> for FlatVector {
144144 }
145145}
146146
147+ impl Inserter < & String > for FlatVector {
148+ fn insert ( & self , index : usize , value : & String ) {
149+ self . insert ( index, value. as_str ( ) ) ;
150+ }
151+ }
152+
147153impl Inserter < & [ u8 ] > for FlatVector {
148154 fn insert ( & self , index : usize , value : & [ u8 ] ) {
149155 let value_size = value. len ( ) ;
@@ -159,6 +165,12 @@ impl Inserter<&[u8]> for FlatVector {
159165 }
160166}
161167
168+ impl Inserter < & Vec < u8 > > for FlatVector {
169+ fn insert ( & self , index : usize , value : & Vec < u8 > ) {
170+ self . insert ( index, value. as_slice ( ) ) ;
171+ }
172+ }
173+
162174/// A list vector.
163175pub struct ListVector {
164176 /// ListVector does not own the vector pointer.
@@ -352,3 +364,35 @@ impl StructVector {
352364 }
353365 }
354366}
367+
368+ #[ cfg( test) ]
369+ mod tests {
370+ use super :: * ;
371+ use crate :: core:: { DataChunkHandle , LogicalTypeId } ;
372+ use std:: ffi:: CString ;
373+
374+ #[ test]
375+ fn test_insert_string_values ( ) {
376+ let chunk = DataChunkHandle :: new ( & [ LogicalTypeId :: Varchar . into ( ) ] ) ;
377+ let vector = chunk. flat_vector ( 0 ) ;
378+ chunk. set_len ( 3 ) ;
379+
380+ vector. insert ( 0 , "first" ) ;
381+ vector. insert ( 1 , & String :: from ( "second" ) ) ;
382+ let cstring = CString :: new ( "third" ) . unwrap ( ) ;
383+ vector. insert ( 2 , cstring) ;
384+ }
385+
386+ #[ test]
387+ fn test_insert_byte_values ( ) {
388+ let chunk = DataChunkHandle :: new ( & [ LogicalTypeId :: Blob . into ( ) ] ) ;
389+ let vector = chunk. flat_vector ( 0 ) ;
390+ chunk. set_len ( 2 ) ;
391+
392+ vector. insert ( 0 , b"hello world" . as_slice ( ) ) ;
393+ vector. insert (
394+ 1 ,
395+ & vec ! [ 0x68 , 0x65 , 0x6c , 0x6c , 0x6f , 0x20 , 0x77 , 0x6f , 0x72 , 0x6c , 0x64 ] ,
396+ ) ;
397+ }
398+ }
0 commit comments