pub enum Literal {
Primitive(PrimitiveLiteral),
Struct(Struct),
List(Vec<Option<Literal>>),
Map(Map),
}
Expand description
Values present in iceberg type
Variants§
Primitive(PrimitiveLiteral)
A primitive value
Struct(Struct)
A struct is a tuple of typed values. Each field in the tuple is named and has an integer id that is unique in the table schema. Each field can be either optional or required, meaning that values can (or cannot) be null. Fields may be any type. Fields may have an optional comment or doc string. Fields can have default values.
List(Vec<Option<Literal>>)
A list is a collection of values with some element type. The element field has an integer id that is unique in the table schema. Elements can be either optional or required. Element types may be any type.
Map(Map)
A map is a collection of key-value pairs with a key type and a value type. Both the key field and value field each have an integer id that is unique in the table schema. Map keys are required and map values can be either optional or required. Both map keys and map values may be any type, including nested types.
Implementations§
source§impl Literal
impl Literal
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::{Literal, PrimitiveLiteral};
let t = Literal::bool(true);
assert_eq!(Literal::Primitive(PrimitiveLiteral::Boolean(true)), t);
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::{Literal, PrimitiveLiteral};
let t = Literal::bool_from_str("false").unwrap();
assert_eq!(Literal::Primitive(PrimitiveLiteral::Boolean(false)), t);
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::{Literal, PrimitiveLiteral};
let t = Literal::int(23i8);
assert_eq!(Literal::Primitive(PrimitiveLiteral::Int(23)), t);
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::{Literal, PrimitiveLiteral};
let t = Literal::long(24i8);
assert_eq!(Literal::Primitive(PrimitiveLiteral::Long(24)), t);
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::{Literal, PrimitiveLiteral};
use ordered_float::OrderedFloat;
let t = Literal::float(32.1f32);
assert_eq!(
Literal::Primitive(PrimitiveLiteral::Float(OrderedFloat(32.1))),
t
);
sourcepub fn double<T: Into<f64>>(t: T) -> Self
pub fn double<T: Into<f64>>(t: T) -> Self
Creates an 32bit floating point number.
Example:
use iceberg::spec::{Literal, PrimitiveLiteral};
use ordered_float::OrderedFloat;
let t = Literal::double(32.1f64);
assert_eq!(
Literal::Primitive(PrimitiveLiteral::Double(OrderedFloat(32.1))),
t
);
sourcepub fn date(days: i32) -> Self
pub fn date(days: i32) -> Self
Creates date literal from number of days from unix epoch directly.
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 a date in %Y-%m-%d
format, assume in utc timezone.
See NaiveDate::from_str
.
Example
use iceberg::spec::Literal;
let t = Literal::date_from_str("1970-01-03").unwrap();
assert_eq!(Literal::date(2), t);
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 a date from calendar date (year, month and day).
Example:
use iceberg::spec::Literal;
let t = Literal::date_from_ymd(1970, 1, 5).unwrap();
assert_eq!(Literal::date(4), t);
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 in microseconds in %H:%M:%S:.f
format.
See NaiveTime::from_str
for details.
Example:
use iceberg::spec::Literal;
let t = Literal::time_from_str("01:02:01.888999777").unwrap();
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
};
assert_eq!(Literal::time(micro_secs), t);
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::Literal;
let t = Literal::time_from_hms_micro(22, 15, 33, 111).unwrap();
assert_eq!(Literal::time_from_str("22:15:33.000111").unwrap(), t);
sourcepub fn timestamptz(value: i64) -> Self
pub fn timestamptz(value: i64) -> Self
Creates a timestamp with timezone from unix epoch in microseconds.
sourcepub fn timestamp_from_datetime<T: TimeZone>(dt: DateTime<T>) -> Self
pub fn timestamp_from_datetime<T: TimeZone>(dt: DateTime<T>) -> Self
Creates a timestamp from DateTime
.
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
.
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 RFC3339 format.
Example:
use chrono::{DateTime, FixedOffset, NaiveDate, NaiveDateTime, NaiveTime};
use iceberg::spec::Literal;
let t = Literal::timestamp_from_str("2012-12-12 12:12:12.8899-04:00").unwrap();
let t2 = {
let date = NaiveDate::from_ymd_opt(2012, 12, 12).unwrap();
let time = NaiveTime::from_hms_micro_opt(12, 12, 12, 889900).unwrap();
let dt = NaiveDateTime::new(date, time);
Literal::timestamp_from_datetime(DateTime::<FixedOffset>::from_local(
dt,
FixedOffset::west_opt(4 * 3600).unwrap(),
))
};
assert_eq!(t, t2);
sourcepub fn timestamptz_from_str<S: AsRef<str>>(s: S) -> Result<Self>
pub fn timestamptz_from_str<S: AsRef<str>>(s: S) -> Result<Self>
Similar to Literal::timestamp_from_str
, but return timestamp with timezone literal.
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::Literal;
use uuid::Uuid;
let t1 = Literal::uuid_from_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8").unwrap();
let t2 = Literal::uuid(Uuid::from_u128_le(0xd8d7d6d5d4d3d2d1c2c1b2b1a4a3a2a1));
assert_eq!(t1, t2);
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::{Literal, PrimitiveLiteral};
let t1 = Literal::fixed(vec![1u8, 2u8]);
let t2 = Literal::Primitive(PrimitiveLiteral::Binary(vec![1u8, 2u8]));
assert_eq!(t1, t2);
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::{Literal, PrimitiveLiteral};
let t1 = Literal::binary(vec![1u8, 2u8]);
let t2 = Literal::Primitive(PrimitiveLiteral::Binary(vec![1u8, 2u8]));
assert_eq!(t1, t2);
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::Literal;
use rust_decimal::Decimal;
let t1 = Literal::decimal(12345);
let t2 = Literal::decimal_from_str("123.45").unwrap();
assert_eq!(t1, t2);
source§impl Literal
impl Literal
Trait Implementations§
source§impl PartialEq for Literal
impl PartialEq for Literal
impl Eq for Literal
impl StructuralPartialEq for Literal
Auto Trait Implementations§
impl Freeze for Literal
impl RefUnwindSafe for Literal
impl Send for Literal
impl Sync for Literal
impl Unpin for Literal
impl UnwindSafe for Literal
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.