Skip to content

Commit

Permalink
Add FixedSizeBinaryArrayData
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Feb 27, 2023
1 parent 8d49647 commit ad6d546
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
45 changes: 45 additions & 0 deletions arrow-data/src/data/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,48 @@ impl<O: BytesOffset, B: Bytes> BytesArrayData<O, B> {
&self.data_type
}
}

/// ArrayData for fixed size binary arrays
pub struct FixedSizeBinaryArrayData {
data_type: DataType,
nulls: Option<NullBuffer>,
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<NullBuffer>,
) -> 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
}
}
3 changes: 1 addition & 2 deletions arrow-data/src/data/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ pub enum PhysicalType {
Bytes(OffsetType, BytesType),
FixedSizeList,
List(OffsetType),
Map,
Struct,
Union,
Dictionary(DictionaryKeyType),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit ad6d546

Please sign in to comment.