pub enum ScalarValue {
Show 40 variants Null, Boolean(Option<bool>), Float32(Option<f32>), Float64(Option<f64>), Decimal128(Option<i128>, u8, i8), Decimal256(Option<i256>, 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>>), FixedSizeBinary(i32, Option<Vec<u8>>), LargeBinary(Option<Vec<u8>>), Fixedsizelist(Option<Vec<ScalarValue>>, FieldRef, i32), List(Option<Vec<ScalarValue>>, FieldRef), Date32(Option<i32>), Date64(Option<i64>), Time32Second(Option<i32>), Time32Millisecond(Option<i32>), Time64Microsecond(Option<i64>), Time64Nanosecond(Option<i64>), TimestampSecond(Option<i64>, Option<Arc<str>>), TimestampMillisecond(Option<i64>, Option<Arc<str>>), TimestampMicrosecond(Option<i64>, Option<Arc<str>>), TimestampNanosecond(Option<i64>, Option<Arc<str>>), 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>>, Fields), Dictionary(Box<DataType>, Box<ScalarValue>),
}
Expand description

Represents a dynamically typed, nullable single value. This is the single-valued counter-part to arrow’s Array.

See datatypes for details on datatypes and the format for the definitive reference.

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

§

Decimal256(Option<i256>, u8, i8)

256bit decimal, using the i256 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>>)

binary

§

FixedSizeBinary(i32, Option<Vec<u8>>)

fixed size binary

§

LargeBinary(Option<Vec<u8>>)

large binary

§

Fixedsizelist(Option<Vec<ScalarValue>>, FieldRef, i32)

Fixed size list of nested ScalarValue

§

List(Option<Vec<ScalarValue>>, FieldRef)

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>>)

Timestamp Second

§

TimestampMillisecond(Option<i64>, Option<Arc<str>>)

Timestamp Milliseconds

§

TimestampMicrosecond(Option<i64>, Option<Arc<str>>)

Timestamp Microseconds

§

TimestampNanosecond(Option<i64>, Option<Arc<str>>)

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>>, Fields)

struct of nested ScalarValue

§

Dictionary(Box<DataType>, Box<ScalarValue>)

Dictionary type: index type and value

Implementations§

source§

impl ScalarValue

source

pub fn new_primitive<T: ArrowPrimitiveType>( a: Option<T::Native>, d: &DataType ) -> Self

Create a ScalarValue with the provided value and datatype

Panics

Panics if d is not compatible with T

source

pub fn try_new_decimal128(value: i128, precision: u8, scale: i8) -> Result<Self>

Create a decimal Scalar from value/precision and scale.

source

pub fn new_utf8(val: impl Into<String>) -> Self

Returns a ScalarValue::Utf8 representing val

source

pub fn new_interval_ym(years: i32, months: i32) -> Self

Returns a ScalarValue::IntervalYearMonth representing years years and months months

source

pub fn new_interval_dt(days: i32, millis: i32) -> Self

Returns a ScalarValue::IntervalDayTime representing days days and millis milliseconds

source

pub fn new_interval_mdn(months: i32, days: i32, nanos: i64) -> Self

Returns a ScalarValue::IntervalMonthDayNano representing months months and days days, and nanos nanoseconds

source

pub fn new_list(scalars: Option<Vec<Self>>, child_type: DataType) -> Self

Create a new nullable ScalarValue::List with the specified child_type

source

pub fn new_zero(datatype: &DataType) -> Result<ScalarValue>

Create a zero value in the given type.

source

pub fn new_one(datatype: &DataType) -> Result<ScalarValue>

Create an one value in the given type.

source

pub fn new_negative_one(datatype: &DataType) -> Result<ScalarValue>

Create a negative one value in the given type.

source

pub fn new_ten(datatype: &DataType) -> Result<ScalarValue>

source

pub fn data_type(&self) -> DataType

return the [DataType] of this ScalarValue

source

pub fn get_datatype(&self) -> DataType

Getter for the DataType of the value.

Suggest using Self::data_type as a more standard API

source

pub fn arithmetic_negate(&self) -> Result<Self>

Calculate arithmetic negation for a scalar value

source

pub fn add<T: Borrow<ScalarValue>>(&self, other: T) -> Result<ScalarValue>

Wrapping addition of ScalarValue

NB: operating on ScalarValue directly is not efficient, performance sensitive code should operate on Arrays directly, using vectorized array kernels

source

pub fn add_checked<T: Borrow<ScalarValue>>( &self, other: T ) -> Result<ScalarValue>

Checked addition of ScalarValue

NB: operating on ScalarValue directly is not efficient, performance sensitive code should operate on Arrays directly, using vectorized array kernels

source

pub fn sub<T: Borrow<ScalarValue>>(&self, other: T) -> Result<ScalarValue>

Wrapping subtraction of ScalarValue

NB: operating on ScalarValue directly is not efficient, performance sensitive code should operate on Arrays directly, using vectorized array kernels

source

pub fn sub_checked<T: Borrow<ScalarValue>>( &self, other: T ) -> Result<ScalarValue>

Checked subtraction of ScalarValue

NB: operating on ScalarValue directly is not efficient, performance sensitive code should operate on Arrays directly, using vectorized array kernels

source

pub fn is_unsigned(&self) -> bool

source

pub fn is_null(&self) -> bool

whether this value is null or not.

source

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.

source

pub fn to_array(&self) -> ArrayRef

Converts a scalar value into an 1-row array.

source

pub fn to_scalar(&self) -> Scalar<ArrayRef>

Converts a scalar into an arrow Scalar (which implements the Datum interface).

This can be used to call arrow compute kernels such as lt

Example
use datafusion_common::ScalarValue;
use arrow::array::{BooleanArray, Int32Array};

let arr = Int32Array::from(vec![Some(1), None, Some(10)]);
let five = ScalarValue::Int32(Some(5));

let result = arrow::compute::kernels::cmp::lt(
  &arr,
  &five.to_scalar(),
).unwrap();

let expected = BooleanArray::from(vec![
    Some(true),
    None,
    Some(false)
  ]
);

assert_eq!(&result, &expected);
source

pub fn iter_to_array( scalars: impl IntoIterator<Item = ScalarValue> ) -> Result<ArrayRef>

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 ScalarValues 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);
source

pub fn to_array_of_size(&self, size: usize) -> ArrayRef

Converts a scalar value into an array of size rows.

source

pub fn try_from_array(array: &dyn Array, index: usize) -> Result<Self>

Converts a value in array at index into a ScalarValue

source

pub fn try_from_string(value: String, target_type: &DataType) -> Result<Self>

Try to parse value into a ScalarValue of type target_type

source

pub fn eq_array(&self, array: &ArrayRef, 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.

source

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)

source

pub fn size_of_vec(vec: &Vec<Self>) -> usize

Estimates size of Vec in bytes.

Includes the size of the Vec container itself.

source

pub fn size_of_hashset<S>(set: &HashSet<Self, S>) -> usize

Estimates size of HashSet in bytes.

Includes the size of the HashSet container itself.

Trait Implementations§

source§

impl Clone for ScalarValue

source§

fn clone(&self) -> ScalarValue

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ScalarValue

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for ScalarValue

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&str> for ScalarValue

source§

fn from(value: &str) -> Self

Converts to this type from the input type.
source§

impl From<Option<&str>> for ScalarValue

source§

fn from(value: Option<&str>) -> Self

Converts to this type from the input type.
source§

impl From<Option<bool>> for ScalarValue

source§

fn from(value: Option<bool>) -> Self

Converts to this type from the input type.
source§

impl From<Option<f32>> for ScalarValue

source§

fn from(value: Option<f32>) -> Self

Converts to this type from the input type.
source§

impl From<Option<f64>> for ScalarValue

source§

fn from(value: Option<f64>) -> Self

Converts to this type from the input type.
source§

impl From<Option<i16>> for ScalarValue

source§

fn from(value: Option<i16>) -> Self

Converts to this type from the input type.
source§

impl From<Option<i32>> for ScalarValue

source§

fn from(value: Option<i32>) -> Self

Converts to this type from the input type.
source§

impl From<Option<i64>> for ScalarValue

source§

fn from(value: Option<i64>) -> Self

Converts to this type from the input type.
source§

impl From<Option<i8>> for ScalarValue

source§

fn from(value: Option<i8>) -> Self

Converts to this type from the input type.
source§

impl From<Option<u16>> for ScalarValue

source§

fn from(value: Option<u16>) -> Self

Converts to this type from the input type.
source§

impl From<Option<u32>> for ScalarValue

source§

fn from(value: Option<u32>) -> Self

Converts to this type from the input type.
source§

impl From<Option<u64>> for ScalarValue

source§

fn from(value: Option<u64>) -> Self

Converts to this type from the input type.
source§

impl From<Option<u8>> for ScalarValue

source§

fn from(value: Option<u8>) -> Self

Converts to this type from the input type.
source§

impl From<Vec<(&str, ScalarValue), Global>> for ScalarValue

source§

fn from(value: Vec<(&str, ScalarValue)>) -> Self

Converts to this type from the input type.
source§

impl From<bool> for ScalarValue

source§

fn from(value: bool) -> Self

Converts to this type from the input type.
source§

impl From<f32> for ScalarValue

source§

fn from(value: f32) -> Self

Converts to this type from the input type.
source§

impl From<f64> for ScalarValue

source§

fn from(value: f64) -> Self

Converts to this type from the input type.
source§

impl From<i16> for ScalarValue

source§

fn from(value: i16) -> Self

Converts to this type from the input type.
source§

impl From<i32> for ScalarValue

source§

fn from(value: i32) -> Self

Converts to this type from the input type.
source§

impl From<i64> for ScalarValue

source§

fn from(value: i64) -> Self

Converts to this type from the input type.
source§

impl From<i8> for ScalarValue

source§

fn from(value: i8) -> Self

Converts to this type from the input type.
source§

impl From<u16> for ScalarValue

source§

fn from(value: u16) -> Self

Converts to this type from the input type.
source§

impl From<u32> for ScalarValue

source§

fn from(value: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for ScalarValue

source§

fn from(value: u64) -> Self

Converts to this type from the input type.
source§

impl From<u8> for ScalarValue

source§

fn from(value: u8) -> Self

Converts to this type from the input type.
source§

impl FromStr for ScalarValue

§

type Err = Infallible

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for ScalarValue

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq<ScalarValue> for ScalarValue

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<ScalarValue> for ScalarValue

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<&DataType> for ScalarValue

source§

fn try_from(datatype: &DataType) -> Result<Self>

Create a Null instance of ScalarValue for this datatype

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

impl TryFrom<DataType> for ScalarValue

source§

fn try_from(datatype: DataType) -> Result<Self>

Create a Null instance of ScalarValue for this datatype

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

impl TryFrom<ScalarValue> for bool

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

fn try_from(value: ScalarValue) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<ScalarValue> for f32

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

fn try_from(value: ScalarValue) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<ScalarValue> for f64

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

fn try_from(value: ScalarValue) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<ScalarValue> for i128

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

fn try_from(value: ScalarValue) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<ScalarValue> for i16

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

fn try_from(value: ScalarValue) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<ScalarValue> for i256

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

fn try_from(value: ScalarValue) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<ScalarValue> for i32

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

fn try_from(value: ScalarValue) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<ScalarValue> for i64

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

fn try_from(value: ScalarValue) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<ScalarValue> for i8

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

fn try_from(value: ScalarValue) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<ScalarValue> for u16

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

fn try_from(value: ScalarValue) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<ScalarValue> for u32

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

fn try_from(value: ScalarValue) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<ScalarValue> for u64

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

fn try_from(value: ScalarValue) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<ScalarValue> for u8

§

type Error = DataFusionError

The type returned in the event of a conversion error.
source§

fn try_from(value: ScalarValue) -> Result<Self>

Performs the conversion.
source§

impl Eq for ScalarValue

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Allocation for Twhere T: RefUnwindSafe + Send + Sync,