1
1
use std:: { any:: Any , ffi:: CString , slice} ;
2
2
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
+ } ;
4
6
5
7
use super :: LogicalTypeHandle ;
6
8
use crate :: ffi:: {
@@ -55,6 +57,24 @@ impl FlatVector {
55
57
self . capacity
56
58
}
57
59
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
+
58
78
/// Returns an unsafe mutable pointer to the vector’s
59
79
pub fn as_mut_ptr < T > ( & self ) -> * mut T {
60
80
unsafe { duckdb_vector_get_data ( self . ptr ) . cast ( ) }
@@ -65,11 +85,21 @@ impl FlatVector {
65
85
unsafe { slice:: from_raw_parts ( self . as_mut_ptr ( ) , self . capacity ( ) ) }
66
86
}
67
87
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
+
68
93
/// Returns a mutable slice of the vector
69
94
pub fn as_mut_slice < T > ( & mut self ) -> & mut [ T ] {
70
95
unsafe { slice:: from_raw_parts_mut ( self . as_mut_ptr ( ) , self . capacity ( ) ) }
71
96
}
72
97
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
+
73
103
/// Returns the logical type of the vector
74
104
pub fn logical_type ( & self ) -> LogicalTypeHandle {
75
105
unsafe { LogicalTypeHandle :: new ( duckdb_vector_get_column_type ( self . ptr ) ) }
0 commit comments