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