reifydb_core/value/column/
row.rs1use reifydb_type::value::{
9 Value,
10 blob::Blob,
11 date::Date,
12 datetime::DateTime,
13 decimal::Decimal,
14 duration::Duration,
15 identity::IdentityId,
16 int::Int,
17 ordered_f64::OrderedF64,
18 row_number::RowNumber,
19 time::Time,
20 uint::Uint,
21 uuid::{Uuid4, Uuid7},
22};
23
24use crate::value::column::columns::Columns;
25
26impl Columns {
27 pub fn get_bool(&self, name: &str, row_idx: usize) -> Option<bool> {
29 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
30 Value::Boolean(v) => Some(v),
31 _ => None,
32 })
33 }
34
35 pub fn get_f32(&self, name: &str, row_idx: usize) -> Option<f32> {
37 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
38 Value::Float4(v) => Some(v.into()),
39 _ => None,
40 })
41 }
42
43 pub fn get_f64(&self, name: &str, row_idx: usize) -> Option<f64> {
45 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
46 Value::Float8(v) => Some(v.into()),
47 Value::Float4(v) => Some(f64::from(f32::from(v))),
48 _ => None,
49 })
50 }
51
52 pub fn get_float8(&self, name: &str, row_idx: usize) -> Option<OrderedF64> {
54 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
55 Value::Float8(v) => Some(v),
56 _ => None,
57 })
58 }
59
60 pub fn get_i8(&self, name: &str, row_idx: usize) -> Option<i8> {
62 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
63 Value::Int1(v) => Some(v),
64 _ => None,
65 })
66 }
67
68 pub fn get_i16(&self, name: &str, row_idx: usize) -> Option<i16> {
70 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
71 Value::Int2(v) => Some(v),
72 Value::Int1(v) => Some(v as i16),
73 _ => None,
74 })
75 }
76
77 pub fn get_i32(&self, name: &str, row_idx: usize) -> Option<i32> {
79 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
80 Value::Int4(v) => Some(v),
81 Value::Int2(v) => Some(v as i32),
82 Value::Int1(v) => Some(v as i32),
83 _ => None,
84 })
85 }
86
87 pub fn get_i64(&self, name: &str, row_idx: usize) -> Option<i64> {
89 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
90 Value::Int8(v) => Some(v),
91 Value::Int4(v) => Some(v as i64),
92 Value::Int2(v) => Some(v as i64),
93 Value::Int1(v) => Some(v as i64),
94 _ => None,
95 })
96 }
97
98 pub fn get_i128(&self, name: &str, row_idx: usize) -> Option<i128> {
100 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
101 Value::Int16(v) => Some(v),
102 Value::Int8(v) => Some(v as i128),
103 Value::Int4(v) => Some(v as i128),
104 Value::Int2(v) => Some(v as i128),
105 Value::Int1(v) => Some(v as i128),
106 _ => None,
107 })
108 }
109
110 pub fn get_u8(&self, name: &str, row_idx: usize) -> Option<u8> {
112 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
113 Value::Uint1(v) => Some(v),
114 _ => None,
115 })
116 }
117
118 pub fn get_u16(&self, name: &str, row_idx: usize) -> Option<u16> {
120 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
121 Value::Uint2(v) => Some(v),
122 Value::Uint1(v) => Some(v as u16),
123 _ => None,
124 })
125 }
126
127 pub fn get_u32(&self, name: &str, row_idx: usize) -> Option<u32> {
129 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
130 Value::Uint4(v) => Some(v),
131 Value::Uint2(v) => Some(v as u32),
132 Value::Uint1(v) => Some(v as u32),
133 _ => None,
134 })
135 }
136
137 pub fn get_u64(&self, name: &str, row_idx: usize) -> Option<u64> {
139 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
140 Value::Uint8(v) => Some(v),
141 Value::Uint4(v) => Some(v as u64),
142 Value::Uint2(v) => Some(v as u64),
143 Value::Uint1(v) => Some(v as u64),
144 _ => None,
145 })
146 }
147
148 pub fn get_u128(&self, name: &str, row_idx: usize) -> Option<u128> {
150 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
151 Value::Uint16(v) => Some(v),
152 Value::Uint8(v) => Some(v as u128),
153 Value::Uint4(v) => Some(v as u128),
154 Value::Uint2(v) => Some(v as u128),
155 Value::Uint1(v) => Some(v as u128),
156 _ => None,
157 })
158 }
159
160 pub fn get_string(&self, name: &str, row_idx: usize) -> Option<String> {
162 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
163 Value::Utf8(s) => Some(s),
164 _ => None,
165 })
166 }
167
168 pub fn get_date(&self, name: &str, row_idx: usize) -> Option<Date> {
170 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
171 Value::Date(v) => Some(v),
172 _ => None,
173 })
174 }
175
176 pub fn get_datetime(&self, name: &str, row_idx: usize) -> Option<DateTime> {
178 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
179 Value::DateTime(v) => Some(v),
180 _ => None,
181 })
182 }
183
184 pub fn get_time(&self, name: &str, row_idx: usize) -> Option<Time> {
186 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
187 Value::Time(v) => Some(v),
188 _ => None,
189 })
190 }
191
192 pub fn get_duration(&self, name: &str, row_idx: usize) -> Option<Duration> {
194 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
195 Value::Duration(v) => Some(v),
196 _ => None,
197 })
198 }
199
200 pub fn get_identity_id(&self, name: &str, row_idx: usize) -> Option<IdentityId> {
202 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
203 Value::IdentityId(v) => Some(v),
204 _ => None,
205 })
206 }
207
208 pub fn get_uuid4(&self, name: &str, row_idx: usize) -> Option<Uuid4> {
210 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
211 Value::Uuid4(v) => Some(v),
212 _ => None,
213 })
214 }
215
216 pub fn get_uuid7(&self, name: &str, row_idx: usize) -> Option<Uuid7> {
218 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
219 Value::Uuid7(v) => Some(v),
220 _ => None,
221 })
222 }
223
224 pub fn get_blob(&self, name: &str, row_idx: usize) -> Option<Blob> {
226 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
227 Value::Blob(v) => Some(v),
228 _ => None,
229 })
230 }
231
232 pub fn get_int(&self, name: &str, row_idx: usize) -> Option<Int> {
234 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
235 Value::Int(v) => Some(v),
236 _ => None,
237 })
238 }
239
240 pub fn get_uint(&self, name: &str, row_idx: usize) -> Option<Uint> {
242 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
243 Value::Uint(v) => Some(v),
244 _ => None,
245 })
246 }
247
248 pub fn get_decimal(&self, name: &str, row_idx: usize) -> Option<Decimal> {
250 self.column(name).and_then(|col| match col.data().get_value(row_idx) {
251 Value::Decimal(v) => Some(v),
252 _ => None,
253 })
254 }
255
256 pub fn get_value(&self, name: &str, row_idx: usize) -> Option<Value> {
258 self.column(name).map(|col| col.data().get_value(row_idx))
259 }
260
261 pub fn is_undefined(&self, name: &str, row_idx: usize) -> bool {
263 self.column(name).map(|col| matches!(col.data().get_value(row_idx), Value::None { .. })).unwrap_or(true)
264 }
265
266 pub fn get_row_number(&self, row_idx: usize) -> Option<RowNumber> {
268 self.row_numbers.get(row_idx).copied()
269 }
270}