MCPcopy Create free account
hub / github.com/apache/arrow-rs / coerce_array

Function coerce_array

parquet/src/arrow/array_reader/primitive_array.rs:227–244  ·  view source on GitHub ↗

Coerce the parquet physical type array to the target type This should match the logic in schema::primitive::apply_hint

(array: ArrayRef, target_type: &ArrowType)

Source from the content-addressed store, hash-verified

225///
226/// This should match the logic in schema::primitive::apply_hint
227fn coerce_array(array: ArrayRef, target_type: &ArrowType) -> Result<ArrayRef> {
228 if let ArrowType::Dictionary(key_type, value_type) = target_type {
229 let dictionary = pack_dictionary(key_type, array.as_ref())?;
230 let any_dictionary = dictionary.as_any_dictionary();
231
232 let coerced_values =
233 coerce_array(Arc::clone(any_dictionary.values()), value_type.as_ref())?;
234
235 return Ok(any_dictionary.with_values(coerced_values));
236 }
237
238 match array.data_type() {
239 ArrowType::Int32 => coerce_i32(array.as_primitive(), target_type),
240 ArrowType::Int64 => coerce_i64(array.as_primitive(), target_type),
241 ArrowType::Boolean | ArrowType::Float32 | ArrowType::Float64 => Ok(array),
242 _ => unreachable!("Cannot coerce array of type {}", array.data_type()),
243 }
244}
245
246fn coerce_i32(array: &Int32Array, target_type: &ArrowType) -> Result<ArrayRef> {
247 Ok(match target_type {

Callers 1

consume_batchMethod · 0.85

Calls 9

pack_dictionaryFunction · 0.85
coerce_i32Function · 0.85
coerce_i64Function · 0.85
as_any_dictionaryMethod · 0.80
as_primitiveMethod · 0.80
as_refMethod · 0.45
valuesMethod · 0.45
with_valuesMethod · 0.45
data_typeMethod · 0.45

Tested by

no test coverage detected