tustvold commented on a change in pull request #1041:
URL: https://github.com/apache/arrow-rs/pull/1041#discussion_r778402824



##########
File path: parquet/src/arrow/record_reader/buffer.rs
##########
@@ -0,0 +1,191 @@
+// 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 std::marker::PhantomData;
+use std::ops::Range;
+
+use arrow::buffer::{Buffer, MutableBuffer};
+
+/// A buffer that supports writing new data to the end, and removing data from 
the front
+///
+/// Used by [RecordReader](`super::RecordReader`) to buffer up values before 
returning a
+/// potentially smaller number of values, corresponding to a whole number of 
semantic records
+pub trait BufferQueue: Sized {
+    type Output: Sized;
+
+    type Slice: ?Sized;
+
+    /// Split out the first `len` items
+    ///
+    /// # Panics
+    ///
+    /// Implementations must panic if `len` is beyond the length of 
[`BufferQueue`]
+    ///
+    fn split_off(&mut self, len: usize) -> Self::Output;
+
+    /// Returns a [`Self::Slice`] with at least `batch_size` capacity that can 
be used
+    /// to append data to the end of this [`BufferQueue`]
+    ///
+    /// NB: writes to the returned slice will not update the length of 
[`BufferQueue`]
+    /// instead a subsequent call should be made to [`BufferQueue::set_len`]
+    fn spare_capacity_mut(&mut self, batch_size: usize) -> &mut Self::Slice;
+
+    /// Sets the length of the [`BufferQueue`].
+    ///
+    /// Intended to be used in combination with 
[`BufferQueue::spare_capacity_mut`]
+    ///
+    /// # Panics
+    ///
+    /// Implementations must panic if `len` is beyond the initialized length

Review comment:
       I was trying to distinguish this from `Vec::set_len` which is unsafe 
because it doesn't know how much is initialized. In the case of RecordBuffer<T> 
the entire capacity is initialized, just possibly not set to anything useful. 
The result may not be desirable, but isn't UB and therefore unsafe




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to