pub struct ScalarStructBuilder { /* private fields */ }
Expand description
Builder for ScalarValue::Struct
.
See examples on ScalarValue
Implementations§
Source§impl ScalarStructBuilder
impl ScalarStructBuilder
Sourcepub fn new_null(fields: impl IntoFields) -> ScalarValue
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:}");
Sourcepub fn with_array(self, field: impl IntoFieldRef, value: ArrayRef) -> Self
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.
Sourcepub fn with_scalar(self, field: impl IntoFieldRef, value: ScalarValue) -> Self
pub fn with_scalar(self, field: impl IntoFieldRef, value: ScalarValue) -> Self
Add the specified field and ScalarValue
to the struct.
Sourcepub fn with_name_and_scalar(self, name: &str, value: ScalarValue) -> Self
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
Sourcepub fn build(self) -> Result<ScalarValue>
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
impl Debug for ScalarStructBuilder
Source§impl Default for ScalarStructBuilder
impl Default for ScalarStructBuilder
Source§fn default() -> ScalarStructBuilder
fn default() -> ScalarStructBuilder
Auto Trait Implementations§
impl Freeze for ScalarStructBuilder
impl !RefUnwindSafe for ScalarStructBuilder
impl Send for ScalarStructBuilder
impl Sync for ScalarStructBuilder
impl Unpin for ScalarStructBuilder
impl !UnwindSafe for ScalarStructBuilder
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more