Skip to content

Commit

Permalink
ARROW-4393: [Rust] coding style: apply 90 characters per line limit
Browse files Browse the repository at this point in the history
This is a coding style change for Rust that limit the number of characters per line to be 90.

Author: Chao Sun <[email protected]>

Closes apache#3501 from sunchao/format-90-characters and squashes the following commits:

db89566 <Chao Sun> ARROW-4393:  coding style: apply 90 characters per line limit
  • Loading branch information
sunchao authored and wesm committed Jan 28, 2019
1 parent d93db4a commit 4dcd493
Show file tree
Hide file tree
Showing 41 changed files with 1,165 additions and 597 deletions.
4 changes: 2 additions & 2 deletions rust/arrow/examples/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use arrow::builder::Int32Builder;
fn main() {
// Primitive Arrays
//
// Primitive arrays are arrays of fixed-width primitive types (bool, u8, u16, u32, u64, i8, i16,
// i32, i64, f32, f64)
// Primitive arrays are arrays of fixed-width primitive types (bool, u8, u16, u32,
// u64, i8, i16, i32, i64, f32, f64)

// Create a new builder with a capacity of 100
let mut primitive_array_builder = Int32Builder::new(100);
Expand Down
69 changes: 45 additions & 24 deletions rust/arrow/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
// specific language governing permissions and limitations
// under the License.

//! Defines public types representing Apache Arrow arrays. Arrow's specification defines an array as
//! "a sequence of values with known length all having the same type." For example, the type
//! `Int16Array` represents an Apache Arrow array of 16-bit integers.
//! Defines public types representing Apache Arrow arrays. Arrow's specification defines
//! an array as "a sequence of values with known length all having the same type." For
//! example, the type `Int16Array` represents an Apache Arrow array of 16-bit integers.
//!
//! ```
//! extern crate arrow;
Expand All @@ -39,11 +39,19 @@
//! // Build the array
//! let array = builder.finish();
//!
//! assert_eq!(5, array.len(), "The array has 5 values, counting the null value");
//! assert_eq!(
//! 5,
//! array.len(),
//! "The array has 5 values, counting the null value"
//! );
//!
//! assert_eq!(2, array.value(2), "Get the value with index 2");
//!
//! assert_eq!(array.value_slice(3, 2), &[3, 4], "Get slice of len 2 starting at idx 3")
//! assert_eq!(
//! array.value_slice(3, 2),
//! &[3, 4],
//! "Get slice of len 2 starting at idx 3"
//! )
//! ```
use std::any::Any;
Expand Down Expand Up @@ -153,8 +161,8 @@ pub struct PrimitiveArray<T: ArrowPrimitiveType> {
data: ArrayDataRef,
/// Pointer to the value array. The lifetime of this must be <= to the value buffer
/// stored in `data`, so it's safe to store.
/// Also note that boolean arrays are bit-packed, so although the underlying pointer is of type
/// bool it should be cast back to u8 before being used.
/// Also note that boolean arrays are bit-packed, so although the underlying pointer
/// is of type bool it should be cast back to u8 before being used.
/// i.e. `self.raw_values.get() as *const u8`
raw_values: RawPtrBox<T::Native>,
}
Expand Down Expand Up @@ -212,7 +220,9 @@ impl<T: ArrowNumericType> PrimitiveArray<T> {

/// Returns a raw pointer to the values of this array.
pub fn raw_values(&self) -> *const T::Native {
unsafe { mem::transmute(self.raw_values.get().offset(self.data.offset() as isize)) }
unsafe {
mem::transmute(self.raw_values.get().offset(self.data.offset() as isize))
}
}

/// Returns the primitive value at index `i`.
Expand Down Expand Up @@ -288,8 +298,10 @@ macro_rules! def_numeric_from_vec {
fn from(data: Vec<Option<$native_ty>>) -> Self {
let data_len = data.len();
let num_bytes = bit_util::ceil(data_len, 8);
let mut null_buf = MutableBuffer::new(num_bytes).with_bitset(num_bytes, false);
let mut val_buf = MutableBuffer::new(data_len * mem::size_of::<$native_ty>());
let mut null_buf =
MutableBuffer::new(num_bytes).with_bitset(num_bytes, false);
let mut val_buf =
MutableBuffer::new(data_len * mem::size_of::<$native_ty>());

{
let null = vec![0; mem::size_of::<$native_ty>()];
Expand Down Expand Up @@ -590,7 +602,8 @@ impl From<ListArray> for BinaryArray {
assert_eq!(
v.data().child_data()[0].child_data().len(),
0,
"BinaryArray can only be created from list array of u8 values (i.e. List<PrimitiveArray<u8>>)."
"BinaryArray can only be created from list array of u8 values \
(i.e. List<PrimitiveArray<u8>>)."
);
assert_eq!(
v.data().child_data()[0].data_type(),
Expand Down Expand Up @@ -627,7 +640,8 @@ impl Array for BinaryArray {
}
}

/// A nested array type where each child (called *field*) is represented by a separate array.
/// A nested array type where each child (called *field*) is represented by a separate
/// array.
pub struct StructArray {
data: ArrayDataRef,
boxed_fields: Vec<ArrayRef>,
Expand Down Expand Up @@ -759,9 +773,8 @@ mod tests {
}

#[test]
#[should_panic(
expected = "PrimitiveArray data should contain a single buffer only (values buffer)"
)]
#[should_panic(expected = "PrimitiveArray data should contain a single buffer only \
(values buffer)")]
fn test_primitive_array_invalid_buffer_len() {
let data = ArrayData::builder(DataType::Int32).len(5).build();
Int32Array::from(data);
Expand Down Expand Up @@ -841,9 +854,8 @@ mod tests {
}

#[test]
#[should_panic(
expected = "PrimitiveArray data should contain a single buffer only (values buffer)"
)]
#[should_panic(expected = "PrimitiveArray data should contain a single buffer only \
(values buffer)")]
fn test_boolean_array_invalid_buffer_len() {
let data = ArrayData::builder(DataType::Boolean).len(5).build();
BooleanArray::from(data);
Expand Down Expand Up @@ -901,7 +913,9 @@ mod tests {
}

#[test]
#[should_panic(expected = "ListArray data should contain a single buffer only (value offsets)")]
#[should_panic(
expected = "ListArray data should contain a single buffer only (value offsets)"
)]
fn test_list_array_invalid_buffer_len() {
let value_data = ArrayData::builder(DataType::Int32)
.len(8)
Expand All @@ -916,7 +930,9 @@ mod tests {
}

#[test]
#[should_panic(expected = "ListArray should contain a single child array (values array)")]
#[should_panic(
expected = "ListArray should contain a single child array (values array)"
)]
fn test_list_array_invalid_child_array_len() {
let value_offsets = Buffer::from(&[0, 2, 5, 7].to_byte_slice());
let list_data_type = DataType::List(Box::new(DataType::Int32));
Expand Down Expand Up @@ -1058,7 +1074,8 @@ mod tests {

#[test]
#[should_panic(
expected = "BinaryArray can only be created from List<u8> arrays, mismatched data types."
expected = "BinaryArray can only be created from List<u8> arrays, mismatched \
data types."
)]
fn test_binary_array_from_incorrect_list_array_type() {
let values: [u32; 12] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
Expand All @@ -1079,7 +1096,8 @@ mod tests {

#[test]
#[should_panic(
expected = "BinaryArray can only be created from list array of u8 values (i.e. List<PrimitiveArray<u8>>)."
expected = "BinaryArray can only be created from list array of u8 values \
(i.e. List<PrimitiveArray<u8>>)."
)]
fn test_binary_array_from_incorrect_list_array() {
let values: [u32; 12] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
Expand Down Expand Up @@ -1151,7 +1169,8 @@ mod tests {
let struct_array = StructArray::from(vec![
(
Field::new("b", DataType::Boolean, false),
Arc::new(BooleanArray::from(vec![false, false, true, true])) as Arc<Array>,
Arc::new(BooleanArray::from(vec![false, false, true, true]))
as Arc<Array>,
),
(
Field::new("c", DataType::Int32, false),
Expand All @@ -1163,7 +1182,9 @@ mod tests {
}

#[test]
#[should_panic(expected = "all child arrays of a StructArray must have the same length")]
#[should_panic(
expected = "all child arrays of a StructArray must have the same length"
)]
fn test_invalid_struct_child_array_lengths() {
StructArray::from(vec![
(
Expand Down
7 changes: 4 additions & 3 deletions rust/arrow/src/array_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// specific language governing permissions and limitations
// under the License.

//! Contains `ArrayData`, a generic representation of Arrow array data which encapsulates common
//! attributes and operations for Arrow array.
//! Contains `ArrayData`, a generic representation of Arrow array data which encapsulates
//! common attributes and operations for Arrow array.
use std::sync::Arc;

Expand Down Expand Up @@ -237,7 +237,8 @@ mod tests {

#[test]
fn test_new() {
let arr_data = ArrayData::new(DataType::Boolean, 10, Some(1), None, 2, vec![], vec![]);
let arr_data =
ArrayData::new(DataType::Boolean, 10, Some(1), None, 2, vec![], vec![]);
assert_eq!(10, arr_data.len());
assert_eq!(1, arr_data.null_count());
assert_eq!(2, arr_data.offset());
Expand Down
76 changes: 55 additions & 21 deletions rust/arrow/src/array_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ use crate::datatypes;
use crate::datatypes::ArrowNumericType;
use crate::error::{ArrowError, Result};

/// Perform `left + right` operation on two arrays. If either left or right value is null then the result is also null.
pub fn add<T>(left: &PrimitiveArray<T>, right: &PrimitiveArray<T>) -> Result<PrimitiveArray<T>>
/// Perform `left + right` operation on two arrays. If either left or right value is null
/// then the result is also null.
pub fn add<T>(
left: &PrimitiveArray<T>,
right: &PrimitiveArray<T>,
) -> Result<PrimitiveArray<T>>
where
T: datatypes::ArrowNumericType,
T::Native: Add<Output = T::Native>
Expand All @@ -40,8 +44,12 @@ where
math_op(left, right, |a, b| Ok(a + b))
}

/// Perform `left - right` operation on two arrays. If either left or right value is null then the result is also null.
pub fn subtract<T>(left: &PrimitiveArray<T>, right: &PrimitiveArray<T>) -> Result<PrimitiveArray<T>>
/// Perform `left - right` operation on two arrays. If either left or right value is null
/// then the result is also null.
pub fn subtract<T>(
left: &PrimitiveArray<T>,
right: &PrimitiveArray<T>,
) -> Result<PrimitiveArray<T>>
where
T: datatypes::ArrowNumericType,
T::Native: Add<Output = T::Native>
Expand All @@ -53,8 +61,12 @@ where
math_op(left, right, |a, b| Ok(a - b))
}

/// Perform `left * right` operation on two arrays. If either left or right value is null then the result is also null.
pub fn multiply<T>(left: &PrimitiveArray<T>, right: &PrimitiveArray<T>) -> Result<PrimitiveArray<T>>
/// Perform `left * right` operation on two arrays. If either left or right value is null
/// then the result is also null.
pub fn multiply<T>(
left: &PrimitiveArray<T>,
right: &PrimitiveArray<T>,
) -> Result<PrimitiveArray<T>>
where
T: datatypes::ArrowNumericType,
T::Native: Add<Output = T::Native>
Expand All @@ -66,9 +78,13 @@ where
math_op(left, right, |a, b| Ok(a * b))
}

/// Perform `left / right` operation on two arrays. If either left or right value is null then the result is also null.
/// If any right hand value is zero then the result of this operation will be `Err(ArrowError::DivideByZero)`.
pub fn divide<T>(left: &PrimitiveArray<T>, right: &PrimitiveArray<T>) -> Result<PrimitiveArray<T>>
/// Perform `left / right` operation on two arrays. If either left or right value is null
/// then the result is also null. If any right hand value is zero then the result of this
/// operation will be `Err(ArrowError::DivideByZero)`.
pub fn divide<T>(
left: &PrimitiveArray<T>,
right: &PrimitiveArray<T>,
) -> Result<PrimitiveArray<T>>
where
T: datatypes::ArrowNumericType,
T::Native: Add<Output = T::Native>
Expand All @@ -86,8 +102,9 @@ where
})
}

/// Helper function to perform math lambda function on values from two arrays. If either left or
/// right value is null then the output value is also null, so `1 + null` is `null`.
/// Helper function to perform math lambda function on values from two arrays. If either
/// left or right value is null then the output value is also null, so `1 + null` is
/// `null`.
fn math_op<T, F>(
left: &PrimitiveArray<T>,
right: &PrimitiveArray<T>,
Expand Down Expand Up @@ -200,7 +217,8 @@ where
bool_op(left, right, |a, b| a != b)
}

/// Perform `left < right` operation on two arrays. Null values are less than non-null values.
/// Perform `left < right` operation on two arrays. Null values are less than non-null
/// values.
pub fn lt<T>(left: &PrimitiveArray<T>, right: &PrimitiveArray<T>) -> Result<BooleanArray>
where
T: ArrowNumericType,
Expand All @@ -213,8 +231,12 @@ where
})
}

/// Perform `left <= right` operation on two arrays. Null values are less than non-null values.
pub fn lt_eq<T>(left: &PrimitiveArray<T>, right: &PrimitiveArray<T>) -> Result<BooleanArray>
/// Perform `left <= right` operation on two arrays. Null values are less than non-null
/// values.
pub fn lt_eq<T>(
left: &PrimitiveArray<T>,
right: &PrimitiveArray<T>,
) -> Result<BooleanArray>
where
T: ArrowNumericType,
{
Expand All @@ -226,7 +248,8 @@ where
})
}

/// Perform `left > right` operation on two arrays. Non-null values are greater than null values.
/// Perform `left > right` operation on two arrays. Non-null values are greater than null
/// values.
pub fn gt<T>(left: &PrimitiveArray<T>, right: &PrimitiveArray<T>) -> Result<BooleanArray>
where
T: ArrowNumericType,
Expand All @@ -239,8 +262,12 @@ where
})
}

/// Perform `left >= right` operation on two arrays. Non-null values are greater than null values.
pub fn gt_eq<T>(left: &PrimitiveArray<T>, right: &PrimitiveArray<T>) -> Result<BooleanArray>
/// Perform `left >= right` operation on two arrays. Non-null values are greater than null
/// values.
pub fn gt_eq<T>(
left: &PrimitiveArray<T>,
right: &PrimitiveArray<T>,
) -> Result<BooleanArray>
where
T: ArrowNumericType,
{
Expand All @@ -253,7 +280,11 @@ where
}

/// Helper function to perform boolean lambda function on values from two arrays.
fn bool_op<T, F>(left: &PrimitiveArray<T>, right: &PrimitiveArray<T>, op: F) -> Result<BooleanArray>
fn bool_op<T, F>(
left: &PrimitiveArray<T>,
right: &PrimitiveArray<T>,
op: F,
) -> Result<BooleanArray>
where
T: ArrowNumericType,
F: Fn(Option<T::Native>, Option<T::Native>) -> bool,
Expand Down Expand Up @@ -281,7 +312,8 @@ where
Ok(b.finish())
}

/// Perform `AND` operation on two arrays. If either left or right value is null then the result is also null.
/// Perform `AND` operation on two arrays. If either left or right value is null then the
/// result is also null.
pub fn and(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> {
if left.len() != right.len() {
return Err(ArrowError::ComputeError(
Expand All @@ -299,7 +331,8 @@ pub fn and(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> {
Ok(b.finish())
}

/// Perform `OR` operation on two arrays. If either left or right value is null then the result is also null.
/// Perform `OR` operation on two arrays. If either left or right value is null then the
/// result is also null.
pub fn or(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> {
if left.len() != right.len() {
return Err(ArrowError::ComputeError(
Expand All @@ -317,7 +350,8 @@ pub fn or(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> {
Ok(b.finish())
}

/// Perform unary `NOT` operation on an arrays. If value is null then the result is also null.
/// Perform unary `NOT` operation on an arrays. If value is null then the result is also
/// null.
pub fn not(left: &BooleanArray) -> Result<BooleanArray> {
let mut b = BooleanArray::builder(left.len());
for i in 0..left.len() {
Expand Down
4 changes: 2 additions & 2 deletions rust/arrow/src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// specific language governing permissions and limitations
// under the License.

//! Defines a bitmap, which is used to track which values in an Arrow array are null. This is called
//! a "validity bitmap" in the Arrow documentation.
//! Defines a bitmap, which is used to track which values in an Arrow array are null.
//! This is called a "validity bitmap" in the Arrow documentation.
use super::buffer::Buffer;
use crate::util::bit_util;
Expand Down
Loading

0 comments on commit 4dcd493

Please sign in to comment.