From 020906aede1bea48068b149e16ac6699868d607d Mon Sep 17 00:00:00 2001 From: Neville Dipale Date: Wed, 6 Mar 2019 05:19:04 +0200 Subject: [PATCH] move cast_kernels > kernels/cast --- .../{cast_kernels.rs => kernels/cast.rs} | 30 ++++++++----------- rust/arrow/src/compute/kernels/mod.rs | 20 +++++++++++++ rust/arrow/src/compute/mod.rs | 4 +-- 3 files changed, 35 insertions(+), 19 deletions(-) rename rust/arrow/src/compute/{cast_kernels.rs => kernels/cast.rs} (97%) create mode 100644 rust/arrow/src/compute/kernels/mod.rs diff --git a/rust/arrow/src/compute/cast_kernels.rs b/rust/arrow/src/compute/kernels/cast.rs similarity index 97% rename from rust/arrow/src/compute/cast_kernels.rs rename to rust/arrow/src/compute/kernels/cast.rs index ec261bfa2fdff..a25af0296f173 100644 --- a/rust/arrow/src/compute/cast_kernels.rs +++ b/rust/arrow/src/compute/kernels/cast.rs @@ -15,23 +15,7 @@ // specific language governing permissions and limitations // under the License. -//! Defines cast kernels for `ArrayRef`. -//! -//! Allows casting arrays between supported datatypes. -//! -//! ## Behavior -//! -//! * Boolean to Utf8: `true` => '1', `false` => `0` -//! * Utf8 to numeric: strings that can't be parsed to numbers return null, float strings -//! in integer casts return null -//! * Numeric to boolean: 0 returns `false`, any other value returns `true` -//! -//! ## Unsupported Casts -//! -//! * To or from `StructArray` -//! * To or from `ListArray` -//! * Boolean to float -//! * Utf8 to boolean +//! Defines cast kernels for `ArrayRef`, allowing casting arrays between supported datatypes. //! //! Example: //! @@ -123,6 +107,18 @@ macro_rules! cast_bool_to_numeric { } /// Cast array to provided data type +/// +/// Behavior: +/// * Boolean to Utf8: `true` => '1', `false` => `0` +/// * Utf8 to numeric: strings that can't be parsed to numbers return null, float strings +/// in integer casts return null +/// * Numeric to boolean: 0 returns `false`, any other value returns `true` +/// +/// Unsupported Casts +/// * To or from `StructArray` +/// * To or from `ListArray` +/// * Boolean to float +/// * Utf8 to boolean pub fn cast(array: &ArrayRef, to_type: &DataType) -> Result { use DataType::*; let from_type = array.data_type(); diff --git a/rust/arrow/src/compute/kernels/mod.rs b/rust/arrow/src/compute/kernels/mod.rs new file mode 100644 index 0000000000000..fc5ef0da3a282 --- /dev/null +++ b/rust/arrow/src/compute/kernels/mod.rs @@ -0,0 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Computation kernels on Arrow Arrays + +pub mod cast; diff --git a/rust/arrow/src/compute/mod.rs b/rust/arrow/src/compute/mod.rs index 8a06b19ad31cd..7e17eed86e243 100644 --- a/rust/arrow/src/compute/mod.rs +++ b/rust/arrow/src/compute/mod.rs @@ -20,13 +20,13 @@ pub mod arithmetic_kernels; pub mod array_ops; pub mod boolean_kernels; -pub mod cast_kernels; pub mod comparison_kernels; +pub mod kernels; mod util; pub use self::arithmetic_kernels::*; pub use self::array_ops::*; pub use self::boolean_kernels::*; -pub use self::cast_kernels::*; pub use self::comparison_kernels::*; +pub use self::kernels::cast::*;