arrow_ord/lib.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5//! Arrow ordering kernels
6//!
7//! # Sort RecordBatch
8//!
9//! ```
10//! # use std::sync::Arc;
11//! # use arrow_array::*;
12//! # use arrow_array::cast::AsArray;
13//! # use arrow_array::types::Int32Type;
14//! # use arrow_ord::sort::sort_to_indices;
15//! # use arrow_select::take::take;
16//! #
17//! let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3, 4]));
18//! let b: ArrayRef = Arc::new(StringArray::from(vec!["b", "a", "e", "d"]));
19//! let batch = RecordBatch::try_from_iter(vec![("a", a), ("b", b)]).unwrap();
20//!
21//! // Sort by column 1
22//! let indices = sort_to_indices(batch.column(1), None, None).unwrap();
23//!
24//! // Apply indices to batch columns
25//! let columns = batch.columns().iter().map(|c| take(&*c, &indices, None).unwrap()).collect();
26//! let sorted = RecordBatch::try_new(batch.schema(), columns).unwrap();
27//!
28//! let col1 = sorted.column(0).as_primitive::<Int32Type>();
29//! assert_eq!(col1.values(), &[2, 1, 4, 3]);
30//! ```
31//!
32//!
33//! # Platform Support
34//!
35//! Only little-endian platforms are officially supported and tested in CI.
36//! Big-endian platforms are not tested in CI and may not work correctly.
37//! Fixes for big-endian platforms are welcome and handled on a best-effort basis,
38//! but compatibility is not guaranteed.
39
40#![doc(
41 html_logo_url = "https://arrow.apache.org/img/arrow-logo_chevrons_black-txt_white-bg.svg",
42 html_favicon_url = "https://arrow.apache.org/img/arrow-logo_chevrons_black-txt_transparent-bg.svg"
43)]
44#![cfg_attr(docsrs, feature(doc_cfg))]
45#![warn(missing_docs)]
46pub mod cmp;
47#[doc(hidden)]
48pub mod comparison;
49pub mod ord;
50pub mod partition;
51pub mod rank;
52pub mod sort;