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

Function cast_output_field

datafusion/expr/src/expr_schema.rs:74–88  ·  view source on GitHub ↗

Derives the output field for a cast expression from the source field. For `TryCast`, `force_nullable` is `true` since a failed cast returns NULL.

(
    source_field: &FieldRef,
    target_type: &DataType,
    force_nullable: bool,
)

Source from the content-addressed store, hash-verified

72/// Derives the output field for a cast expression from the source field.
73/// For `TryCast`, `force_nullable` is `true` since a failed cast returns NULL.
74fn cast_output_field(
75 source_field: &FieldRef,
76 target_type: &DataType,
77 force_nullable: bool,
78) -> Arc<Field> {
79 let mut f = source_field
80 .as_ref()
81 .clone()
82 .with_data_type(target_type.clone())
83 .with_metadata(source_field.metadata().clone());
84 if force_nullable {
85 f = f.with_nullable(true);
86 }
87 Arc::new(f)
88}
89
90impl ExprSchemable for Expr {
91 /// Returns the [arrow::datatypes::DataType] of the expression

Callers 1

to_fieldMethod · 0.85

Calls 7

newFunction · 0.85
with_data_typeMethod · 0.80
with_metadataMethod · 0.45
cloneMethod · 0.45
as_refMethod · 0.45
metadataMethod · 0.45
with_nullableMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…