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

Function coerce_i32

parquet/src/arrow/array_reader/primitive_array.rs:246–333  ·  view source on GitHub ↗
(array: &Int32Array, target_type: &ArrowType)

Source from the content-addressed store, hash-verified

244}
245
246fn coerce_i32(array: &Int32Array, target_type: &ArrowType) -> Result<ArrayRef> {
247 Ok(match target_type {
248 ArrowType::UInt8 => {
249 let array = array.unary(|i| i as u8) as UInt8Array;
250 Arc::new(array) as ArrayRef
251 }
252 ArrowType::Int8 => {
253 let array = array.unary(|i| i as i8) as Int8Array;
254 Arc::new(array) as ArrayRef
255 }
256 ArrowType::UInt16 => {
257 let array = array.unary(|i| i as u16) as UInt16Array;
258 Arc::new(array) as ArrayRef
259 }
260 ArrowType::Int16 => {
261 let array = array.unary(|i| i as i16) as Int16Array;
262 Arc::new(array) as ArrayRef
263 }
264 ArrowType::Int32 => Arc::new(array.clone()),
265 // follow C++ implementation and use overflow/reinterpret cast from i32 to u32 which will map
266 // `i32::MIN..0` to `(i32::MAX as u32)..u32::MAX`
267 ArrowType::UInt32 => Arc::new(UInt32Array::new(
268 array.values().inner().clone().into(),
269 array.nulls().cloned(),
270 )) as ArrayRef,
271 ArrowType::Date32 => Arc::new(array.reinterpret_cast::<Date32Type>()) as _,
272 ArrowType::Date64 => {
273 let array: Date64Array = array.unary(|x| x as i64 * 86_400_000);
274 Arc::new(array) as ArrayRef
275 }
276 ArrowType::Time32(TimeUnit::Second) => {
277 Arc::new(array.reinterpret_cast::<Time32SecondType>()) as ArrayRef
278 }
279 ArrowType::Time32(TimeUnit::Millisecond) => {
280 Arc::new(array.reinterpret_cast::<Time32MillisecondType>()) as ArrayRef
281 }
282 ArrowType::Timestamp(time_unit, timezone) => match time_unit {
283 TimeUnit::Second => {
284 let array: TimestampSecondArray = array
285 .unary(|x| x as i64)
286 .with_timezone_opt(timezone.clone());
287 Arc::new(array) as _
288 }
289 TimeUnit::Millisecond => {
290 let array: TimestampMillisecondArray = array
291 .unary(|x| x as i64)
292 .with_timezone_opt(timezone.clone());
293 Arc::new(array) as _
294 }
295 TimeUnit::Microsecond => {
296 let array: TimestampMicrosecondArray = array
297 .unary(|x| x as i64)
298 .with_timezone_opt(timezone.clone());
299 Arc::new(array) as _
300 }
301 TimeUnit::Nanosecond => {
302 let array: TimestampNanosecondArray = array
303 .unary(|x| x as i64)

Callers 1

coerce_arrayFunction · 0.85

Calls 7

unaryMethod · 0.80
cloneMethod · 0.45
innerMethod · 0.45
valuesMethod · 0.45
nullsMethod · 0.45
with_timezone_optMethod · 0.45

Tested by

no test coverage detected