pub struct Datum { /* private fields */ }
Expand description
Literal associated with its type. The value and type pair is checked when construction, so the type and value is guaranteed to be correct when used.
By default, we decouple the type and value of a literal, so we can use avoid the cost of storing extra type info for each literal. But associate type with literal can be useful in some cases, for example, in unbound expression.
Implementations§
source§impl Datum
impl Datum
sourcepub fn try_from_bytes(bytes: &[u8], data_type: PrimitiveType) -> Result<Self>
pub fn try_from_bytes(bytes: &[u8], data_type: PrimitiveType) -> Result<Self>
Create iceberg value from bytes.
See this spec for reference.
sourcepub fn bool<T: Into<bool>>(t: T) -> Self
pub fn bool<T: Into<bool>>(t: T) -> Self
Creates a boolean value.
Example:
use iceberg::spec::{Datum, Literal, PrimitiveLiteral};
let t = Datum::bool(true);
assert_eq!(format!("{}", t), "true".to_string());
assert_eq!(
Literal::from(t),
Literal::Primitive(PrimitiveLiteral::Boolean(true))
);
sourcepub fn bool_from_str<S: AsRef<str>>(s: S) -> Result<Self>
pub fn bool_from_str<S: AsRef<str>>(s: S) -> Result<Self>
Creates a boolean value from string. See Parse bool from str for reference.
Example:
use iceberg::spec::{Datum, Literal, PrimitiveLiteral};
let t = Datum::bool_from_str("false").unwrap();
assert_eq!(&format!("{}", t), "false");
assert_eq!(
Literal::Primitive(PrimitiveLiteral::Boolean(false)),
t.into()
);
sourcepub fn int<T: Into<i32>>(t: T) -> Self
pub fn int<T: Into<i32>>(t: T) -> Self
Creates an 32bit integer.
Example:
use iceberg::spec::{Datum, Literal, PrimitiveLiteral};
let t = Datum::int(23i8);
assert_eq!(&format!("{}", t), "23");
assert_eq!(Literal::Primitive(PrimitiveLiteral::Int(23)), t.into());
sourcepub fn long<T: Into<i64>>(t: T) -> Self
pub fn long<T: Into<i64>>(t: T) -> Self
Creates an 64bit integer.
Example:
use iceberg::spec::{Datum, Literal, PrimitiveLiteral};
let t = Datum::long(24i8);
assert_eq!(&format!("{t}"), "24");
assert_eq!(Literal::Primitive(PrimitiveLiteral::Long(24)), t.into());
sourcepub fn float<T: Into<f32>>(t: T) -> Self
pub fn float<T: Into<f32>>(t: T) -> Self
Creates an 32bit floating point number.
Example:
use iceberg::spec::{Datum, Literal, PrimitiveLiteral};
use ordered_float::OrderedFloat;
let t = Datum::float(32.1f32);
assert_eq!(&format!("{t}"), "32.1");
assert_eq!(
Literal::Primitive(PrimitiveLiteral::Float(OrderedFloat(32.1))),
t.into()
);
sourcepub fn double<T: Into<f64>>(t: T) -> Self
pub fn double<T: Into<f64>>(t: T) -> Self
Creates an 64bit floating point number.
Example:
use iceberg::spec::{Datum, Literal, PrimitiveLiteral};
use ordered_float::OrderedFloat;
let t = Datum::double(32.1f64);
assert_eq!(&format!("{t}"), "32.1");
assert_eq!(
Literal::Primitive(PrimitiveLiteral::Double(OrderedFloat(32.1))),
t.into()
);
sourcepub fn date(days: i32) -> Self
pub fn date(days: i32) -> Self
Creates date literal from number of days from unix epoch directly.
Example:
use iceberg::spec::{Datum, Literal, PrimitiveLiteral};
// 2 days after 1970-01-01
let t = Datum::date(2);
assert_eq!(&format!("{t}"), "1970-01-03");
assert_eq!(Literal::Primitive(PrimitiveLiteral::Int(2)), t.into());
sourcepub fn date_from_str<S: AsRef<str>>(s: S) -> Result<Self>
pub fn date_from_str<S: AsRef<str>>(s: S) -> Result<Self>
Creates date literal in %Y-%m-%d
format, assume in utc timezone.
See NaiveDate::from_str
.
Example
use iceberg::spec::{Datum, Literal};
let t = Datum::date_from_str("1970-01-05").unwrap();
assert_eq!(&format!("{t}"), "1970-01-05");
assert_eq!(Literal::date(4), t.into());
sourcepub fn date_from_ymd(year: i32, month: u32, day: u32) -> Result<Self>
pub fn date_from_ymd(year: i32, month: u32, day: u32) -> Result<Self>
Create date literal from calendar date (year, month and day).
Example:
use iceberg::spec::{Datum, Literal};
let t = Datum::date_from_ymd(1970, 1, 5).unwrap();
assert_eq!(&format!("{t}"), "1970-01-05");
assert_eq!(Literal::date(4), t.into());
sourcepub fn time_micros(value: i64) -> Result<Self>
pub fn time_micros(value: i64) -> Result<Self>
Creates time literal in microseconds directly.
It will return error when it’s negative or too large to fit in 24 hours.
Example:
use iceberg::spec::{Datum, Literal};
let micro_secs = {
1 * 3600 * 1_000_000 + // 1 hour
2 * 60 * 1_000_000 + // 2 minutes
1 * 1_000_000 + // 1 second
888999 // microseconds
};
let t = Datum::time_micros(micro_secs).unwrap();
assert_eq!(&format!("{t}"), "01:02:01.888999");
assert_eq!(Literal::time(micro_secs), t.into());
let negative_value = -100;
assert!(Datum::time_micros(negative_value).is_err());
let too_large_value = 36 * 60 * 60 * 1_000_000; // Too large to fit in 24 hours.
assert!(Datum::time_micros(too_large_value).is_err());
sourcepub fn time_from_str<S: AsRef<str>>(s: S) -> Result<Self>
pub fn time_from_str<S: AsRef<str>>(s: S) -> Result<Self>
Creates time literal in microseconds in %H:%M:%S:.f
format.
See NaiveTime::from_str
for details.
Example:
use iceberg::spec::{Datum, Literal};
let t = Datum::time_from_str("01:02:01.888999777").unwrap();
assert_eq!(&format!("{t}"), "01:02:01.888999");
sourcepub fn time_from_hms_micro(
hour: u32,
min: u32,
sec: u32,
micro: u32,
) -> Result<Self>
pub fn time_from_hms_micro( hour: u32, min: u32, sec: u32, micro: u32, ) -> Result<Self>
Creates time literal from hour, minute, second, and microseconds.
See NaiveTime::from_hms_micro_opt
.
Example:
use iceberg::spec::{Datum, Literal};
let t = Datum::time_from_hms_micro(22, 15, 33, 111).unwrap();
assert_eq!(&format!("{t}"), "22:15:33.000111");
sourcepub fn timestamp_micros(value: i64) -> Self
pub fn timestamp_micros(value: i64) -> Self
Creates a timestamp from unix epoch in microseconds.
Example:
use iceberg::spec::Datum;
let t = Datum::timestamp_micros(1000);
assert_eq!(&format!("{t}"), "1970-01-01 00:00:00.001");
sourcepub fn timestamp_nanos(value: i64) -> Self
pub fn timestamp_nanos(value: i64) -> Self
Creates a timestamp from unix epoch in nanoseconds.
Example:
use iceberg::spec::Datum;
let t = Datum::timestamp_nanos(1000);
assert_eq!(&format!("{t}"), "1970-01-01 00:00:00.000001");
sourcepub fn timestamp_from_datetime(dt: NaiveDateTime) -> Self
pub fn timestamp_from_datetime(dt: NaiveDateTime) -> Self
Creates a timestamp from DateTime
.
Example:
use chrono::{NaiveDate, NaiveDateTime, TimeZone, Utc};
use iceberg::spec::Datum;
let t = Datum::timestamp_from_datetime(
NaiveDate::from_ymd_opt(1992, 3, 1)
.unwrap()
.and_hms_micro_opt(1, 2, 3, 88)
.unwrap(),
);
assert_eq!(&format!("{t}"), "1992-03-01 01:02:03.000088");
sourcepub fn timestamp_from_str<S: AsRef<str>>(s: S) -> Result<Self>
pub fn timestamp_from_str<S: AsRef<str>>(s: S) -> Result<Self>
Parse a timestamp in [%Y-%m-%dT%H:%M:%S%.f
] format.
Example:
use chrono::{DateTime, FixedOffset, NaiveDate, NaiveDateTime, NaiveTime};
use iceberg::spec::{Datum, Literal};
let t = Datum::timestamp_from_str("1992-03-01T01:02:03.000088").unwrap();
assert_eq!(&format!("{t}"), "1992-03-01 01:02:03.000088");
sourcepub fn timestamptz_micros(value: i64) -> Self
pub fn timestamptz_micros(value: i64) -> Self
Creates a timestamp with timezone from unix epoch in microseconds.
Example:
use iceberg::spec::Datum;
let t = Datum::timestamptz_micros(1000);
assert_eq!(&format!("{t}"), "1970-01-01 00:00:00.001 UTC");
sourcepub fn timestamptz_nanos(value: i64) -> Self
pub fn timestamptz_nanos(value: i64) -> Self
Creates a timestamp with timezone from unix epoch in nanoseconds.
Example:
use iceberg::spec::Datum;
let t = Datum::timestamptz_nanos(1000);
assert_eq!(&format!("{t}"), "1970-01-01 00:00:00.000001 UTC");
sourcepub fn timestamptz_from_datetime<T: TimeZone>(dt: DateTime<T>) -> Self
pub fn timestamptz_from_datetime<T: TimeZone>(dt: DateTime<T>) -> Self
Creates a timestamp with timezone from DateTime
.
Example:
use chrono::{TimeZone, Utc};
use iceberg::spec::Datum;
let t = Datum::timestamptz_from_datetime(Utc.timestamp_opt(1000, 0).unwrap());
assert_eq!(&format!("{t}"), "1970-01-01 00:16:40 UTC");
sourcepub fn timestamptz_from_str<S: AsRef<str>>(s: S) -> Result<Self>
pub fn timestamptz_from_str<S: AsRef<str>>(s: S) -> Result<Self>
Parse timestamp with timezone in RFC3339 format.
See DateTime::from_str
.
Example:
use chrono::{DateTime, FixedOffset, NaiveDate, NaiveDateTime, NaiveTime};
use iceberg::spec::{Datum, Literal};
let t = Datum::timestamptz_from_str("1992-03-01T01:02:03.000088+08:00").unwrap();
assert_eq!(&format!("{t}"), "1992-02-29 17:02:03.000088 UTC");
sourcepub fn string<S: ToString>(s: S) -> Self
pub fn string<S: ToString>(s: S) -> Self
Creates a string literal.
Example:
use iceberg::spec::Datum;
let t = Datum::string("ss");
assert_eq!(&format!("{t}"), r#""ss""#);
sourcepub fn uuid(uuid: Uuid) -> Self
pub fn uuid(uuid: Uuid) -> Self
Creates uuid literal.
Example:
use iceberg::spec::Datum;
use uuid::uuid;
let t = Datum::uuid(uuid!("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8"));
assert_eq!(&format!("{t}"), "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8");
sourcepub fn uuid_from_str<S: AsRef<str>>(s: S) -> Result<Self>
pub fn uuid_from_str<S: AsRef<str>>(s: S) -> Result<Self>
Creates uuid from str. See Uuid::parse_str
.
Example:
use iceberg::spec::Datum;
let t = Datum::uuid_from_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8").unwrap();
assert_eq!(&format!("{t}"), "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8");
sourcepub fn fixed<I: IntoIterator<Item = u8>>(input: I) -> Self
pub fn fixed<I: IntoIterator<Item = u8>>(input: I) -> Self
Creates a fixed literal from bytes.
Example:
use iceberg::spec::{Datum, Literal, PrimitiveLiteral};
let t = Datum::fixed(vec![1u8, 2u8]);
assert_eq!(&format!("{t}"), "0102");
sourcepub fn binary<I: IntoIterator<Item = u8>>(input: I) -> Self
pub fn binary<I: IntoIterator<Item = u8>>(input: I) -> Self
Creates a binary literal from bytes.
Example:
use iceberg::spec::Datum;
let t = Datum::binary(vec![1u8, 100u8]);
assert_eq!(&format!("{t}"), "0164");
sourcepub fn decimal_from_str<S: AsRef<str>>(s: S) -> Result<Self>
pub fn decimal_from_str<S: AsRef<str>>(s: S) -> Result<Self>
Creates decimal literal from string. See [Decimal::from_str_exact
].
Example:
use iceberg::spec::Datum;
use itertools::assert_equal;
use rust_decimal::Decimal;
let t = Datum::decimal_from_str("123.45").unwrap();
assert_eq!(&format!("{t}"), "123.45");
sourcepub fn decimal(value: impl Into<Decimal>) -> Result<Self>
pub fn decimal(value: impl Into<Decimal>) -> Result<Self>
Try to create a decimal literal from [Decimal
].
Example:
use iceberg::spec::Datum;
use rust_decimal::Decimal;
let t = Datum::decimal(Decimal::new(123, 2)).unwrap();
assert_eq!(&format!("{t}"), "1.23");
sourcepub fn literal(&self) -> &PrimitiveLiteral
pub fn literal(&self) -> &PrimitiveLiteral
Get the primitive literal from datum.
sourcepub fn data_type(&self) -> &PrimitiveType
pub fn data_type(&self) -> &PrimitiveType
Get the primitive type from datum.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Datum
impl<'de> Deserialize<'de> for Datum
source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
source§impl From<Datum> for PrimitiveLiteral
impl From<Datum> for PrimitiveLiteral
source§impl PartialEq for Datum
impl PartialEq for Datum
source§impl PartialOrd for Datum
impl PartialOrd for Datum
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for Datum
impl StructuralPartialEq for Datum
Auto Trait Implementations§
impl Freeze for Datum
impl RefUnwindSafe for Datum
impl Send for Datum
impl Sync for Datum
impl Unpin for Datum
impl UnwindSafe for Datum
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
§impl<T> Conv for T
impl<T> Conv for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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> ⓘ
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> ⓘ
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 more§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.