pub struct PushBuffers {
offset: u64,
file_len: u64,
ranges: Vec<Range<u64>>,
buffers: Vec<Bytes>,
max_len: u64,
buffered_bytes: u64,
}Expand description
Holds multiple non-contiguous, caller-provided buffers of file data.
This is the in-memory buffer used by the push-based Parquet decoders
(ParquetPushDecoder and ParquetMetaDataPushDecoder). It can be
constructed up front and handed to a builder so the decoder reuses bytes
that have already been fetched.
Features:
- Zero copy
- non contiguous ranges of bytes
§Non Coalescing
This buffer does not coalesce (merging adjacent ranges of bytes into a single range). Coalescing at this level would require copying the data but the caller may already have the needed data in a single buffer which would require no copying.
Thus, the implementation defers to the caller to coalesce subsequent requests if desired.
§Ordering
The buffers are sorted by the start of their range. Thus, lookups use a binary search, not a scan of all buffers. Pushed ranges can overlap.
Fields§
§offset: u64the virtual “offset” of this buffers (added to any request)
file_len: u64The total length of the file being decoded
ranges: Vec<Range<u64>>The ranges of data that are available for decoding (not adjusted for
offset), sorted by start
buffers: Vec<Bytes>The buffers of data that can be used to decode the Parquet file, in the
same order as ranges
max_len: u64The length of the longest range in ranges.
This keeps lookups fast in the common case: buffers that do not
overlap and have similar lengths. Pushed ranges can overlap, so a
lookup cannot stop at the nearest buffer. max_len tells the lookup
when no earlier buffer can reach the requested range, so it checks one
or two buffers, not all of them. See Self::find.
buffered_bytes: u64The sum of the lengths of ranges, kept up to date so that
Self::buffered_bytes does not scan all ranges.
Implementations§
Source§impl PushBuffers
impl PushBuffers
Sourcepub fn new(file_len: u64) -> Self
pub fn new(file_len: u64) -> Self
Create a new, empty PushBuffers for a file of the given length.
Use PushBuffers::default when the file length is unknown or
irrelevant (e.g. the push decoder, which tracks ranges by absolute
offset and never consults file_len).
Sourcepub fn push_ranges(
&mut self,
ranges: Vec<Range<u64>>,
buffers: Vec<Bytes>,
) -> Result<(), ParquetError>
pub fn push_ranges( &mut self, ranges: Vec<Range<u64>>, buffers: Vec<Bytes>, ) -> Result<(), ParquetError>
Push all the ranges and buffers
§Errors
Returns an error if the number of ranges does not match the number of
buffers, or if any buffer’s length does not match its range (see
Self::push_range).
Sourcepub fn push_range(
&mut self,
range: Range<u64>,
buffer: Bytes,
) -> Result<(), ParquetError>
pub fn push_range( &mut self, range: Range<u64>, buffer: Bytes, ) -> Result<(), ParquetError>
Push a new range and its associated buffer
§Errors
Returns an error if the buffer’s length does not match the range’s length, e.g. when a truncated (short) read is pushed.
Sourcepub(crate) fn has_range(&self, range: &Range<u64>) -> bool
pub(crate) fn has_range(&self, range: &Range<u64>) -> bool
Returns true if the Buffers contains data for the given range
Sourcefn find(&self, start: u64, end: u64) -> Option<usize>
fn find(&self, start: u64, end: u64) -> Option<usize>
Returns the index of a buffer that contains all bytes of start..end,
if any.
Sourcefn with_offset(self, offset: u64) -> Self
fn with_offset(self, offset: u64) -> Self
Specify a new offset
Sourcepub(crate) fn buffered_bytes(&self) -> u64
pub(crate) fn buffered_bytes(&self) -> u64
Return the total length of all buffered ranges.
This counts the bytes that the decoder can still read, not the
allocated memory. Self::release_ranges keeps the remaining parts of
a buffer as slices of the pushed [Bytes], and the allocation of a
pushed [Bytes] is freed only after all of its parts are released.
Sourcepub(crate) fn clear_ranges(&mut self, ranges_to_clear: &[Range<u64>])
pub(crate) fn clear_ranges(&mut self, ranges_to_clear: &[Range<u64>])
Clear any range and corresponding buffer that is exactly in the ranges_to_clear
Sourcefn update_max_len(&mut self)
fn update_max_len(&mut self)
Set max_len to the maximum length of the remaining ranges.
A max_len that is too large is still correct, lookups only scan
further. This update is for performance: a large buffer that was
removed must not slow down later lookups.
Sourcepub(crate) fn release_ranges(&mut self, ranges: &[Range<u64>])
pub(crate) fn release_ranges(&mut self, ranges: &[Range<u64>])
Remove all buffered bytes in ranges.
A buffer that overlaps a range is trimmed or split, and the parts
outside the range are kept. The kept parts are zero-copy slices, which
record the bytes that the decoder can still read. Thus, the allocator
frees the memory of a pushed [Bytes] only after all of its parts are
removed.
The buffers stay sorted by start, which lookups require (see
Self::find). If no buffer overlaps ranges, the buffers do not
change.
Sourcepub(crate) fn retain_ranges(&mut self, keep: &[Range<u64>])
pub(crate) fn retain_ranges(&mut self, keep: &[Range<u64>])
Remove all buffered bytes outside keep.
This calls Self::release_ranges with the complement of keep, so
the same rules apply to the kept parts.
Sourcepub(crate) fn clear_all_ranges(&mut self)
pub(crate) fn clear_all_ranges(&mut self)
Clear all buffered ranges and their corresponding data
Trait Implementations§
Source§impl ChunkReader for PushBuffers
impl ChunkReader for PushBuffers
Source§impl Clone for PushBuffers
impl Clone for PushBuffers
Source§impl Debug for PushBuffers
impl Debug for PushBuffers
Source§impl Default for PushBuffers
impl Default for PushBuffers
Source§impl Display for PushBuffers
impl Display for PushBuffers
Source§impl Length for PushBuffers
impl Length for PushBuffers
Source§impl Read for PushBuffers
less efficient implementation of Read for Buffers
impl Read for PushBuffers
less efficient implementation of Read for Buffers
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)Auto Trait Implementations§
impl Freeze for PushBuffers
impl RefUnwindSafe for PushBuffers
impl Send for PushBuffers
impl Sync for PushBuffers
impl Unpin for PushBuffers
impl UnsafeUnpin for PushBuffers
impl UnwindSafe for PushBuffers
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<R> ReadBytesExt for R
impl<R> ReadBytesExt for R
§fn read_u8(&mut self) -> Result<u8, Error>
fn read_u8(&mut self) -> Result<u8, Error>
§fn read_i8(&mut self) -> Result<i8, Error>
fn read_i8(&mut self) -> Result<i8, Error>
§fn read_u16<T>(&mut self) -> Result<u16, Error>where
T: ByteOrder,
fn read_u16<T>(&mut self) -> Result<u16, Error>where
T: ByteOrder,
§fn read_i16<T>(&mut self) -> Result<i16, Error>where
T: ByteOrder,
fn read_i16<T>(&mut self) -> Result<i16, Error>where
T: ByteOrder,
§fn read_u24<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
fn read_u24<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
§fn read_i24<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
fn read_i24<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
§fn read_u32<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
fn read_u32<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
§fn read_i32<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
fn read_i32<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
§fn read_u48<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
fn read_u48<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
§fn read_i48<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
fn read_i48<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
§fn read_u64<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
fn read_u64<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
§fn read_i64<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
fn read_i64<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
§fn read_u128<T>(&mut self) -> Result<u128, Error>where
T: ByteOrder,
fn read_u128<T>(&mut self) -> Result<u128, Error>where
T: ByteOrder,
§fn read_i128<T>(&mut self) -> Result<i128, Error>where
T: ByteOrder,
fn read_i128<T>(&mut self) -> Result<i128, Error>where
T: ByteOrder,
§fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>where
T: ByteOrder,
fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>where
T: ByteOrder,
§fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>where
T: ByteOrder,
fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>where
T: ByteOrder,
§fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>where
T: ByteOrder,
fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>where
T: ByteOrder,
§fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>where
T: ByteOrder,
fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>where
T: ByteOrder,
§fn read_f32<T>(&mut self) -> Result<f32, Error>where
T: ByteOrder,
fn read_f32<T>(&mut self) -> Result<f32, Error>where
T: ByteOrder,
§fn read_f64<T>(&mut self) -> Result<f64, Error>where
T: ByteOrder,
fn read_f64<T>(&mut self) -> Result<f64, Error>where
T: ByteOrder,
§fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>where
T: ByteOrder,
fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>where
T: ByteOrder,
§fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>where
T: ByteOrder,
fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>where
T: ByteOrder,
§fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>where
T: ByteOrder,
fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>where
T: ByteOrder,
§fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>where
T: ByteOrder,
fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>where
T: ByteOrder,
§fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>
fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>
§fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>where
T: ByteOrder,
fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>where
T: ByteOrder,
§fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>where
T: ByteOrder,
fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>where
T: ByteOrder,
§fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>where
T: ByteOrder,
fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>where
T: ByteOrder,
§fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>where
T: ByteOrder,
fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>where
T: ByteOrder,
§fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
§fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
please use read_f32_into instead