MCPcopy Create free account
hub / github.com/apache/datafusion / cast_to

Method cast_to

datafusion/expr-common/src/columnar_value.rs:288–303  ·  view source on GitHub ↗

Cast this [ColumnarValue] to the specified `DataType` # Struct Casting Behavior When casting struct types, fields are matched **by name** rather than position: - Source fields are matched to target fields using case-sensitive name comparison - Fields are reordered to match the target schema - Missing target fields are filled with null arrays - Extra source fields are ignored For non-struct type

(
        &self,
        cast_type: &DataType,
        cast_options: Option<&CastOptions<'static>>,
    )

Source from the content-addressed store, hash-verified

286 ///
287 /// For non-struct types, uses Arrow's standard positional casting.
288 pub fn cast_to(
289 &self,
290 cast_type: &DataType,
291 cast_options: Option<&CastOptions<'static>>,
292 ) -> Result<ColumnarValue> {
293 let cast_options = cast_options.cloned().unwrap_or(DEFAULT_CAST_OPTIONS);
294 match self {
295 ColumnarValue::Array(array) => {
296 let casted = cast_array_by_name(array, cast_type, &cast_options)?;
297 Ok(ColumnarValue::Array(casted))
298 }
299 ColumnarValue::Scalar(scalar) => Ok(ColumnarValue::Scalar(
300 scalar.cast_to_with_options(cast_type, &cast_options)?,
301 )),
302 }
303 }
304}
305
306fn cast_array_by_name(

Callers 6

meanMethod · 0.45
varianceMethod · 0.45
medianMethod · 0.45

Calls 3

cast_array_by_nameFunction · 0.85
cast_to_with_optionsMethod · 0.80
clonedMethod · 0.45