Read a Datum from the given position based on the DataType. Returns `None` if the field is null.
(
&self,
pos: usize,
data_type: &crate::spec::DataType,
)
| 291 | /// Read a Datum from the given position based on the DataType. |
| 292 | /// Returns `None` if the field is null. |
| 293 | pub fn get_datum( |
| 294 | &self, |
| 295 | pos: usize, |
| 296 | data_type: &crate::spec::DataType, |
| 297 | ) -> crate::Result<Option<crate::spec::Datum>> { |
| 298 | if self.is_null_at(pos) { |
| 299 | return Ok(None); |
| 300 | } |
| 301 | use crate::spec::{DataType, Datum}; |
| 302 | let datum = match data_type { |
| 303 | DataType::Boolean(_) => Datum::Bool(self.get_boolean(pos)?), |
| 304 | DataType::TinyInt(_) => Datum::TinyInt(self.get_byte(pos)?), |
| 305 | DataType::SmallInt(_) => Datum::SmallInt(self.get_short(pos)?), |
| 306 | DataType::Int(_) => Datum::Int(self.get_int(pos)?), |
| 307 | DataType::BigInt(_) => Datum::Long(self.get_long(pos)?), |
| 308 | DataType::Float(_) => Datum::Float(self.get_float(pos)?), |
| 309 | DataType::Double(_) => Datum::Double(self.get_double(pos)?), |
| 310 | DataType::Date(_) => Datum::Date(self.get_int(pos)?), |
| 311 | DataType::Time(_) => Datum::Time(self.get_int(pos)?), |
| 312 | DataType::VarChar(_) | DataType::Char(_) => { |
| 313 | Datum::String(self.get_string(pos)?.to_string()) |
| 314 | } |
| 315 | DataType::Binary(_) | DataType::VarBinary(_) => { |
| 316 | Datum::Bytes(self.get_binary(pos)?.to_vec()) |
| 317 | } |
| 318 | DataType::Decimal(dt) => { |
| 319 | let unscaled = self.get_decimal_unscaled(pos, dt.precision())?; |
| 320 | Datum::Decimal { |
| 321 | unscaled, |
| 322 | precision: dt.precision(), |
| 323 | scale: dt.scale(), |
| 324 | } |
| 325 | } |
| 326 | DataType::Timestamp(ts) => { |
| 327 | let (millis, nanos) = self.get_timestamp_raw(pos, ts.precision())?; |
| 328 | Datum::Timestamp { millis, nanos } |
| 329 | } |
| 330 | DataType::LocalZonedTimestamp(ts) => { |
| 331 | let (millis, nanos) = self.get_timestamp_raw(pos, ts.precision())?; |
| 332 | Datum::LocalZonedTimestamp { millis, nanos } |
| 333 | } |
| 334 | _ => { |
| 335 | return Err(crate::Error::Unsupported { |
| 336 | message: format!( |
| 337 | "BinaryRow::get_datum: unsupported data type {:?} at pos {pos}", |
| 338 | data_type |
| 339 | ), |
| 340 | }); |
| 341 | } |
| 342 | }; |
| 343 | Ok(Some(datum)) |
| 344 | } |
| 345 | |
| 346 | /// Build a BinaryRow from selected columns of an Arrow RecordBatch at a given row. |
| 347 | /// |
no test coverage detected