Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions ci/scripts/rust_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,34 @@ cargo run --example read_csv
cargo run --example read_csv_infer_schema
popd

# Install cross
cargo install cross

# Linker issues exists with the triples below.
# Needs to be resolved with shipping triple specific toolchain inside containers:
#
# armv7-unknown-linux-musleabi
# armv7-unknown-linux-gnueabi

# Define targets
export TARGETS="armv7-unknown-linux-musleabihf \
arm-unknown-linux-musleabihf \
arm-unknown-linux-musleabi \
armv7-unknown-linux-gnueabihf \
arm-unknown-linux-gnueabihf \
arm-unknown-linux-gnueabi"

# Run on targets
pushd arrow
for target in $TARGETS; do
# Target specific runs
cross run --target ${target} --example builders
cross run --target ${target} --example dynamic_types
cross run --target ${target} --example read_csv
cross run --target ${target} --example read_csv_infer_schema
done
popd

# test datafusion examples
pushd datafusion
cargo run --example csv_sql
Expand Down
1 change: 1 addition & 0 deletions dev/release/rat_exclude_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ r/inst/include/cpp11/*.hpp
ruby/red-arrow/.yardopts
rust/arrow/test/data/*.csv
rust/rust-toolchain
rust/arrow/Cross.toml
rust/arrow-flight/src/arrow.flight.protocol.rs
julia/Arrow/Project.toml
julia/Arrow/README.md
Expand Down
7 changes: 7 additions & 0 deletions rust/arrow/Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build.env]
passthrough = [
"RUST_BACKTRACE",
"RUST_LOG",
"ARROW_TEST_DATA",
"PARQUET_TEST_DATA"
]
12 changes: 7 additions & 5 deletions rust/arrow/src/array/array_primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,21 @@ impl<T: ArrowPrimitiveType> fmt::Debug for PrimitiveArray<T> {
write!(f, "PrimitiveArray<{:?}>\n[\n", T::DATA_TYPE)?;
print_long_array(self, f, |array, index, f| match T::DATA_TYPE {
DataType::Date32(_) | DataType::Date64(_) => {
let v = self.value(index).to_usize().unwrap() as i64;
let v = self.value(index).cast().unwrap();
match as_date::<T>(v) {
Some(date) => write!(f, "{:?}", date),
None => write!(f, "null"),
}
}
DataType::Time32(_) | DataType::Time64(_) => {
let v = self.value(index).to_usize().unwrap() as i64;
let v = self.value(index).cast().unwrap();
match as_time::<T>(v) {
Some(time) => write!(f, "{:?}", time),
None => write!(f, "null"),
}
}
DataType::Timestamp(_, _) => {
let v = self.value(index).to_usize().unwrap() as i64;
let v = self.value(index).cast().unwrap();
match as_datetime::<T>(v) {
Some(datetime) => write!(f, "{:?}", datetime),
None => write!(f, "null"),
Expand Down Expand Up @@ -500,6 +500,7 @@ mod tests {

use crate::buffer::Buffer;
use crate::datatypes::DataType;
use crate::memory::POINTER_WIDTH;

#[test]
fn test_primitive_array_from_vec() {
Expand All @@ -518,7 +519,7 @@ mod tests {
}

assert_eq!(64, arr.get_buffer_memory_size());
let internals_of_primitive_array = 8 + 72; // RawPtrBox & Arc<ArrayData> combined.
let internals_of_primitive_array = POINTER_WIDTH / 4 + POINTER_WIDTH; // RawPtrBox & Arc<ArrayData> combined.
assert_eq!(
arr.get_buffer_memory_size() + internals_of_primitive_array,
arr.get_array_memory_size()
Expand All @@ -544,7 +545,8 @@ mod tests {
}

assert_eq!(128, arr.get_buffer_memory_size());
let internals_of_primitive_array = 8 + 72 + 16; // RawPtrBox & Arc<ArrayData> and it's null_bitmap combined.
let internals_of_primitive_array =
POINTER_WIDTH / 4 + POINTER_WIDTH + POINTER_WIDTH / 4; // RawPtrBox & Arc<ArrayData> and it's null_bitmap combined.
assert_eq!(
arr.get_buffer_memory_size() + internals_of_primitive_array,
arr.get_array_memory_size()
Expand Down
7 changes: 6 additions & 1 deletion rust/arrow/src/array/array_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ impl fmt::Debug for UnionArray {
mod tests {
use super::*;

use crate::memory::POINTER_WIDTH;
use std::sync::Arc;

use crate::array::*;
Expand Down Expand Up @@ -419,7 +420,11 @@ mod tests {
4 * 8 * 4 * mem::size_of::<i32>(),
union.get_buffer_memory_size()
);
let internals_of_union_array = (8 + 72) + (union.boxed_fields.len() * 144); // Arc<ArrayData> & Vec<ArrayRef> combined.
let tagged_pointer_size = POINTER_WIDTH / 4 + POINTER_WIDTH;
let internals_of_union_array = tagged_pointer_size
+ ((union.boxed_fields.len() * tagged_pointer_size)
+ POINTER_WIDTH * 2
+ POINTER_WIDTH); // Arc<ArrayData> & Vec<ArrayRef> combined.
assert_eq!(
union.get_buffer_memory_size() + internals_of_union_array,
union.get_array_memory_size()
Expand Down
3 changes: 2 additions & 1 deletion rust/arrow/src/array/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl fmt::Debug for NullArray {
#[cfg(test)]
mod tests {
use super::*;
use crate::memory::POINTER_WIDTH;

#[test]
fn test_null_array() {
Expand All @@ -130,7 +131,7 @@ mod tests {
assert_eq!(null_arr.is_valid(0), false);

assert_eq!(0, null_arr.get_buffer_memory_size());
let internals_of_null_array = 64; // Arc<ArrayData>
let internals_of_null_array = POINTER_WIDTH; // Arc<ArrayData>
assert_eq!(
null_arr.get_buffer_memory_size() + internals_of_null_array,
null_arr.get_array_memory_size()
Expand Down
10 changes: 2 additions & 8 deletions rust/arrow/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,7 @@ pub(super) fn buffer_bin_and(
}
}

#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
not(any(feature = "simd", feature = "avx512"))
))]
#[cfg(not(any(feature = "simd", feature = "avx512")))]
pub(super) fn buffer_bin_and(
left: &Buffer,
left_offset_in_bits: usize,
Expand Down Expand Up @@ -674,10 +671,7 @@ pub(super) fn buffer_bin_or(
}
}

#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
not(any(feature = "simd", feature = "avx512"))
))]
#[cfg(not(any(feature = "simd", feature = "avx512")))]
pub(super) fn buffer_bin_or(
left: &Buffer,
left_offset_in_bits: usize,
Expand Down
80 changes: 80 additions & 0 deletions rust/arrow/src/datatypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ use serde_json::{
json, Number, Value, Value::Number as VNumber, Value::String as VString,
};

use num::NumCast;

use crate::error::{ArrowError, Result};
use crate::util::bit_util;

Expand Down Expand Up @@ -209,6 +211,14 @@ pub trait ArrowNativeType:
fn to_usize(&self) -> Option<usize> {
None
}

/// Cast native type to destination type
fn cast<T>(self) -> Option<T>
where
T: NumCast,
{
None
}
}

/// Trait indicating a primitive fixed-width type (bool, ints and floats).
Expand Down Expand Up @@ -259,6 +269,13 @@ impl ArrowNativeType for i8 {
fn to_usize(&self) -> Option<usize> {
num::ToPrimitive::to_usize(self)
}

fn cast<T>(self) -> Option<T>
where
T: NumCast,
{
NumCast::from(self)
}
}

impl ArrowNativeType for i16 {
Expand All @@ -273,6 +290,13 @@ impl ArrowNativeType for i16 {
fn to_usize(&self) -> Option<usize> {
num::ToPrimitive::to_usize(self)
}

fn cast<T>(self) -> Option<T>
where
T: NumCast,
{
NumCast::from(self)
}
}

impl ArrowNativeType for i32 {
Expand All @@ -287,6 +311,13 @@ impl ArrowNativeType for i32 {
fn to_usize(&self) -> Option<usize> {
num::ToPrimitive::to_usize(self)
}

fn cast<T>(self) -> Option<T>
where
T: NumCast,
{
NumCast::from(self)
}
}

impl ArrowNativeType for i64 {
Expand All @@ -301,6 +332,13 @@ impl ArrowNativeType for i64 {
fn to_usize(&self) -> Option<usize> {
num::ToPrimitive::to_usize(self)
}

fn cast<T>(self) -> Option<T>
where
T: NumCast,
{
NumCast::from(self)
}
}

impl ArrowNativeType for u8 {
Expand All @@ -315,6 +353,13 @@ impl ArrowNativeType for u8 {
fn to_usize(&self) -> Option<usize> {
num::ToPrimitive::to_usize(self)
}

fn cast<T>(self) -> Option<T>
where
T: NumCast,
{
NumCast::from(self)
}
}

impl ArrowNativeType for u16 {
Expand All @@ -329,6 +374,13 @@ impl ArrowNativeType for u16 {
fn to_usize(&self) -> Option<usize> {
num::ToPrimitive::to_usize(self)
}

fn cast<T>(self) -> Option<T>
where
T: NumCast,
{
NumCast::from(self)
}
}

impl ArrowNativeType for u32 {
Expand All @@ -343,6 +395,13 @@ impl ArrowNativeType for u32 {
fn to_usize(&self) -> Option<usize> {
num::ToPrimitive::to_usize(self)
}

fn cast<T>(self) -> Option<T>
where
T: NumCast,
{
NumCast::from(self)
}
}

impl ArrowNativeType for u64 {
Expand All @@ -357,18 +416,39 @@ impl ArrowNativeType for u64 {
fn to_usize(&self) -> Option<usize> {
num::ToPrimitive::to_usize(self)
}

fn cast<T>(self) -> Option<T>
where
T: NumCast,
{
NumCast::from(self)
}
}

impl ArrowNativeType for f32 {
fn into_json_value(self) -> Option<Value> {
Number::from_f64(f64::round(self as f64 * 1000.0) / 1000.0).map(VNumber)
}

fn cast<T>(self) -> Option<T>
where
T: NumCast,
{
NumCast::from(self)
}
}

impl ArrowNativeType for f64 {
fn into_json_value(self) -> Option<Value> {
Number::from_f64(self).map(VNumber)
}

fn cast<T>(self) -> Option<T>
where
T: NumCast,
{
NumCast::from(self)
}
}

// BooleanType is special: its bit-width is not the size of the primitive type, and its `index`
Expand Down
11 changes: 9 additions & 2 deletions rust/arrow/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ use std::alloc::Layout;
use std::mem::align_of;
use std::ptr::NonNull;

/// Target pointer width of the targeted platform
#[cfg(target_pointer_width = "64")]
pub(crate) const POINTER_WIDTH: usize = 64;
/// Target pointer width of the targeted platform
#[cfg(target_pointer_width = "32")]
pub(crate) const POINTER_WIDTH: usize = 32;

// NOTE: Below code is written for spatial/temporal prefetcher optimizations. Memory allocation
// should align well with usage pattern of cache access and block sizes on layers of storage levels from
// registers to non-volatile memory. These alignments are all cache aware alignments incorporated
Expand Down Expand Up @@ -239,8 +246,8 @@ mod tests {
fn test_allocate() {
for _ in 0..10 {
let p = allocate_aligned(1024);
// make sure this is 64-byte aligned
assert_eq!(0, (p as usize) % 64);
// make sure this is native pointer size aligned
assert_eq!(0, (p as usize) % POINTER_WIDTH);
}
}

Expand Down