From ad6d54684a42192cdb9fd3783189b0db21cdd704 Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Mon, 27 Feb 2023 18:16:16 +0000 Subject: [PATCH] Add FixedSizeBinaryArrayData --- arrow-data/src/data/bytes.rs | 45 ++++++++++++++++++++++++++++++++++++ arrow-data/src/data/types.rs | 3 +-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/arrow-data/src/data/bytes.rs b/arrow-data/src/data/bytes.rs index 731479e68624..bfcdc0b1c213 100644 --- a/arrow-data/src/data/bytes.rs +++ b/arrow-data/src/data/bytes.rs @@ -286,3 +286,48 @@ impl BytesArrayData { &self.data_type } } + +/// ArrayData for fixed size binary arrays +pub struct FixedSizeBinaryArrayData { + data_type: DataType, + nulls: Option, + values: Buffer, +} + +impl FixedSizeBinaryArrayData { + /// Creates a new [`FixedSizeBinaryArrayData`] + /// + /// # Safety + /// + /// - `data_type` must be valid for this layout + /// - `nulls.len() == values.len() / element_size` + pub unsafe fn new_unchecked( + data_type: DataType, + values: Buffer, + nulls: Option, + ) -> Self { + Self { + data_type, + nulls, + values, + } + } + + /// Returns the raw byte data + #[inline] + pub fn values(&self) -> &B { + &self.values + } + + /// Returns the null buffer if any + #[inline] + pub fn null_buffer(&self) -> Option<&NullBuffer> { + self.nulls.as_ref() + } + + /// Returns the data type of this array + #[inline] + pub fn data_type(&self) -> &DataType { + &self.data_type + } +} diff --git a/arrow-data/src/data/types.rs b/arrow-data/src/data/types.rs index 09e169f6aa61..3414e481ca66 100644 --- a/arrow-data/src/data/types.rs +++ b/arrow-data/src/data/types.rs @@ -80,7 +80,6 @@ pub enum PhysicalType { Bytes(OffsetType, BytesType), FixedSizeList, List(OffsetType), - Map, Struct, Union, Dictionary(DictionaryKeyType), @@ -141,7 +140,7 @@ impl From<&DataType> for PhysicalType { DataType::UInt64 => Self::Dictionary(DictionaryKeyType::UInt64), d => panic!("illegal dictionary key data type {d}"), }, - DataType::Map(_, _) => Self::Map, + DataType::Map(_, _) => Self::List(OffsetType::Int32), DataType::RunEndEncoded(f, _) => match f.data_type() { DataType::Int16 => Self::Run(RunEndType::Int16), DataType::Int32 => Self::Run(RunEndType::Int32),