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