From 789f490f8ba60b7ce5a55a055d0ebe07e2e01f45 Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Sat, 29 Jul 2023 17:45:25 +0100 Subject: [PATCH 1/3] Cleanup ArrayData::buffers --- arrow-data/src/{data/mod.rs => data.rs} | 11 ++- arrow-data/src/data/buffers.rs | 96 ------------------------- 2 files changed, 5 insertions(+), 102 deletions(-) rename arrow-data/src/{data/mod.rs => data.rs} (99%) delete mode 100644 arrow-data/src/data/buffers.rs diff --git a/arrow-data/src/data/mod.rs b/arrow-data/src/data.rs similarity index 99% rename from arrow-data/src/data/mod.rs rename to arrow-data/src/data.rs index 32aae1e92a51..a123ac8e655f 100644 --- a/arrow-data/src/data/mod.rs +++ b/arrow-data/src/data.rs @@ -29,8 +29,8 @@ use std::sync::Arc; use crate::equal; -mod buffers; -pub use buffers::*; +/// A collection of [`Buffer`] +pub type Buffers<'a> = &'a [Buffer]; #[inline] pub(crate) fn contains_nulls( @@ -345,10 +345,9 @@ impl ArrayData { &self.data_type } - /// Returns the [`Buffers`] storing data for this [`ArrayData`] - pub fn buffers(&self) -> Buffers<'_> { - // In future ArrayData won't store data contiguously as `Vec` (#1799) - Buffers::from_slice(&self.buffers) + /// Returns the [`Buffer`] storing data for this [`ArrayData`] + pub fn buffers(&self) -> &[Buffer] { + &self.buffers } /// Returns a slice of children [`ArrayData`]. This will be non diff --git a/arrow-data/src/data/buffers.rs b/arrow-data/src/data/buffers.rs deleted file mode 100644 index 883e92e36d82..000000000000 --- a/arrow-data/src/data/buffers.rs +++ /dev/null @@ -1,96 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -use arrow_buffer::Buffer; -use std::iter::Chain; -use std::ops::Index; - -/// A collection of [`Buffer`] -#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)] -pub struct Buffers<'a>([Option<&'a Buffer>; 2]); - -impl<'a> Buffers<'a> { - /// Temporary will be removed once ArrayData does not store `Vec` directly (#3769) - pub(crate) fn from_slice(a: &'a [Buffer]) -> Self { - match a.len() { - 0 => Self([None, None]), - 1 => Self([Some(&a[0]), None]), - _ => Self([Some(&a[0]), Some(&a[1])]), - } - } - - /// Returns the number of [`Buffer`] in this collection - #[inline] - pub fn len(&self) -> usize { - self.0[0].is_some() as usize + self.0[1].is_some() as usize - } - - /// Returns `true` if this collection is empty - #[inline] - pub fn is_empty(&self) -> bool { - self.0[0].is_none() && self.0[1].is_none() - } - - #[inline] - pub fn iter(&self) -> IntoIter<'a> { - self.into_iter() - } - - /// Converts this [`Buffers`] to a `Vec` - #[inline] - pub fn to_vec(&self) -> Vec { - self.iter().cloned().collect() - } -} - -impl<'a> Index for Buffers<'a> { - type Output = &'a Buffer; - - #[inline] - fn index(&self, index: usize) -> &Self::Output { - self.0[index].as_ref().unwrap() - } -} - -impl<'a> IntoIterator for Buffers<'a> { - type Item = &'a Buffer; - type IntoIter = IntoIter<'a>; - - #[inline] - fn into_iter(self) -> Self::IntoIter { - IntoIter(self.0[0].into_iter().chain(self.0[1].into_iter())) - } -} - -type OptionIter<'a> = std::option::IntoIter<&'a Buffer>; - -/// [`Iterator`] for [`Buffers`] -pub struct IntoIter<'a>(Chain, OptionIter<'a>>); - -impl<'a> Iterator for IntoIter<'a> { - type Item = &'a Buffer; - - #[inline] - fn next(&mut self) -> Option { - self.0.next() - } - - #[inline] - fn size_hint(&self) -> (usize, Option) { - self.0.size_hint() - } -} From f060325320d158917b52ad1e518b89001dd63520 Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Sat, 29 Jul 2023 17:48:03 +0100 Subject: [PATCH 2/3] Hide from docs --- arrow-data/src/data.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/arrow-data/src/data.rs b/arrow-data/src/data.rs index a123ac8e655f..51baad402d67 100644 --- a/arrow-data/src/data.rs +++ b/arrow-data/src/data.rs @@ -30,6 +30,7 @@ use std::sync::Arc; use crate::equal; /// A collection of [`Buffer`] +#[doc(hidden)] pub type Buffers<'a> = &'a [Buffer]; #[inline] From 8053da5dcca93d2fa641855c3f10cc8e22fa05ab Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Tue, 1 Aug 2023 10:04:06 +0100 Subject: [PATCH 3/3] Review feedback --- arrow-data/src/data.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/arrow-data/src/data.rs b/arrow-data/src/data.rs index 51baad402d67..e01bdfde9854 100644 --- a/arrow-data/src/data.rs +++ b/arrow-data/src/data.rs @@ -31,6 +31,7 @@ use crate::equal; /// A collection of [`Buffer`] #[doc(hidden)] +#[deprecated(note = "Use [Buffer]")] pub type Buffers<'a> = &'a [Buffer]; #[inline]