MCPcopy Create free account
hub / github.com/apache/paimon-rust / get_datum

Method get_datum

crates/paimon/src/spec/binary_row.rs:293–344  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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 ///

Callers 1

format_fieldFunction · 0.80

Calls 15

DateTypeAlias · 0.85
TimeTypeAlias · 0.85
BytesTypeAlias · 0.85
is_null_atMethod · 0.80
get_booleanMethod · 0.80
get_byteMethod · 0.80
get_shortMethod · 0.80
get_intMethod · 0.80
get_longMethod · 0.80
get_floatMethod · 0.80
get_doubleMethod · 0.80
get_stringMethod · 0.80

Tested by

no test coverage detected