arrow_ord/lib.rs
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18//! Arrow ordering kernels
19//!
20//! # Sort RecordBatch
21//!
22//! ```
23//! # use std::sync::Arc;
24//! # use arrow_array::*;
25//! # use arrow_array::cast::AsArray;
26//! # use arrow_array::types::Int32Type;
27//! # use arrow_ord::sort::sort_to_indices;
28//! # use arrow_select::take::take;
29//! #
30//! let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3, 4]));
31//! let b: ArrayRef = Arc::new(StringArray::from(vec!["b", "a", "e", "d"]));
32//! let batch = RecordBatch::try_from_iter(vec![("a", a), ("b", b)]).unwrap();
33//!
34//! // Sort by column 1
35//! let indices = sort_to_indices(batch.column(1), None, None).unwrap();
36//!
37//! // Apply indices to batch columns
38//! let columns = batch.columns().iter().map(|c| take(&*c, &indices, None).unwrap()).collect();
39//! let sorted = RecordBatch::try_new(batch.schema(), columns).unwrap();
40//!
41//! let col1 = sorted.column(0).as_primitive::<Int32Type>();
42//! assert_eq!(col1.values(), &[2, 1, 4, 3]);
43//! ```
44//!
45
46#![warn(missing_docs)]
47pub mod cmp;
48#[doc(hidden)]
49pub mod comparison;
50pub mod ord;
51pub mod partition;
52pub mod rank;
53pub mod sort;