Skip to content

Commit

Permalink
move cast_kernels > kernels/cast
Browse files Browse the repository at this point in the history
  • Loading branch information
nevi-me committed Mar 6, 2019
1 parent eebc3fb commit 020906a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
//!
Expand Down Expand Up @@ -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<ArrayRef> {
use DataType::*;
let from_type = array.data_type();
Expand Down
20 changes: 20 additions & 0 deletions rust/arrow/src/compute/kernels/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions rust/arrow/src/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

0 comments on commit 020906a

Please sign in to comment.