Enum datafusion::scalar::ScalarValue
source · pub enum ScalarValue {
Show 39 variants
Null,
Boolean(Option<bool>),
Float32(Option<f32>),
Float64(Option<f64>),
Decimal128(Option<i128>, u8, i8),
Int8(Option<i8>),
Int16(Option<i16>),
Int32(Option<i32>),
Int64(Option<i64>),
UInt8(Option<u8>),
UInt16(Option<u16>),
UInt32(Option<u32>),
UInt64(Option<u64>),
Utf8(Option<String>),
LargeUtf8(Option<String>),
Binary(Option<Vec<u8, Global>>),
FixedSizeBinary(i32, Option<Vec<u8, Global>>),
LargeBinary(Option<Vec<u8, Global>>),
Fixedsizelist(Option<Vec<ScalarValue, Global>>, Arc<Field, Global>, i32),
List(Option<Vec<ScalarValue, Global>>, Arc<Field, Global>),
Date32(Option<i32>),
Date64(Option<i64>),
Time32Second(Option<i32>),
Time32Millisecond(Option<i32>),
Time64Microsecond(Option<i64>),
Time64Nanosecond(Option<i64>),
TimestampSecond(Option<i64>, Option<Arc<str, Global>>),
TimestampMillisecond(Option<i64>, Option<Arc<str, Global>>),
TimestampMicrosecond(Option<i64>, Option<Arc<str, Global>>),
TimestampNanosecond(Option<i64>, Option<Arc<str, Global>>),
IntervalYearMonth(Option<i32>),
IntervalDayTime(Option<i64>),
IntervalMonthDayNano(Option<i128>),
DurationSecond(Option<i64>),
DurationMillisecond(Option<i64>),
DurationMicrosecond(Option<i64>),
DurationNanosecond(Option<i64>),
Struct(Option<Vec<ScalarValue, Global>>, Fields),
Dictionary(Box<DataType, Global>, Box<ScalarValue, Global>),
}
Expand description
Variants§
Null
represents DataType::Null
(castable to/from any other type)
Boolean(Option<bool>)
true or false value
Float32(Option<f32>)
32bit float
Float64(Option<f64>)
64bit float
Decimal128(Option<i128>, u8, i8)
128bit decimal, using the i128 to represent the decimal, precision scale
Int8(Option<i8>)
signed 8bit int
Int16(Option<i16>)
signed 16bit int
Int32(Option<i32>)
signed 32bit int
Int64(Option<i64>)
signed 64bit int
UInt8(Option<u8>)
unsigned 8bit int
UInt16(Option<u16>)
unsigned 16bit int
UInt32(Option<u32>)
unsigned 32bit int
UInt64(Option<u64>)
unsigned 64bit int
Utf8(Option<String>)
utf-8 encoded string.
LargeUtf8(Option<String>)
utf-8 encoded string representing a LargeString’s arrow type.
Binary(Option<Vec<u8, Global>>)
binary
FixedSizeBinary(i32, Option<Vec<u8, Global>>)
fixed size binary
LargeBinary(Option<Vec<u8, Global>>)
large binary
Fixedsizelist(Option<Vec<ScalarValue, Global>>, Arc<Field, Global>, i32)
Fixed size list of nested ScalarValue
List(Option<Vec<ScalarValue, Global>>, Arc<Field, Global>)
List of nested ScalarValue
Date32(Option<i32>)
Date stored as a signed 32bit int days since UNIX epoch 1970-01-01
Date64(Option<i64>)
Date stored as a signed 64bit int milliseconds since UNIX epoch 1970-01-01
Time32Second(Option<i32>)
Time stored as a signed 32bit int as seconds since midnight
Time32Millisecond(Option<i32>)
Time stored as a signed 32bit int as milliseconds since midnight
Time64Microsecond(Option<i64>)
Time stored as a signed 64bit int as microseconds since midnight
Time64Nanosecond(Option<i64>)
Time stored as a signed 64bit int as nanoseconds since midnight
TimestampSecond(Option<i64>, Option<Arc<str, Global>>)
Timestamp Second
TimestampMillisecond(Option<i64>, Option<Arc<str, Global>>)
Timestamp Milliseconds
TimestampMicrosecond(Option<i64>, Option<Arc<str, Global>>)
Timestamp Microseconds
TimestampNanosecond(Option<i64>, Option<Arc<str, Global>>)
Timestamp Nanoseconds
IntervalYearMonth(Option<i32>)
Number of elapsed whole months
IntervalDayTime(Option<i64>)
Number of elapsed days and milliseconds (no leap seconds) stored as 2 contiguous 32-bit signed integers
IntervalMonthDayNano(Option<i128>)
A triple of the number of elapsed months, days, and nanoseconds. Months and days are encoded as 32-bit signed integers. Nanoseconds is encoded as a 64-bit signed integer (no leap seconds).
DurationSecond(Option<i64>)
Duration in seconds
DurationMillisecond(Option<i64>)
Duration in milliseconds
DurationMicrosecond(Option<i64>)
Duration in microseconds
DurationNanosecond(Option<i64>)
Duration in nanoseconds
Struct(Option<Vec<ScalarValue, Global>>, Fields)
struct of nested ScalarValue
Dictionary(Box<DataType, Global>, Box<ScalarValue, Global>)
Dictionary type: index type and value
Implementations§
source§impl ScalarValue
impl ScalarValue
sourcepub fn try_new_decimal128(
value: i128,
precision: u8,
scale: i8
) -> Result<ScalarValue, DataFusionError>
pub fn try_new_decimal128( value: i128, precision: u8, scale: i8 ) -> Result<ScalarValue, DataFusionError>
Create a decimal Scalar from value/precision and scale.
sourcepub fn new_utf8(val: impl Into<String>) -> ScalarValue
pub fn new_utf8(val: impl Into<String>) -> ScalarValue
Returns a ScalarValue::Utf8
representing val
sourcepub fn new_interval_ym(years: i32, months: i32) -> ScalarValue
pub fn new_interval_ym(years: i32, months: i32) -> ScalarValue
Returns a ScalarValue::IntervalYearMonth
representing
years
years and months
months
sourcepub fn new_interval_dt(days: i32, millis: i32) -> ScalarValue
pub fn new_interval_dt(days: i32, millis: i32) -> ScalarValue
Returns a ScalarValue::IntervalDayTime
representing
days
days and millis
milliseconds
sourcepub fn new_interval_mdn(months: i32, days: i32, nanos: i64) -> ScalarValue
pub fn new_interval_mdn(months: i32, days: i32, nanos: i64) -> ScalarValue
Returns a ScalarValue::IntervalMonthDayNano
representing
months
months and days
days, and nanos
nanoseconds
sourcepub fn new_list(
scalars: Option<Vec<ScalarValue, Global>>,
child_type: DataType
) -> ScalarValue
pub fn new_list( scalars: Option<Vec<ScalarValue, Global>>, child_type: DataType ) -> ScalarValue
Create a new nullable ScalarValue::List with the specified child_type
sourcepub fn new_zero(datatype: &DataType) -> Result<ScalarValue, DataFusionError>
pub fn new_zero(datatype: &DataType) -> Result<ScalarValue, DataFusionError>
Create a zero value in the given type.
sourcepub fn new_one(datatype: &DataType) -> Result<ScalarValue, DataFusionError>
pub fn new_one(datatype: &DataType) -> Result<ScalarValue, DataFusionError>
Create an one value in the given type.
sourcepub fn new_negative_one(
datatype: &DataType
) -> Result<ScalarValue, DataFusionError>
pub fn new_negative_one( datatype: &DataType ) -> Result<ScalarValue, DataFusionError>
Create a negative one value in the given type.
pub fn new_ten(datatype: &DataType) -> Result<ScalarValue, DataFusionError>
sourcepub fn get_datatype(&self) -> DataType
pub fn get_datatype(&self) -> DataType
Getter for the DataType
of the value
sourcepub fn arithmetic_negate(&self) -> Result<ScalarValue, DataFusionError>
pub fn arithmetic_negate(&self) -> Result<ScalarValue, DataFusionError>
Calculate arithmetic negation for a scalar value
pub fn add<T>(&self, other: T) -> Result<ScalarValue, DataFusionError>where T: Borrow<ScalarValue>,
pub fn add_checked<T>(&self, other: T) -> Result<ScalarValue, DataFusionError>where T: Borrow<ScalarValue>,
pub fn sub<T>(&self, other: T) -> Result<ScalarValue, DataFusionError>where T: Borrow<ScalarValue>,
pub fn sub_checked<T>(&self, other: T) -> Result<ScalarValue, DataFusionError>where T: Borrow<ScalarValue>,
pub fn and<T>(&self, other: T) -> Result<ScalarValue, DataFusionError>where T: Borrow<ScalarValue>,
pub fn or<T>(&self, other: T) -> Result<ScalarValue, DataFusionError>where T: Borrow<ScalarValue>,
pub fn bitand<T>(&self, other: T) -> Result<ScalarValue, DataFusionError>where T: Borrow<ScalarValue>,
pub fn bitor<T>(&self, other: T) -> Result<ScalarValue, DataFusionError>where T: Borrow<ScalarValue>,
pub fn bitxor<T>(&self, other: T) -> Result<ScalarValue, DataFusionError>where T: Borrow<ScalarValue>,
pub fn is_unsigned(&self) -> bool
sourcepub fn distance(&self, other: &ScalarValue) -> Option<usize>
pub fn distance(&self, other: &ScalarValue) -> Option<usize>
Absolute distance between two numeric values (of the same type). This method will return
None if either one of the arguments are null. It might also return None if the resulting
distance is greater than usize::MAX
. If the type is a float, then the distance will be
rounded to the nearest integer.
Note: the datatype itself must support subtraction.
sourcepub fn iter_to_array(
scalars: impl IntoIterator<Item = ScalarValue>
) -> Result<Arc<dyn Array, Global>, DataFusionError>
pub fn iter_to_array( scalars: impl IntoIterator<Item = ScalarValue> ) -> Result<Arc<dyn Array, Global>, DataFusionError>
Converts an iterator of references ScalarValue
into an ArrayRef
corresponding to those values. For example,
Returns an error if the iterator is empty or if the
ScalarValue
s are not all the same type
Example
use datafusion_common::ScalarValue;
use arrow::array::{ArrayRef, BooleanArray};
let scalars = vec![
ScalarValue::Boolean(Some(true)),
ScalarValue::Boolean(None),
ScalarValue::Boolean(Some(false)),
];
// Build an Array from the list of ScalarValues
let array = ScalarValue::iter_to_array(scalars.into_iter())
.unwrap();
let expected: ArrayRef = std::sync::Arc::new(
BooleanArray::from(vec![
Some(true),
None,
Some(false)
]
));
assert_eq!(&array, &expected);
sourcepub fn to_array_of_size(&self, size: usize) -> Arc<dyn Array, Global>
pub fn to_array_of_size(&self, size: usize) -> Arc<dyn Array, Global>
Converts a scalar value into an array of size
rows.
sourcepub fn try_from_array(
array: &dyn Array,
index: usize
) -> Result<ScalarValue, DataFusionError>
pub fn try_from_array( array: &dyn Array, index: usize ) -> Result<ScalarValue, DataFusionError>
Converts a value in array
at index
into a ScalarValue
sourcepub fn try_from_string(
value: String,
target_type: &DataType
) -> Result<ScalarValue, DataFusionError>
pub fn try_from_string( value: String, target_type: &DataType ) -> Result<ScalarValue, DataFusionError>
Try to parse value
into a ScalarValue of type target_type
sourcepub fn eq_array(&self, array: &Arc<dyn Array, Global>, index: usize) -> bool
pub fn eq_array(&self, array: &Arc<dyn Array, Global>, index: usize) -> bool
Compares a single row of array @ index for equality with self, in an optimized fashion.
This method implements an optimized version of:
let arr_scalar = Self::try_from_array(array, index).unwrap();
arr_scalar.eq(self)
Performance note: the arrow compute kernels should be preferred over this function if at all possible as they can be vectorized and are generally much faster.
This function has a few narrow usescases such as hash table key comparisons where comparing a single row at a time is necessary.
sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Estimate size if bytes including Self
. For values with internal containers such as String
includes the allocated size (capacity
) rather than the current length (len
)
sourcepub fn size_of_vec(vec: &Vec<ScalarValue, Global>) -> usize
pub fn size_of_vec(vec: &Vec<ScalarValue, Global>) -> usize
sourcepub fn size_of_hashset<S>(set: &HashSet<ScalarValue, S>) -> usize
pub fn size_of_hashset<S>(set: &HashSet<ScalarValue, S>) -> usize
Trait Implementations§
source§impl Clone for ScalarValue
impl Clone for ScalarValue
source§fn clone(&self) -> ScalarValue
fn clone(&self) -> ScalarValue
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ScalarValue
impl Debug for ScalarValue
source§impl Display for ScalarValue
impl Display for ScalarValue
source§impl<T> From<&HyperLogLog<T>> for ScalarValuewhere
T: Hash,
impl<T> From<&HyperLogLog<T>> for ScalarValuewhere T: Hash,
source§fn from(v: &HyperLogLog<T>) -> ScalarValue
fn from(v: &HyperLogLog<T>) -> ScalarValue
source§impl From<&str> for ScalarValue
impl From<&str> for ScalarValue
source§fn from(value: &str) -> ScalarValue
fn from(value: &str) -> ScalarValue
source§impl From<Vec<(&str, ScalarValue), Global>> for ScalarValue
impl From<Vec<(&str, ScalarValue), Global>> for ScalarValue
source§fn from(value: Vec<(&str, ScalarValue), Global>) -> ScalarValue
fn from(value: Vec<(&str, ScalarValue), Global>) -> ScalarValue
source§impl From<bool> for ScalarValue
impl From<bool> for ScalarValue
source§fn from(value: bool) -> ScalarValue
fn from(value: bool) -> ScalarValue
source§impl From<f32> for ScalarValue
impl From<f32> for ScalarValue
source§fn from(value: f32) -> ScalarValue
fn from(value: f32) -> ScalarValue
source§impl From<f64> for ScalarValue
impl From<f64> for ScalarValue
source§fn from(value: f64) -> ScalarValue
fn from(value: f64) -> ScalarValue
source§impl From<i16> for ScalarValue
impl From<i16> for ScalarValue
source§fn from(value: i16) -> ScalarValue
fn from(value: i16) -> ScalarValue
source§impl From<i32> for ScalarValue
impl From<i32> for ScalarValue
source§fn from(value: i32) -> ScalarValue
fn from(value: i32) -> ScalarValue
source§impl From<i64> for ScalarValue
impl From<i64> for ScalarValue
source§fn from(value: i64) -> ScalarValue
fn from(value: i64) -> ScalarValue
source§impl From<i8> for ScalarValue
impl From<i8> for ScalarValue
source§fn from(value: i8) -> ScalarValue
fn from(value: i8) -> ScalarValue
source§impl From<u16> for ScalarValue
impl From<u16> for ScalarValue
source§fn from(value: u16) -> ScalarValue
fn from(value: u16) -> ScalarValue
source§impl From<u32> for ScalarValue
impl From<u32> for ScalarValue
source§fn from(value: u32) -> ScalarValue
fn from(value: u32) -> ScalarValue
source§impl From<u64> for ScalarValue
impl From<u64> for ScalarValue
source§fn from(value: u64) -> ScalarValue
fn from(value: u64) -> ScalarValue
source§impl From<u8> for ScalarValue
impl From<u8> for ScalarValue
source§fn from(value: u8) -> ScalarValue
fn from(value: u8) -> ScalarValue
source§impl FromStr for ScalarValue
impl FromStr for ScalarValue
§type Err = Infallible
type Err = Infallible
source§fn from_str(s: &str) -> Result<ScalarValue, <ScalarValue as FromStr>::Err>
fn from_str(s: &str) -> Result<ScalarValue, <ScalarValue as FromStr>::Err>
s
to return a value of this type. Read moresource§impl Hash for ScalarValue
impl Hash for ScalarValue
source§impl Literal for ScalarValue
impl Literal for ScalarValue
source§impl PartialEq<ScalarValue> for ScalarValue
impl PartialEq<ScalarValue> for ScalarValue
source§fn eq(&self, other: &ScalarValue) -> bool
fn eq(&self, other: &ScalarValue) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<ScalarValue> for ScalarValue
impl PartialOrd<ScalarValue> for ScalarValue
source§fn partial_cmp(&self, other: &ScalarValue) -> Option<Ordering>
fn partial_cmp(&self, other: &ScalarValue) -> Option<Ordering>
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 moresource§impl TryFrom<&DataType> for ScalarValue
impl TryFrom<&DataType> for ScalarValue
source§fn try_from(datatype: &DataType) -> Result<ScalarValue, DataFusionError>
fn try_from(datatype: &DataType) -> Result<ScalarValue, DataFusionError>
Create a Null instance of ScalarValue for this datatype
§type Error = DataFusionError
type Error = DataFusionError
source§impl TryFrom<DataType> for ScalarValue
impl TryFrom<DataType> for ScalarValue
source§fn try_from(datatype: DataType) -> Result<ScalarValue, DataFusionError>
fn try_from(datatype: DataType) -> Result<ScalarValue, DataFusionError>
Create a Null instance of ScalarValue for this datatype
§type Error = DataFusionError
type Error = DataFusionError
source§impl TryFrom<ScalarValue> for u32
impl TryFrom<ScalarValue> for u32
§type Error = DataFusionError
type Error = DataFusionError
source§fn try_from(value: ScalarValue) -> Result<u32, DataFusionError>
fn try_from(value: ScalarValue) -> Result<u32, DataFusionError>
impl Eq for ScalarValue
Auto Trait Implementations§
impl RefUnwindSafe for ScalarValue
impl Send for ScalarValue
impl Sync for ScalarValue
impl Unpin for ScalarValue
impl UnwindSafe for ScalarValue
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<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.