Enum datafusion::scalar::ScalarValue
source · [−]pub enum ScalarValue {
Show 27 variants
Boolean(Option<bool>),
Float32(Option<f32>),
Float64(Option<f64>),
Decimal128(Option<i128>, usize, usize),
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>>),
LargeBinary(Option<Vec<u8, Global>>),
List(Option<Box<Vec<ScalarValue, Global>, Global>>, Box<DataType, Global>),
Date32(Option<i32>),
Date64(Option<i64>),
TimestampSecond(Option<i64>, Option<String>),
TimestampMillisecond(Option<i64>, Option<String>),
TimestampMicrosecond(Option<i64>, Option<String>),
TimestampNanosecond(Option<i64>, Option<String>),
IntervalYearMonth(Option<i32>),
IntervalDayTime(Option<i64>),
IntervalMonthDayNano(Option<i128>),
Struct(Option<Box<Vec<ScalarValue, Global>, Global>>, Box<Vec<Field, Global>, Global>),
}
Expand description
Represents a dynamically typed, nullable single value.
This is the single-valued counter-part of arrow’s Array
.
Variants
Boolean(Option<bool>)
true or false value
Float32(Option<f32>)
32bit float
Float64(Option<f64>)
64bit float
Decimal128(Option<i128>, usize, usize)
128bit decimal, using the i128 to represent the decimal
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
LargeBinary(Option<Vec<u8, Global>>)
large binary
List(Option<Box<Vec<ScalarValue, Global>, Global>>, Box<DataType, Global>)
list of nested ScalarValue (boxed to reduce size_of(ScalarValue))
Date32(Option<i32>)
Date stored as a signed 32bit int
Date64(Option<i64>)
Date stored as a signed 64bit int
TimestampSecond(Option<i64>, Option<String>)
Timestamp Second
TimestampMillisecond(Option<i64>, Option<String>)
Timestamp Milliseconds
TimestampMicrosecond(Option<i64>, Option<String>)
Timestamp Microseconds
TimestampNanosecond(Option<i64>, Option<String>)
Timestamp Nanoseconds
IntervalYearMonth(Option<i32>)
Interval with YearMonth unit
IntervalDayTime(Option<i64>)
Interval with DayTime unit
IntervalMonthDayNano(Option<i128>)
Interval with MonthDayNano unit
Struct(Option<Box<Vec<ScalarValue, Global>, Global>>, Box<Vec<Field, Global>, Global>)
struct of nested ScalarValue (boxed to reduce size_of(ScalarValue))
Implementations
sourceimpl ScalarValue
impl ScalarValue
sourcepub fn try_new_decimal128(
value: i128,
precision: usize,
scale: usize
) -> Result<ScalarValue, DataFusionError>
pub fn try_new_decimal128(
value: i128,
precision: usize,
scale: usize
) -> Result<ScalarValue, DataFusionError>
Create a decimal Scalar from value/precision and scale.
sourcepub fn get_datatype(&self) -> DataType
pub fn get_datatype(&self) -> DataType
Getter for the DataType
of the value
sourcepub fn arithmetic_negate(&self) -> ScalarValue
pub fn arithmetic_negate(&self) -> ScalarValue
Calculate arithmetic negation for a scalar value
sourcepub fn to_array(&self) -> Arc<dyn Array + 'static>
pub fn to_array(&self) -> Arc<dyn Array + 'static>
Converts a scalar value into an 1-row array.
sourcepub fn iter_to_array(
scalars: impl IntoIterator<Item = ScalarValue>
) -> Result<Arc<dyn Array + 'static>, DataFusionError>
pub fn iter_to_array(
scalars: impl IntoIterator<Item = ScalarValue>
) -> Result<Arc<dyn Array + 'static>, 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 + 'static>
pub fn to_array_of_size(&self, size: usize) -> Arc<dyn Array + 'static>
Converts a scalar value into an array of size
rows.
sourcepub fn try_from_array(
array: &Arc<dyn Array + 'static>,
index: usize
) -> Result<ScalarValue, DataFusionError>
pub fn try_from_array(
array: &Arc<dyn Array + 'static>,
index: usize
) -> Result<ScalarValue, DataFusionError>
Converts a value in array
at index
into a ScalarValue
sourcepub fn eq_array(&self, array: &Arc<dyn Array + 'static>, index: usize) -> bool
pub fn eq_array(&self, array: &Arc<dyn Array + 'static>, 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.
Trait Implementations
sourceimpl Clone for ScalarValue
impl Clone for ScalarValue
sourcepub fn clone(&self) -> ScalarValue
pub fn clone(&self) -> ScalarValue
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for ScalarValue
impl Debug for ScalarValue
sourceimpl Display for ScalarValue
impl Display for ScalarValue
sourceimpl<'_> From<&'_ str> for ScalarValue
impl<'_> From<&'_ str> for ScalarValue
sourcepub fn from(value: &str) -> ScalarValue
pub fn from(value: &str) -> ScalarValue
Performs the conversion.
sourceimpl<'_> From<Option<&'_ str>> for ScalarValue
impl<'_> From<Option<&'_ str>> for ScalarValue
sourcepub fn from(value: Option<&str>) -> ScalarValue
pub fn from(value: Option<&str>) -> ScalarValue
Performs the conversion.
sourceimpl From<Option<bool>> for ScalarValue
impl From<Option<bool>> for ScalarValue
sourcepub fn from(value: Option<bool>) -> ScalarValue
pub fn from(value: Option<bool>) -> ScalarValue
Performs the conversion.
sourceimpl From<Option<f32>> for ScalarValue
impl From<Option<f32>> for ScalarValue
sourcepub fn from(value: Option<f32>) -> ScalarValue
pub fn from(value: Option<f32>) -> ScalarValue
Performs the conversion.
sourceimpl From<Option<f64>> for ScalarValue
impl From<Option<f64>> for ScalarValue
sourcepub fn from(value: Option<f64>) -> ScalarValue
pub fn from(value: Option<f64>) -> ScalarValue
Performs the conversion.
sourceimpl From<Option<i16>> for ScalarValue
impl From<Option<i16>> for ScalarValue
sourcepub fn from(value: Option<i16>) -> ScalarValue
pub fn from(value: Option<i16>) -> ScalarValue
Performs the conversion.
sourceimpl From<Option<i32>> for ScalarValue
impl From<Option<i32>> for ScalarValue
sourcepub fn from(value: Option<i32>) -> ScalarValue
pub fn from(value: Option<i32>) -> ScalarValue
Performs the conversion.
sourceimpl From<Option<i64>> for ScalarValue
impl From<Option<i64>> for ScalarValue
sourcepub fn from(value: Option<i64>) -> ScalarValue
pub fn from(value: Option<i64>) -> ScalarValue
Performs the conversion.
sourceimpl From<Option<i8>> for ScalarValue
impl From<Option<i8>> for ScalarValue
sourcepub fn from(value: Option<i8>) -> ScalarValue
pub fn from(value: Option<i8>) -> ScalarValue
Performs the conversion.
sourceimpl From<Option<u16>> for ScalarValue
impl From<Option<u16>> for ScalarValue
sourcepub fn from(value: Option<u16>) -> ScalarValue
pub fn from(value: Option<u16>) -> ScalarValue
Performs the conversion.
sourceimpl From<Option<u32>> for ScalarValue
impl From<Option<u32>> for ScalarValue
sourcepub fn from(value: Option<u32>) -> ScalarValue
pub fn from(value: Option<u32>) -> ScalarValue
Performs the conversion.
sourceimpl From<Option<u64>> for ScalarValue
impl From<Option<u64>> for ScalarValue
sourcepub fn from(value: Option<u64>) -> ScalarValue
pub fn from(value: Option<u64>) -> ScalarValue
Performs the conversion.
sourceimpl From<Option<u8>> for ScalarValue
impl From<Option<u8>> for ScalarValue
sourcepub fn from(value: Option<u8>) -> ScalarValue
pub fn from(value: Option<u8>) -> ScalarValue
Performs the conversion.
sourceimpl<'_> From<Vec<(&'_ str, ScalarValue), Global>> for ScalarValue
impl<'_> From<Vec<(&'_ str, ScalarValue), Global>> for ScalarValue
sourcepub fn from(value: Vec<(&str, ScalarValue), Global>) -> ScalarValue
pub fn from(value: Vec<(&str, ScalarValue), Global>) -> ScalarValue
Performs the conversion.
sourceimpl From<bool> for ScalarValue
impl From<bool> for ScalarValue
sourcepub fn from(value: bool) -> ScalarValue
pub fn from(value: bool) -> ScalarValue
Performs the conversion.
sourceimpl From<f32> for ScalarValue
impl From<f32> for ScalarValue
sourcepub fn from(value: f32) -> ScalarValue
pub fn from(value: f32) -> ScalarValue
Performs the conversion.
sourceimpl From<f64> for ScalarValue
impl From<f64> for ScalarValue
sourcepub fn from(value: f64) -> ScalarValue
pub fn from(value: f64) -> ScalarValue
Performs the conversion.
sourceimpl From<i16> for ScalarValue
impl From<i16> for ScalarValue
sourcepub fn from(value: i16) -> ScalarValue
pub fn from(value: i16) -> ScalarValue
Performs the conversion.
sourceimpl From<i32> for ScalarValue
impl From<i32> for ScalarValue
sourcepub fn from(value: i32) -> ScalarValue
pub fn from(value: i32) -> ScalarValue
Performs the conversion.
sourceimpl From<i64> for ScalarValue
impl From<i64> for ScalarValue
sourcepub fn from(value: i64) -> ScalarValue
pub fn from(value: i64) -> ScalarValue
Performs the conversion.
sourceimpl From<i8> for ScalarValue
impl From<i8> for ScalarValue
sourcepub fn from(value: i8) -> ScalarValue
pub fn from(value: i8) -> ScalarValue
Performs the conversion.
sourceimpl From<u16> for ScalarValue
impl From<u16> for ScalarValue
sourcepub fn from(value: u16) -> ScalarValue
pub fn from(value: u16) -> ScalarValue
Performs the conversion.
sourceimpl From<u32> for ScalarValue
impl From<u32> for ScalarValue
sourcepub fn from(value: u32) -> ScalarValue
pub fn from(value: u32) -> ScalarValue
Performs the conversion.
sourceimpl From<u64> for ScalarValue
impl From<u64> for ScalarValue
sourcepub fn from(value: u64) -> ScalarValue
pub fn from(value: u64) -> ScalarValue
Performs the conversion.
sourceimpl From<u8> for ScalarValue
impl From<u8> for ScalarValue
sourcepub fn from(value: u8) -> ScalarValue
pub fn from(value: u8) -> ScalarValue
Performs the conversion.
sourceimpl FromStr for ScalarValue
impl FromStr for ScalarValue
type Err = Infallible
type Err = Infallible
The associated error which can be returned from parsing.
sourcepub fn from_str(s: &str) -> Result<ScalarValue, <ScalarValue as FromStr>::Err>
pub fn from_str(s: &str) -> Result<ScalarValue, <ScalarValue as FromStr>::Err>
Parses a string s
to return a value of this type. Read more
sourceimpl Hash for ScalarValue
impl Hash for ScalarValue
sourceimpl Literal for ScalarValue
impl Literal for ScalarValue
sourceimpl PartialEq<ScalarValue> for ScalarValue
impl PartialEq<ScalarValue> for ScalarValue
sourceimpl PartialOrd<ScalarValue> for ScalarValue
impl PartialOrd<ScalarValue> for ScalarValue
sourcepub fn partial_cmp(&self, other: &ScalarValue) -> Option<Ordering>
pub fn partial_cmp(&self, other: &ScalarValue) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<'_> TryFrom<&'_ DataType> for ScalarValue
impl<'_> TryFrom<&'_ DataType> for ScalarValue
sourcepub fn try_from(datatype: &DataType) -> Result<ScalarValue, DataFusionError>
pub fn try_from(datatype: &DataType) -> Result<ScalarValue, DataFusionError>
Create a Null instance of ScalarValue for this datatype
type Error = DataFusionError
type Error = DataFusionError
The type returned in the event of a conversion error.
sourceimpl TryFrom<ScalarValue> for u32
impl TryFrom<ScalarValue> for u32
type Error = DataFusionError
type Error = DataFusionError
The type returned in the event of a conversion error.
sourcepub fn try_from(value: ScalarValue) -> Result<u32, DataFusionError>
pub fn try_from(value: ScalarValue) -> Result<u32, DataFusionError>
Performs the conversion.
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CallHasher for T where
T: Hash + ?Sized,
impl<T> CallHasher for T where
T: Hash + ?Sized,
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcepub fn equivalent(&self, key: &K) -> bool
pub fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more