pub struct TextArrayV {
pub array: TextArray,
pub offset: usize,
/* private fields */
}Expand description
§TextArrayView
Borrowed, indexable view into a [offset .. offset + len) window of a
TextArray.
§Purpose
- Zero-copy access to contiguous UTF-8 values in either
StringArrayorCategoricalArrayform. - Allows null counts for the view to be cached to speed up scans.
§Fields
array: the backingTextArray.offset: starting index of the view.len: number of logical elements in the view.null_count: cachedOption<usize>of nulls for this range.
§Notes
TextArrayVis not thread-safe due to its use ofCellfor caching the null count.- Use
sliceto derive smaller views from this one. - Use
to_text_arrayto materialise the data.
Fields§
§array: TextArray§offset: usizeImplementations§
Source§impl TextArrayV
impl TextArrayV
Sourcepub fn new(array: TextArray, offset: usize, len: usize) -> Self
pub fn new(array: TextArray, offset: usize, len: usize) -> Self
Creates a new TextArrayView with the given offset and length.
Examples found in repository?
examples/print_arrays.rs (line 119)
20fn main() {
21 // Numeric (Integer, Float, all sizes)
22 let col_i32 = IntArr::<i32>::from_slice(&[1, 2, 3, 4, 5]);
23 let col_u32 = IntArr::<u32>::from_slice(&[100, 200, 300, 400, 500]);
24 let col_f32 = FltArr::<f32>::from_slice(&[1.1, 2.2, 3.3, 4.4, 5.5]);
25
26 // Boolean with nulls
27 let mut col_bool = BoolArr::from_slice(&[true, false, true, false, true]);
28 col_bool.set_null_mask(Some(Bitmask::from_bools(&[true, true, true, false, true])));
29
30 // String and Dictionary/Categorical
31 let col_str32 = StrArr::from_slice(&["red", "blue", "green", "yellow", "purple"]);
32
33 let col_cat32 = CatArr::<u32>::from_values(
34 ["apple", "banana", "cherry", "banana", "apple"]
35 .iter()
36 .copied(),
37 );
38
39 // Datetime
40 #[cfg(feature = "datetime")]
41 let col_dt32 = DatetimeArray::<i32>::from_slice(
42 &[1000, 2000, 3000, 4000, 5000],
43 Some(minarrow::enums::time_units::TimeUnit::Milliseconds),
44 );
45 #[cfg(feature = "datetime")]
46 let col_dt64 = DatetimeArray::<i64>::from_slice(
47 &[
48 1_000_000_000,
49 2_000_000_000,
50 3_000_000_000,
51 4_000_000_000,
52 5_000_000_000,
53 ],
54 Some(minarrow::enums::time_units::TimeUnit::Nanoseconds),
55 );
56
57 #[cfg(feature = "datetime")]
58 col_dt32.print();
59 #[cfg(feature = "datetime")]
60 println!("\n");
61 #[cfg(feature = "datetime")]
62 col_dt64.print();
63 #[cfg(feature = "datetime")]
64 println!("\n");
65
66 // --- Print NumericArray, TextArray, TemporalArray enums
67 println!("\n--- Enums: NumericArray, TextArray, TemporalArray ---");
68 NumericArray::Int32(Arc::new(col_i32.clone())).print();
69 println!("\n");
70 NumericArray::UInt32(Arc::new(col_u32.clone())).print();
71 println!("\n");
72 NumericArray::Float32(Arc::new(col_f32.clone())).print();
73 println!("\n");
74 TextArray::String32(Arc::new(col_str32.clone())).print();
75 println!("\n");
76 let _ = &TextArray::Categorical32(Arc::new(col_cat32.clone())).print();
77
78 println!("\n/ *** To display as dates, enable the optional 'chrono' feature *** /\n");
79
80 #[cfg(feature = "datetime")]
81 let _ = &TemporalArray::Datetime32(Arc::new(col_dt32.clone())).print();
82 println!("\n");
83 #[cfg(feature = "datetime")]
84 let _ = &TemporalArray::Datetime64(Arc::new(col_dt64.clone())).print();
85 println!("\n");
86
87 println!("\n--- Array (top-level) ---");
88 Array::from_int32(col_i32.clone()).print();
89 println!("\n");
90 Array::from_uint32(col_u32.clone()).print();
91 println!("\n");
92 Array::from_float32(col_f32.clone()).print();
93 println!("\n");
94 Array::from_string32(col_str32.clone()).print();
95 println!("\n");
96 Array::from_categorical32(col_cat32.clone()).print();
97 println!("\n");
98 #[cfg(feature = "datetime")]
99 Array::from_datetime_i32(col_dt32.clone()).print();
100 println!("\n");
101 // --- Print Array Views (ArrayV, NumericArrayV, TextArrayV, TemporalArrayV)
102 #[cfg(feature = "views")]
103 println!("\n--- Array Views ---");
104 #[cfg(feature = "views")]
105 ArrayV::new(Array::from_int32(col_i32.clone()), 1, 3).print();
106
107 let num_arr = NumericArray::Int32(Arc::new(col_i32.clone()));
108 num_arr.print();
109
110 #[cfg(feature = "views")]
111 let num_view = NumericArrayV::new(num_arr, 1, 3);
112 #[cfg(feature = "views")]
113 num_view.print();
114
115 let txt_arr = TextArray::String32(Arc::new(col_str32.clone()));
116 txt_arr.print();
117
118 #[cfg(feature = "views")]
119 let txt_view = TextArrayV::new(txt_arr, 1, 3);
120 #[cfg(feature = "views")]
121 txt_view.print();
122
123 #[cfg(all(feature = "datetime", feature = "views"))]
124 {
125 use minarrow::TemporalArrayV;
126
127 let tmp_arr = TemporalArray::Datetime32(Arc::new(col_dt32.clone()));
128 tmp_arr.print();
129 TemporalArrayV::new(tmp_arr, 1, 3).print();
130 }
131
132 // --- Print Bitmask and BitmaskV
133 println!("\n--- Bitmask & BitmaskV ---");
134 let bm = Bitmask::from_bools(&[true, false, true, true, false]);
135 bm.print();
136 #[cfg(feature = "views")]
137 BitmaskV::new(bm.clone(), 1, 3).print();
138}Sourcepub fn with_null_count(
array: TextArray,
offset: usize,
len: usize,
null_count: usize,
) -> Self
pub fn with_null_count( array: TextArray, offset: usize, len: usize, null_count: usize, ) -> Self
Creates a new TextArrayView with a precomputed null count.
Sourcepub fn get_str(&self, i: usize) -> Option<&str>
pub fn get_str(&self, i: usize) -> Option<&str>
Returns the value at logical index i as an Option<&str>.
Sourcepub fn slice(&self, offset: usize, len: usize) -> Self
pub fn slice(&self, offset: usize, len: usize) -> Self
Returns a sliced view into a subrange of this view.
Sourcepub fn as_array(&self) -> Array
pub fn as_array(&self) -> Array
Returns the underlying array as an Array enum value.
Useful to access its inner methods
Sourcepub fn to_text_array(&self) -> TextArray
pub fn to_text_array(&self) -> TextArray
Returns an owned TextArray clone of the window.
Sourcepub fn as_tuple(&self) -> (TextArray, usize, usize)
pub fn as_tuple(&self) -> (TextArray, usize, usize)
Returns the view as a tuple (array, offset, len).
Sourcepub fn null_count(&self) -> usize
pub fn null_count(&self) -> usize
Returns the number of nulls in the view.
Caches it after the first calculation.
Sourcepub fn null_mask_view(&self) -> Option<BitmaskV>
pub fn null_mask_view(&self) -> Option<BitmaskV>
Returns the null mask as a windowed BitmaskView.
Sourcepub fn set_null_count(&self, count: usize)
pub fn set_null_count(&self, count: usize)
Sets the cached null count for the view.
Trait Implementations§
Source§impl Clone for TextArrayV
impl Clone for TextArrayV
Source§fn clone(&self) -> TextArrayV
fn clone(&self) -> TextArrayV
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TextArrayV
impl Debug for TextArrayV
Source§impl Display for TextArrayV
impl Display for TextArrayV
Source§impl From<Array> for TextArrayV
impl From<Array> for TextArrayV
Source§impl From<ArrayV> for TextArrayV
impl From<ArrayV> for TextArrayV
Source§impl From<TextArray> for TextArrayV
impl From<TextArray> for TextArrayV
Source§impl From<TextArrayV> for Value
impl From<TextArrayV> for Value
Source§fn from(v: TextArrayV) -> Self
fn from(v: TextArrayV) -> Self
Converts to this type from the input type.
Source§impl PartialEq for TextArrayV
impl PartialEq for TextArrayV
Source§impl TryFrom<Value> for TextArrayV
impl TryFrom<Value> for TextArrayV
impl StructuralPartialEq for TextArrayV
Auto Trait Implementations§
impl !Freeze for TextArrayV
impl !RefUnwindSafe for TextArrayV
impl Send for TextArrayV
impl !Sync for TextArrayV
impl Unpin for TextArrayV
impl UnwindSafe for TextArrayV
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Key for Twhere
T: Clone,
impl<T> Key for Twhere
T: Clone,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
CompactString. Read moreSource§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.