Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/enums/time_units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use std::fmt::{Display, Formatter, Result as FmtResult};
/// ## Behaviour
/// - Unit values are stored on the `DatetimeArray`, enabling variant-specific logic.
/// - When transmitted over FFI, an `Apache Arrow`- produces compatible native format.
#[derive(PartialEq, Clone, Copy, Debug, Default)]
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug, Default)]
pub enum TimeUnit {
/// Seconds for Apache Arrow `Time32` and `Time64` units.
Seconds,
Expand All @@ -64,7 +64,7 @@ pub enum TimeUnit {
/// T-integer represents an interval, rather than an epoch value.
/// Then, it will materialise as an `Interval` *Apache Arrow* type
/// when sent over FFI.
#[derive(PartialEq, Clone, Debug)]
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
pub enum IntervalUnit {
YearMonth,
DaysTime,
Expand Down
4 changes: 2 additions & 2 deletions src/ffi/arrow_dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ use crate::{BooleanArray, CategoricalArray, Float, FloatArray, Integer, StringAr
/// - For `DatetimeArray` types, `ArrowType` reflects only the physical encoding.
/// Logical distinctions (e.g., interpreting a `Date64` as a timestamp vs. a duration) are stored in `Field` metadata.
/// - Dictionary key widths are defined by the associated `CategoricalIndexType`.
#[derive(PartialEq, Clone, Debug)]
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
pub enum ArrowType {
Null,
Boolean,
Expand Down Expand Up @@ -139,7 +139,7 @@ pub enum ArrowType {
/// - Maps directly to the integer index type in Apache Arrow's `DictionaryType`.
/// - Preserved when sending categorical arrays over the Arrow C Data Interface.

#[derive(PartialEq, Clone, Debug)]
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
pub enum CategoricalIndexType {
#[cfg(feature = "default_categorical_8")]
UInt8,
Expand Down
9 changes: 8 additions & 1 deletion src/structs/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use std::collections::BTreeMap;
use std::fmt::{Display, Formatter};
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};

#[cfg(feature = "datetime")]
Expand Down Expand Up @@ -64,7 +65,7 @@ static UNNAMED_FIELD_COUNTER: AtomicUsize = AtomicUsize::new(1);
/// - This ensures that when sent over Arrow C-FFI (or `to_apache_arrow()`),
/// it converts to the correct external type. Whilst, avoiding proliferating many
/// specialised types prematurely, keeping the API and binary size minimal.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Field {
pub name: String,
pub dtype: ArrowType,
Expand Down Expand Up @@ -235,6 +236,12 @@ impl Display for Field {
}
}

impl From<Arc<Field>> for Field {
fn from(arc: Arc<Field>) -> Self {
Arc::try_unwrap(arc).unwrap_or_else(|a| (*a).clone())
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
20 changes: 20 additions & 0 deletions src/structs/shared_buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
//! This is an internal module that backs the `Buffer` type supporting
//! the typed Arrays in *Minarrow*.

use std::sync::Arc;

use crate::Vec64;
use crate::structs::shared_buffer::internal::owned::{OWNED_VT, Owned};
use crate::structs::shared_buffer::internal::pvec::PromotableVec;
Expand Down Expand Up @@ -161,6 +163,24 @@ impl SharedBuffer {
Self::from_vec64(Vec64(raw_vec))
}

/// Constructs a `SharedBuffer` from an `Arc<M>` where `M: AsRef<[u8]>`.
///
/// Handles the double deref internally so callers don't need a wrapper
/// type. Use `.slice()` for sub-region views.
pub fn from_arc<M: ?Sized + AsRef<[u8]> + Send + Sync + 'static>(arc: Arc<M>) -> Self {
// ArcOwner adapts Arc<M> to AsRef<[u8]> for from_owner.
// Always Sized since Arc is a pointer regardless of M.
struct ArcOwner<M: ?Sized>(Arc<M>);
impl<M: ?Sized + AsRef<[u8]>> AsRef<[u8]> for ArcOwner<M> {
#[inline]
fn as_ref(&self) -> &[u8] { (*self.0).as_ref() }
}
unsafe impl<M: ?Sized + Send + Sync> Send for ArcOwner<M> {}
unsafe impl<M: ?Sized + Send + Sync> Sync for ArcOwner<M> {}

Self::from_owner(ArcOwner(arc))
}

/// Constructs a `SharedBuffer` from an arbitrary owner (e.g. Arc<[u8]>, mmap, etc).
///
/// The owner must implement `AsRef<[u8]> + Send + Sync + 'static`.
Expand Down
Loading