11use std:: { any:: Any , ffi:: CString , slice} ;
22
3- use libduckdb_sys:: { duckdb_array_type_array_size, duckdb_array_vector_get_child, DuckDbString } ;
3+ use libduckdb_sys:: {
4+ duckdb_array_type_array_size, duckdb_array_vector_get_child, duckdb_validity_row_is_valid, DuckDbString ,
5+ } ;
46
57use super :: LogicalTypeHandle ;
68use crate :: ffi:: {
@@ -55,6 +57,24 @@ impl FlatVector {
5557 self . capacity
5658 }
5759
60+ /// Returns true if the row at the given index is null
61+ pub fn row_is_null ( & self , row : u64 ) -> bool {
62+ // use idx_t entry_idx = row_idx / 64; idx_t idx_in_entry = row_idx % 64; bool is_valid = validity_mask[entry_idx] & (1 « idx_in_entry);
63+ // as the row is valid function is slower
64+ let valid = unsafe {
65+ let validity = duckdb_vector_get_validity ( self . ptr ) ;
66+
67+ // validity can return a NULL pointer if the entire vector is valid
68+ if validity. is_null ( ) {
69+ return false ;
70+ }
71+
72+ duckdb_validity_row_is_valid ( validity, row)
73+ } ;
74+
75+ !valid
76+ }
77+
5878 /// Returns an unsafe mutable pointer to the vector’s
5979 pub fn as_mut_ptr < T > ( & self ) -> * mut T {
6080 unsafe { duckdb_vector_get_data ( self . ptr ) . cast ( ) }
@@ -65,11 +85,21 @@ impl FlatVector {
6585 unsafe { slice:: from_raw_parts ( self . as_mut_ptr ( ) , self . capacity ( ) ) }
6686 }
6787
88+ /// Returns a slice of the vector up to a certain length
89+ pub fn as_slice_with_len < T > ( & self , len : usize ) -> & [ T ] {
90+ unsafe { slice:: from_raw_parts ( self . as_mut_ptr ( ) , len) }
91+ }
92+
6893 /// Returns a mutable slice of the vector
6994 pub fn as_mut_slice < T > ( & mut self ) -> & mut [ T ] {
7095 unsafe { slice:: from_raw_parts_mut ( self . as_mut_ptr ( ) , self . capacity ( ) ) }
7196 }
7297
98+ /// Returns a mutable slice of the vector up to a certain length
99+ pub fn as_mut_slice_with_len < T > ( & mut self , len : usize ) -> & mut [ T ] {
100+ unsafe { slice:: from_raw_parts_mut ( self . as_mut_ptr ( ) , len) }
101+ }
102+
73103 /// Returns the logical type of the vector
74104 pub fn logical_type ( & self ) -> LogicalTypeHandle {
75105 unsafe { LogicalTypeHandle :: new ( duckdb_vector_get_column_type ( self . ptr ) ) }
0 commit comments