lance-arrow-scalar
A scalar type backed by Apache Arrow arrays with Ord, Hash, and Eq support.
Overview
ArrowScalar wraps a single-element Arrow array and provides comparison and hashing operations by leveraging Apache Arrow's OwnedRow representation. This ensures:
- Correct total ordering for all Arrow types
- Proper NaN handling for floating-point values
- Consistent null ordering
- O(1) comparisons via cached row bytes
Features
Eq,Ord, andHashtraits for Arrow scalar values- Support for all Arrow data types
- Serde serialization/deserialization support
- Zero-copy conversion from Arrow arrays
Usage
Add to your Cargo.toml:
[]
= "57.0.0"
Then use in your code:
use ArrowScalar;
// Create from primitive types
let a = from;
let b = from;
assert!;
// Create from strings
let s1 = from;
let s2 = from;
assert!;
// Use in collections
use HashMap;
let mut map = new;
map.insert;
Cross-Type Comparison
Comparing scalars of different data types produces an arbitrary but consistent ordering based on the underlying row bytes. This allows scalars to be used as keys in sorted collections regardless of type, though the ordering across types is not semantically meaningful.
Implementation Details
Comparisons and hashing are delegated to [arrow_row::OwnedRow], which provides efficient byte-level operations. The row representation is cached at construction time, making all comparison and hashing operations O(1).