A complete, safe, native Rust implementation of Apache Arrow, a cross-language development platform for in-memory data.
Columnar Format
The array
module provides statically typed implementations of all the array
types as defined by the Arrow Columnar Format.
For example, an Int32Array
represents a nullable array of i32
# use ;
let array = from;
assert_eq!;
assert_eq!;
assert_eq!;
let collected: = array.iter.collect;
assert_eq!;
assert_eq!
It is also possible to write generic code. For example, the following is generic over all primitively typed arrays:
# use Sum;
# use ;
# use ArrowPrimitiveType;
#
assert_eq!;
assert_eq!;
For more examples, consult the array
docs.
Type Erasure / Trait Objects
It is often the case that code wishes to handle any type of array, without necessarily knowing
its concrete type. This use-case is catered for by a combination of Array
and DataType
, with the former providing a type-erased container for
the array, and the latter identifying the concrete type of array.
# use ;
# use StringArray;
# use DataType;
#
It is also common to want to write a function that returns one of a number of possible
array implementations. ArrayRef
is a type-alias for Arc<dyn Array>
which is frequently used for this purpose
# use FromStr;
# use Arc;
# use ;
# use ;
# use cast;
#
let array = parse_strings;
let integers = array.as_any..unwrap;
assert_eq!
Compute Kernels
The compute
module provides optimised implementations of many common operations,
for example the parse_strings
operation above could also be implemented as follows:
# use Arc;
# use Result;
# use ;
# use DataType;
#
let array = parse_strings.unwrap;
let integers = array.as_any..unwrap;
assert_eq!
This module also implements many common vertical operations:
- All mathematical binary operators, such as
subtract
- All boolean binary operators such as
equality
cast
filter
take
andlimit
sort
- some string operators such as
substring
andlength
As well as some horizontal operations, such as:
Tabular Representation
It is common to want to group one or more columns together into a tabular representation. This
is provided by RecordBatch
which combines a Schema
and a corresponding list of ArrayRef
.
# use Arc;
# use ;
# use RecordBatch;
#
let col_1 = new as _;
let col_2 = new as _;
let batch = try_from_iter.unwrap;
IO
This crate provides readers and writers for various formats to/from RecordBatch
Parquet is published as a separate crate
Memory and Buffers
Advanced users may wish to interact with the underlying buffers of an Array
, for example,
for FFI or high-performance conversion from other formats. This interface is provided by
ArrayData
which stores the Buffer
comprising an Array
, and can be accessed
with Array::data
The APIs for constructing ArrayData
come in safe, and unsafe variants, with the former
performing extensive, but potentially expensive validation to ensure the buffers are well-formed.
An ArrayRef
can be cheaply created from an ArrayData
using make_array
,
or by using the appropriate [From
] conversion on the concrete Array
implementation.
Safety and Security
Like many crates, this crate makes use of unsafe where prudent. However, it endeavours to be sound. Specifically, it should not be possible to trigger undefined behaviour using safe APIs.
If you think you have found an instance where this is possible, please file a ticket in our issue tracker and it will be triaged and fixed. For more information on arrow's use of unsafe, see here.
Higher-level Processing
This crate aims to provide reusable, low-level primitives for operating on columnar data. For more sophisticated query processing workloads, consider checking out DataFusion. This orchestrates the primitives exported by this crate into an embeddable query engine, with SQL and DataFrame frontends, and heavily influences this crate's roadmap.