Struct datafusion_common::scalar::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>,

§

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

§

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.