datafusion_common::scalar

Struct ScalarStructBuilder

Source
pub struct ScalarStructBuilder { /* private fields */ }
Expand description

Builder for ScalarValue::Struct.

See examples on ScalarValue

Implementations§

Source§

impl ScalarStructBuilder

Source

pub fn new() -> Self

Create a new ScalarStructBuilder

Source

pub fn new_null(fields: impl IntoFields) -> ScalarValue

Return a new ScalarValue::Struct with a single null value.

Note this is different from a struct where each of the specified fields are null (e.g. {a: NULL})

§Example
let fields = vec![
   Field::new("a", DataType::Int32, false),
];
let sv = ScalarStructBuilder::new_null(fields);
// Note this is `NULL`, not `{a: NULL}`
assert_eq!(format!("{sv}"), "NULL");

To create a struct where the fields are null, use Self::new() and pass null values for each field:

// make a nullable field
let field = Field::new("a", DataType::Int32, true);
// add a null value for the "a" field
let sv = ScalarStructBuilder::new()
  .with_scalar(field, ScalarValue::Int32(None))
  .build()
  .unwrap();
// value is not null, but field is
assert_eq!(format!("{sv}"), "{a:}");
Source

pub fn with_array(self, field: impl IntoFieldRef, value: ArrayRef) -> Self

Add the specified field and ArrayRef to the struct.

Note the array should have a single row.

Source

pub fn with_scalar(self, field: impl IntoFieldRef, value: ScalarValue) -> Self

Add the specified field and ScalarValue to the struct.

Source

pub fn with_name_and_scalar(self, name: &str, value: ScalarValue) -> Self

Add a field with the specified name and value to the struct. the field is created with the specified data type and as non nullable

Source

pub fn build(self) -> Result<ScalarValue>

Return a ScalarValue::Struct with the fields and values added so far

§Errors

If the StructArray cannot be created (for example if there is a mismatch between field types and arrays) or the arrays do not have exactly one element.

Trait Implementations§

Source§

impl Debug for ScalarStructBuilder

Source§

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

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

impl Default for ScalarStructBuilder

Source§

fn default() -> ScalarStructBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.