pub enum Variant<'m, 'v> {
Show 20 variants
Null,
Int8(i8),
Int16(i16),
Int32(i32),
Int64(i64),
Date(NaiveDate),
TimestampMicros(DateTime<Utc>),
TimestampNtzMicros(NaiveDateTime),
Decimal4 {
integer: i32,
scale: u8,
},
Decimal8 {
integer: i64,
scale: u8,
},
Decimal16 {
integer: i128,
scale: u8,
},
Float(f32),
Double(f64),
BooleanTrue,
BooleanFalse,
Binary(&'v [u8]),
String(&'v str),
ShortString(&'v str),
Object(VariantObject<'m, 'v>),
Array(VariantArray<'m, 'v>),
}
Expand description
Variant value. May contain references to metadata and value
Variants§
Null
Int8(i8)
Int16(i16)
Int32(i32)
Int64(i64)
Date(NaiveDate)
TimestampMicros(DateTime<Utc>)
TimestampNtzMicros(NaiveDateTime)
Decimal4
Decimal8
Decimal16
Float(f32)
Double(f64)
BooleanTrue
BooleanFalse
Binary(&'v [u8])
String(&'v str)
ShortString(&'v str)
Object(VariantObject<'m, 'v>)
Array(VariantArray<'m, 'v>)
Implementations§
Source§impl<'m, 'v> Variant<'m, 'v>
impl<'m, 'v> Variant<'m, 'v>
Sourcepub fn try_new(
metadata: &'m VariantMetadata<'_>,
value: &'v [u8],
) -> Result<Self, ArrowError>
pub fn try_new( metadata: &'m VariantMetadata<'_>, value: &'v [u8], ) -> Result<Self, ArrowError>
Parse the buffers and return the appropriate variant.
Sourcepub fn as_null(&self) -> Option<()>
pub fn as_null(&self) -> Option<()>
Converts this variant to ()
if it is null.
Returns Some(())
for null variants,
None
for non-null variants.
§Examples
use parquet_variant::Variant;
// you can extract `()` from a null variant
let v1 = Variant::from(());
assert_eq!(v1.as_null(), Some(()));
// but not from other variants
let v2 = Variant::from("hello!");
assert_eq!(v2.as_null(), None);
Sourcepub fn as_boolean(&self) -> Option<bool>
pub fn as_boolean(&self) -> Option<bool>
Converts this variant to a bool
if possible.
Returns Some(bool)
for boolean variants,
None
for non-boolean variants.
§Examples
use parquet_variant::Variant;
// you can extract a bool from the true variant
let v1 = Variant::from(true);
assert_eq!(v1.as_boolean(), Some(true));
// and the false variant
let v2 = Variant::from(false);
assert_eq!(v2.as_boolean(), Some(false));
// but not from other variants
let v3 = Variant::from("hello!");
assert_eq!(v3.as_boolean(), None);
Sourcepub fn as_naive_date(&self) -> Option<NaiveDate>
pub fn as_naive_date(&self) -> Option<NaiveDate>
Converts this variant to a NaiveDate
if possible.
Returns Some(NaiveDate)
for date variants,
None
for non-date variants.
§Examples
use parquet_variant::Variant;
use chrono::NaiveDate;
// you can extract a NaiveDate from a date variant
let date = NaiveDate::from_ymd_opt(2025, 4, 12).unwrap();
let v1 = Variant::from(date);
assert_eq!(v1.as_naive_date(), Some(date));
// but not from other variants
let v2 = Variant::from("hello!");
assert_eq!(v2.as_naive_date(), None);
Sourcepub fn as_datetime_utc(&self) -> Option<DateTime<Utc>>
pub fn as_datetime_utc(&self) -> Option<DateTime<Utc>>
Converts this variant to a DateTime<Utc>
if possible.
Returns Some(DateTime<Utc>)
for timestamp variants,
None
for non-timestamp variants.
§Examples
use parquet_variant::Variant;
use chrono::NaiveDate;
// you can extract a DateTime<Utc> from a UTC-adjusted variant
let datetime = NaiveDate::from_ymd_opt(2025, 4, 16).unwrap().and_hms_milli_opt(12, 34, 56, 780).unwrap().and_utc();
let v1 = Variant::from(datetime);
assert_eq!(v1.as_datetime_utc(), Some(datetime));
// or a non-UTC-adjusted variant
let datetime = NaiveDate::from_ymd_opt(2025, 4, 16).unwrap().and_hms_milli_opt(12, 34, 56, 780).unwrap();
let v2 = Variant::from(datetime);
assert_eq!(v2.as_datetime_utc(), Some(datetime.and_utc()));
// but not from other variants
let v3 = Variant::from("hello!");
assert_eq!(v3.as_datetime_utc(), None);
Sourcepub fn as_naive_datetime(&self) -> Option<NaiveDateTime>
pub fn as_naive_datetime(&self) -> Option<NaiveDateTime>
Converts this variant to a NaiveDateTime
if possible.
Returns Some(NaiveDateTime)
for timestamp variants,
None
for non-timestamp variants.
§Examples
use parquet_variant::Variant;
use chrono::NaiveDate;
// you can extract a NaiveDateTime from a non-UTC-adjusted variant
let datetime = NaiveDate::from_ymd_opt(2025, 4, 16).unwrap().and_hms_milli_opt(12, 34, 56, 780).unwrap();
let v1 = Variant::from(datetime);
assert_eq!(v1.as_naive_datetime(), Some(datetime));
// or a UTC-adjusted variant
let datetime = NaiveDate::from_ymd_opt(2025, 4, 16).unwrap().and_hms_milli_opt(12, 34, 56, 780).unwrap().and_utc();
let v2 = Variant::from(datetime);
assert_eq!(v2.as_naive_datetime(), Some(datetime.naive_utc()));
// but not from other variants
let v3 = Variant::from("hello!");
assert_eq!(v3.as_naive_datetime(), None);
Sourcepub fn as_u8_slice(&'v self) -> Option<&'v [u8]>
pub fn as_u8_slice(&'v self) -> Option<&'v [u8]>
Converts this variant to a &[u8]
if possible.
Returns Some(&[u8])
for binary variants,
None
for non-binary variants.
§Examples
use parquet_variant::Variant;
// you can extract a byte slice from a binary variant
let data = b"hello!";
let v1 = Variant::Binary(data);
assert_eq!(v1.as_u8_slice(), Some(data.as_slice()));
// but not from other variant types
let v2 = Variant::from(123i64);
assert_eq!(v2.as_u8_slice(), None);
Sourcepub fn as_string(&'v self) -> Option<&'v str>
pub fn as_string(&'v self) -> Option<&'v str>
Converts this variant to a &str
if possible.
Returns Some(&str)
for string variants (both regular and short strings),
None
for non-string variants.
§Examples
use parquet_variant::Variant;
// you can extract a string from string variants
let s = "hello!";
let v1 = Variant::ShortString(s);
assert_eq!(v1.as_string(), Some(s));
// but not from other variants
let v2 = Variant::from(123i64);
assert_eq!(v2.as_string(), None);
Sourcepub fn as_int8(&self) -> Option<i8>
pub fn as_int8(&self) -> Option<i8>
Converts this variant to an i8
if possible.
Returns Some(i8)
for integer variants that fit in i8
range,
None
for non-integer variants or values that would overflow.
§Examples
use parquet_variant::Variant;
// you can read an int64 variant into an i8 if it fits
let v1 = Variant::from(123i64);
assert_eq!(v1.as_int8(), Some(123i8));
// but not if it would overflow
let v2 = Variant::from(1234i64);
assert_eq!(v2.as_int8(), None);
// or if the variant cannot be cast into an integer
let v3 = Variant::from("hello!");
assert_eq!(v3.as_int8(), None);
Sourcepub fn as_int16(&self) -> Option<i16>
pub fn as_int16(&self) -> Option<i16>
Converts this variant to an i16
if possible.
Returns Some(i16)
for integer variants that fit in i16
range,
None
for non-integer variants or values that would overflow.
§Examples
use parquet_variant::Variant;
// you can read an int64 variant into an i16 if it fits
let v1 = Variant::from(123i64);
assert_eq!(v1.as_int16(), Some(123i16));
// but not if it would overflow
let v2 = Variant::from(123456i64);
assert_eq!(v2.as_int16(), None);
// or if the variant cannot be cast into an integer
let v3 = Variant::from("hello!");
assert_eq!(v3.as_int16(), None);
Sourcepub fn as_int32(&self) -> Option<i32>
pub fn as_int32(&self) -> Option<i32>
Converts this variant to an i32
if possible.
Returns Some(i32)
for integer variants that fit in i32
range,
None
for non-integer variants or values that would overflow.
§Examples
use parquet_variant::Variant;
// you can read an int64 variant into an i32 if it fits
let v1 = Variant::from(123i64);
assert_eq!(v1.as_int32(), Some(123i32));
// but not if it would overflow
let v2 = Variant::from(12345678901i64);
assert_eq!(v2.as_int32(), None);
// or if the variant cannot be cast into an integer
let v3 = Variant::from("hello!");
assert_eq!(v3.as_int32(), None);
Sourcepub fn as_int64(&self) -> Option<i64>
pub fn as_int64(&self) -> Option<i64>
Converts this variant to an i64
if possible.
Returns Some(i64)
for integer variants that fit in i64
range,
None
for non-integer variants or values that would overflow.
§Examples
use parquet_variant::Variant;
// you can read an int64 variant into an i64
let v1 = Variant::from(123i64);
assert_eq!(v1.as_int64(), Some(123i64));
// but not a variant that cannot be cast into an integer
let v2 = Variant::from("hello!");
assert_eq!(v2.as_int64(), None);
Sourcepub fn as_decimal_int32(&self) -> Option<(i32, u8)>
pub fn as_decimal_int32(&self) -> Option<(i32, u8)>
Converts this variant to tuple with a 4-byte unscaled value if possible.
Returns Some((i32, u8))
for decimal variants where the unscaled value
fits in i32
range,
None
for non-decimal variants or decimal values that would overflow.
§Examples
use parquet_variant::Variant;
// you can extract decimal parts from smaller or equally-sized decimal variants
let v1 = Variant::from((1234_i32, 2));
assert_eq!(v1.as_decimal_int32(), Some((1234_i32, 2)));
// and from larger decimal variants if they fit
let v2 = Variant::from((1234_i64, 2));
assert_eq!(v2.as_decimal_int32(), Some((1234_i32, 2)));
// but not if the value would overflow i32
let v3 = Variant::from((12345678901i64, 2));
assert_eq!(v3.as_decimal_int32(), None);
// or if the variant is not a decimal
let v4 = Variant::from("hello!");
assert_eq!(v4.as_decimal_int32(), None);
Sourcepub fn as_decimal_int64(&self) -> Option<(i64, u8)>
pub fn as_decimal_int64(&self) -> Option<(i64, u8)>
Converts this variant to tuple with an 8-byte unscaled value if possible.
Returns Some((i64, u8))
for decimal variants where the unscaled value
fits in i64
range,
None
for non-decimal variants or decimal values that would overflow.
§Examples
use parquet_variant::Variant;
// you can extract decimal parts from smaller or equally-sized decimal variants
let v1 = Variant::from((1234_i64, 2));
assert_eq!(v1.as_decimal_int64(), Some((1234_i64, 2)));
// and from larger decimal variants if they fit
let v2 = Variant::from((1234_i128, 2));
assert_eq!(v2.as_decimal_int64(), Some((1234_i64, 2)));
// but not if the value would overflow i64
let v3 = Variant::from((2e19 as i128, 2));
assert_eq!(v3.as_decimal_int64(), None);
// or if the variant is not a decimal
let v4 = Variant::from("hello!");
assert_eq!(v4.as_decimal_int64(), None);
Sourcepub fn as_decimal_int128(&self) -> Option<(i128, u8)>
pub fn as_decimal_int128(&self) -> Option<(i128, u8)>
Converts this variant to tuple with a 16-byte unscaled value if possible.
Returns Some((i128, u8))
for decimal variants where the unscaled value
fits in i128
range,
None
for non-decimal variants or decimal values that would overflow.
§Examples
use parquet_variant::Variant;
// you can extract decimal parts from smaller or equally-sized decimal variants
let v1 = Variant::from((1234_i128, 2));
assert_eq!(v1.as_decimal_int128(), Some((1234_i128, 2)));
// but not if the variant is not a decimal
let v2 = Variant::from("hello!");
assert_eq!(v2.as_decimal_int128(), None);
Sourcepub fn as_f32(&self) -> Option<f32>
pub fn as_f32(&self) -> Option<f32>
Converts this variant to an f32
if possible.
Returns Some(f32)
for float and double variants,
None
for non-floating-point variants.
§Examples
use parquet_variant::Variant;
// you can extract an f32 from a float variant
let v1 = Variant::from(std::f32::consts::PI);
assert_eq!(v1.as_f32(), Some(std::f32::consts::PI));
// and from a double variant (with loss of precision to nearest f32)
let v2 = Variant::from(std::f64::consts::PI);
assert_eq!(v2.as_f32(), Some(std::f32::consts::PI));
// but not from other variants
let v3 = Variant::from("hello!");
assert_eq!(v3.as_f32(), None);
Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Converts this variant to an f64
if possible.
Returns Some(f64)
for float and double variants,
None
for non-floating-point variants.
§Examples
use parquet_variant::Variant;
// you can extract an f64 from a float variant
let v1 = Variant::from(std::f32::consts::PI);
assert_eq!(v1.as_f64(), Some(std::f32::consts::PI as f64));
// and from a double variant
let v2 = Variant::from(std::f64::consts::PI);
assert_eq!(v2.as_f64(), Some(std::f64::consts::PI));
// but not from other variants
let v3 = Variant::from("hello!");
assert_eq!(v3.as_f64(), None);