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

Function cast_column

datafusion/common/src/nested_struct.rs:171–204  ·  view source on GitHub ↗

Cast a column to match the target field type, with special handling for nested structs. This function serves as the main entry point for column casting operations. For struct types, it enforces that **only struct columns can be cast to struct types**. ## Casting Behavior - **Struct Types**: Delegates to `cast_struct_column` for struct-to-struct casting only - **Non-Struct Types**: Uses Arrow's s

(
    source_col: &ArrayRef,
    target_type: &DataType,
    cast_options: &CastOptions,
)

Source from the content-addressed store, hash-verified

169/// - Memory allocation fails during struct construction
170/// - Invalid data type combinations are encountered
171pub fn cast_column(
172 source_col: &ArrayRef,
173 target_type: &DataType,
174 cast_options: &CastOptions,
175) -> Result<ArrayRef> {
176 match (source_col.data_type(), target_type) {
177 (_, Struct(target_fields)) => {
178 cast_struct_column(source_col, target_fields, cast_options)
179 }
180 (DataType::List(_), DataType::List(target_inner)) => {
181 cast_list_column::<i32>(source_col, target_inner, cast_options)
182 }
183 (DataType::LargeList(_), DataType::LargeList(target_inner)) => {
184 cast_list_column::<i64>(source_col, target_inner, cast_options)
185 }
186 (DataType::ListView(_), DataType::ListView(target_inner)) => {
187 cast_list_view_column::<i32>(source_col, target_inner, cast_options)
188 }
189 (DataType::LargeListView(_), DataType::LargeListView(target_inner)) => {
190 cast_list_view_column::<i64>(source_col, target_inner, cast_options)
191 }
192 (
193 DataType::Dictionary(source_key_type, _),
194 DataType::Dictionary(target_key_type, target_value_type),
195 ) => cast_dictionary_column(
196 source_col,
197 source_key_type,
198 target_key_type,
199 target_value_type,
200 cast_options,
201 ),
202 _ => Ok(cast_with_options(source_col, target_type, cast_options)?),
203 }
204}
205
206fn cast_list_column<O: arrow::array::OffsetSizeTrait>(
207 source_col: &ArrayRef,

Calls 4

cast_struct_columnFunction · 0.85
cast_dictionary_columnFunction · 0.85
cast_with_optionsFunction · 0.85
data_typeMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…