Skip to main content

PushBuffers

Struct PushBuffers 

Source
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:

  1. Zero copy
  2. 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: u64

the virtual “offset” of this buffers (added to any request)

§file_len: u64

The 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: u64

The 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: u64

The sum of the lengths of ranges, kept up to date so that Self::buffered_bytes does not scan all ranges.

Implementations§

Source§

impl PushBuffers

Source

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).

Source

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).

Source

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.

Source

pub(crate) fn has_range(&self, range: &Range<u64>) -> bool

Returns true if the Buffers contains data for the given range

Source

fn find(&self, start: u64, end: u64) -> Option<usize>

Returns the index of a buffer that contains all bytes of start..end, if any.

Source

pub(crate) fn file_len(&self) -> u64

return the file length of the Parquet file being read

Source

fn with_offset(self, offset: u64) -> Self

Specify a new offset

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

pub(crate) fn clear_all_ranges(&mut self)

Clear all buffered ranges and their corresponding data

Trait Implementations§

Source§

impl ChunkReader for PushBuffers

Source§

type T = PushBuffers

The concrete type of reader returned by this trait
Source§

fn get_read(&self, start: u64) -> Result<Self::T, ParquetError>

Get a Read instance starting at the provided file offset Read more
Source§

fn get_bytes(&self, start: u64, length: usize) -> Result<Bytes, ParquetError>

Get a range of data in memory as [Bytes] Read more
Source§

impl Clone for PushBuffers

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PushBuffers

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PushBuffers

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for PushBuffers

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Length for PushBuffers

Source§

fn len(&self) -> u64

Returns the amount of bytes of the inner source.
Source§

impl Read for PushBuffers

less efficient implementation of Read for Buffers

Source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · Source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
Source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Reads all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Reads the exact number of bytes required to fill buf. Read more
Source§

fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
Source§

fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self> ⓘ
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§

fn take(self, limit: u64) -> Take<Self> ⓘ
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
Source§

fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>
where Self: Sized,

🔬This is a nightly-only experimental API. (read_array)
Read and return a fixed array of bytes from this source. Read more
Source§

fn read_le<T>(&mut self) -> Result<T, Error>
where T: FromEndianBytes, Self: Sized,

🔬This is a nightly-only experimental API. (read_le)
Read and return a type (e.g. an integer) in little-endian order. Read more
Source§

fn read_be<T>(&mut self) -> Result<T, Error>
where T: FromEndianBytes, Self: Sized,

🔬This is a nightly-only experimental API. (read_le)
Read and return a type (e.g. an integer) in big-endian order. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<R> ReadBytesExt for R
where R: Read + ?Sized,

§

fn read_u8(&mut self) -> Result<u8, Error>

Reads an unsigned 8 bit integer from the underlying reader. Read more
§

fn read_i8(&mut self) -> Result<i8, Error>

Reads a signed 8 bit integer from the underlying reader. Read more
§

fn read_u16<T>(&mut self) -> Result<u16, Error>
where T: ByteOrder,

Reads an unsigned 16 bit integer from the underlying reader. Read more
§

fn read_i16<T>(&mut self) -> Result<i16, Error>
where T: ByteOrder,

Reads a signed 16 bit integer from the underlying reader. Read more
§

fn read_u24<T>(&mut self) -> Result<u32, Error>
where T: ByteOrder,

Reads an unsigned 24 bit integer from the underlying reader. Read more
§

fn read_i24<T>(&mut self) -> Result<i32, Error>
where T: ByteOrder,

Reads a signed 24 bit integer from the underlying reader. Read more
§

fn read_u32<T>(&mut self) -> Result<u32, Error>
where T: ByteOrder,

Reads an unsigned 32 bit integer from the underlying reader. Read more
§

fn read_i32<T>(&mut self) -> Result<i32, Error>
where T: ByteOrder,

Reads a signed 32 bit integer from the underlying reader. Read more
§

fn read_u48<T>(&mut self) -> Result<u64, Error>
where T: ByteOrder,

Reads an unsigned 48 bit integer from the underlying reader. Read more
§

fn read_i48<T>(&mut self) -> Result<i64, Error>
where T: ByteOrder,

Reads a signed 48 bit integer from the underlying reader. Read more
§

fn read_u64<T>(&mut self) -> Result<u64, Error>
where T: ByteOrder,

Reads an unsigned 64 bit integer from the underlying reader. Read more
§

fn read_i64<T>(&mut self) -> Result<i64, Error>
where T: ByteOrder,

Reads a signed 64 bit integer from the underlying reader. Read more
§

fn read_u128<T>(&mut self) -> Result<u128, Error>
where T: ByteOrder,

Reads an unsigned 128 bit integer from the underlying reader. Read more
§

fn read_i128<T>(&mut self) -> Result<i128, Error>
where T: ByteOrder,

Reads a signed 128 bit integer from the underlying reader. Read more
§

fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>
where T: ByteOrder,

Reads an unsigned n-bytes integer from the underlying reader. Read more
§

fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>
where T: ByteOrder,

Reads a signed n-bytes integer from the underlying reader. Read more
§

fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>
where T: ByteOrder,

Reads an unsigned n-bytes integer from the underlying reader.
§

fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>
where T: ByteOrder,

Reads a signed n-bytes integer from the underlying reader.
§

fn read_f32<T>(&mut self) -> Result<f32, Error>
where T: ByteOrder,

Reads a IEEE754 single-precision (4 bytes) floating point number from the underlying reader. Read more
§

fn read_f64<T>(&mut self) -> Result<f64, Error>
where T: ByteOrder,

Reads a IEEE754 double-precision (8 bytes) floating point number from the underlying reader. Read more
§

fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of unsigned 16 bit integers from the underlying reader. Read more
§

fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of unsigned 32 bit integers from the underlying reader. Read more
§

fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of unsigned 64 bit integers from the underlying reader. Read more
§

fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of unsigned 128 bit integers from the underlying reader. Read more
§

fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>

Reads a sequence of signed 8 bit integers from the underlying reader. Read more
§

fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of signed 16 bit integers from the underlying reader. Read more
§

fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of signed 32 bit integers from the underlying reader. Read more
§

fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of signed 64 bit integers from the underlying reader. Read more
§

fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of signed 128 bit integers from the underlying reader. Read more
§

fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of IEEE754 single-precision (4 bytes) floating point numbers from the underlying reader. Read more
§

fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>
where T: ByteOrder,

👎Deprecated since 1.2.0:

please use read_f32_into instead

DEPRECATED. Read more
§

fn read_f64_into<T>(&mut self, dst: &mut [f64]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of IEEE754 double-precision (8 bytes) floating point numbers from the underlying reader. Read more
§

fn read_f64_into_unchecked<T>(&mut self, dst: &mut [f64]) -> Result<(), Error>
where T: ByteOrder,

👎Deprecated since 1.2.0:

please use read_f64_into instead

DEPRECATED. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Ungil for T
where T: Send,