Struct mz_repr::Row

source ·
pub struct Row { /* private fields */ }
Expand description

A packed representation for Datums.

Datum is easy to work with but very space inefficient. A Datum::Int32(42) is laid out in memory like this:

tag: 3 padding: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 data: 0 0 0 42 padding: 0 0 0 0 0 0 0 0 0 0 0 0

For a total of 32 bytes! The second set of padding is needed in case we were to write a 16-byte datum into this location. The first set of padding is needed to align that hypothetical decimal to a 16 bytes boundary.

A Row stores zero or more Datums without any padding. We avoid the need for the first set of padding by only providing access to the Datums via calls to ptr::read_unaligned, which on modern x86 is barely penalized. We avoid the need for the second set of padding by not providing mutable access to the Datum. Instead, Row is append-only.

A Row can be built from a collection of Datums using Row::pack, but it is more efficient to use Row::pack_slice so that a right-sized allocation can be created. If that is not possible, consider using the row buffer pattern: allocate one row, pack into it, and then call Row::clone to receive a copy of that row, leaving behind the original allocation to pack future rows.

Creating a row via Row::pack_slice:

let row = Row::pack_slice(&[Datum::Int32(0), Datum::Int32(1), Datum::Int32(2)]);
assert_eq!(row.unpack(), vec![Datum::Int32(0), Datum::Int32(1), Datum::Int32(2)])

Rows can be unpacked by iterating over them:

let row = Row::pack_slice(&[Datum::Int32(0), Datum::Int32(1), Datum::Int32(2)]);
assert_eq!(row.iter().nth(1).unwrap(), Datum::Int32(1));

If you want random access to the Datums in a Row, use Row::unpack to create a Vec<Datum>

let row = Row::pack_slice(&[Datum::Int32(0), Datum::Int32(1), Datum::Int32(2)]);
let datums = row.unpack();
assert_eq!(datums[1], Datum::Int32(1));

§Performance

Rows are dynamically sized, but up to a fixed size their data is stored in-line. It is best to re-use a Row across multiple Row creation calls, as this avoids the allocations involved in Row::new().

Implementations§

source§

impl Row

source

pub fn decode_from_proto(&mut self, proto: &ProtoRow) -> Result<(), String>

A variant of Row::from_proto that allows for reuse of internal allocs.

source§

impl Row

source

pub fn with_capacity(cap: usize) -> Self

Allocate an empty Row with a pre-allocated capacity.

source

pub unsafe fn from_bytes_unchecked(data: Vec<u8>) -> Self

Creates a new row from supplied bytes.

§Safety

This method relies on data being an appropriate row encoding, and can result in unsafety if this is not the case.

source

pub fn packer(&mut self) -> RowPacker<'_>

Constructs a RowPacker that will pack datums into this row’s allocation.

This method clears the existing contents of the row, but retains the allocation.

source

pub fn pack<'a, I, D>(iter: I) -> Row
where I: IntoIterator<Item = D>, D: Borrow<Datum<'a>>,

Take some Datums and pack them into a Row.

This method builds a Row by repeatedly increasing the backing allocation. If the contents of the iterator are known ahead of time, consider Row::with_capacity to right-size the allocation first, and then RowPacker::extend to populate it with Datums. This avoids the repeated allocation resizing and copying.

source

pub fn pack_using<'a, I, D>(&mut self, iter: I) -> Row
where I: IntoIterator<Item = D>, D: Borrow<Datum<'a>>,

Use self to pack iter, and then clone the result.

This is a convenience method meant to reduce boilerplate around row formation.

source

pub fn try_pack<'a, I, D, E>(iter: I) -> Result<Row, E>
where I: IntoIterator<Item = Result<D, E>>, D: Borrow<Datum<'a>>,

Like Row::pack, but the provided iterator is allowed to produce an error, in which case the packing operation is aborted and the error returned.

source

pub fn pack_slice<'a>(slice: &[Datum<'a>]) -> Row

Pack a slice of Datums into a Row.

This method has the advantage over pack that it can determine the required allocation before packing the elements, ensuring only one allocation and no redundant copies required.

source

pub fn byte_len(&self) -> usize

Returns the total amount of bytes used by this row.

source

pub fn byte_capacity(&self) -> usize

Returns the total capacity in bytes used by this row.

source

pub fn unpack(&self) -> Vec<Datum<'_>>

Unpack self into a Vec<Datum> for efficient random access.

source

pub fn unpack_first(&self) -> Datum<'_>

Return the first Datum in self

Panics if the Row is empty.

source

pub fn iter(&self) -> DatumListIter<'_>

Iterate the Datum elements of the Row.

source

pub fn data(&self) -> &[u8]

For debugging only

source

pub fn is_empty(&self) -> bool

True iff there is no data in this Row

Trait Implementations§

source§

impl Arbitrary for Row

§

type Parameters = SizeRange

The type of parameters that arbitrary_with accepts for configuration of the generated Strategy. Parameters must implement Default.
§

type Strategy = BoxedStrategy<Row>

The type of Strategy used to generate values of type Self.
source§

fn arbitrary_with(size: Self::Parameters) -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). The strategy is passed the arguments given in args. Read more
source§

fn arbitrary() -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). Read more
source§

impl Clone for Row

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
source§

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

Performs copy-assignment from source. Read more
source§

impl Codec for Row

source§

fn encode<B>(&self, buf: &mut B)
where B: BufMut,

Encodes a row into the permanent storage format.

This perfectly round-trips through Row::decode. It’s guaranteed to be readable by future versions of Materialize through v(TODO: Figure out our policy).

source§

fn decode(buf: &[u8]) -> Result<Row, String>

Decodes a row from the permanent storage format.

This perfectly round-trips through Row::encode. It can read rows encoded by historical versions of Materialize back to v(TODO: Figure out our policy).

§

type Storage = ProtoRow

A type used with Self::decode_from for allocation reuse. Set to () if unnecessary.
§

type Schema = RelationDesc

The type of the associated schema for Self. Read more
source§

fn codec_name() -> String

Name of the codec. Read more
source§

fn decode_from<'a>( &mut self, buf: &'a [u8], storage: &mut Option<ProtoRow> ) -> Result<(), String>

An alternate form of Self::decode which enables amortizing allocs. Read more
source§

impl Columnation for Row

§

type InnerRegion = RowStack

The type of region capable of absorbing allocations owned by the Self type. Note: not allocations of Self, but of the things that it owns.
source§

impl Debug for Row

source§

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

Debug representation using the internal datums

source§

impl Default for Row

source§

fn default() -> Row

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

impl<'de> Deserialize<'de> for Row

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Row

source§

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

Display representation using the internal datums

source§

impl FromDatumIter for Row

source§

fn from_datum_iter<'a, I, D>(&mut self, datum_iter: I) -> Self
where I: IntoIterator<Item = D>, D: Borrow<Datum<'a>>,

Packs into self the given iterator of datums and returns a clone.

source§

fn try_from_datum_iter<'a, I, D, E>(&mut self, datum_iter: I) -> Result<Self, E>
where I: IntoIterator<Item = Result<D, E>>, D: Borrow<Datum<'a>>,

Packs into self by using the packer’s try_extend method on the given iterator and returns a clone.

source§

impl Hash for Row

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a> IntoIterator for &'a Row

§

type Item = Datum<'a>

The type of the elements being iterated over.
§

type IntoIter = DatumListIter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> DatumListIter<'a>

Creates an iterator from a value. Read more
source§

impl Ord for Row

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartDecoder<Row> for RowDecoder

source§

fn decode(&self, idx: usize, val: &mut Row)

Decodes the value at the given index. Read more
source§

impl PartEncoder<Row> for RowEncoder

source§

fn encode(&mut self, val: &Row)

Encodes the given value into the Part being constructed.
source§

fn finish(self) -> (usize, Vec<DynColumnMut>)

Consumes self returning the columns that were written to.
source§

impl PartialEq for Row

source§

fn eq(&self, other: &Row) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Row

These implementations order first by length, and then by slice contents. This allows many comparisons to complete without dereferencing memory. Warning: These order by the u8 array representation, and NOT by Datum::cmp.

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl RustType<ProtoRow> for Row

source§

fn into_proto(&self) -> ProtoRow

Convert a Self into a Proto value.
source§

fn from_proto(proto: ProtoRow) -> Result<Self, TryFromProtoError>

Consume and convert a Proto back into a Self value. Read more
source§

impl Schema<Row> for RelationDesc

§

type Encoder = RowEncoder

The associated PartEncoder implementor.
§

type Decoder = RowDecoder

The associated PartDecoder implementor.
source§

fn columns(&self) -> DynStructCfg

Returns the name and types of the columns in this type.
source§

fn decoder(&self, part: ColumnsRef) -> Result<Self::Decoder, String>

Returns a Self::Decoder for the given columns.
source§

fn encoder<'a>(&self, part: ColumnsMut) -> Result<Self::Encoder, String>

Returns a Self::Encoder for the given columns.
source§

impl Serialize for Row

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl ToDatumIter for Row

§

type DatumIter<'a> = DatumListIter<'a>

Datum iterator for Row.

source§

fn to_datum_iter<'a>(&'a self) -> Self::DatumIter<'a>

Borrows self and gets an iterator from it.

source§

impl TryFrom<&ProtoRow> for Row

TODO: remove this in favor of RustType::from_proto.

§

type Error = String

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

fn try_from(x: &ProtoRow) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for Row

source§

impl StructuralPartialEq for Row

Auto Trait Implementations§

§

impl Freeze for Row

§

impl RefUnwindSafe for Row

§

impl Send for Row

§

impl Sync for Row

§

impl Unpin for Row

§

impl UnwindSafe for Row

Blanket Implementations§

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
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

fn cast_into(self) -> U

Performs the cast.
source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<R, O, T> CopyOnto<ConsecutiveOffsetPairs<R, O>> for T
where R: Region<Index = (usize, usize)>, O: OffsetContainer<usize>, T: CopyOnto<R>,

source§

fn copy_onto( self, target: &mut ConsecutiveOffsetPairs<R, O> ) -> <ConsecutiveOffsetPairs<R, O> as Region>::Index

Copy self into the target container, returning an index that allows to look up the corresponding read item.
source§

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

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> FutureExt for T

source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
source§

impl<T> Hashable for T
where T: Hash,

§

type Output = u64

The type of the output value.
source§

fn hashed(&self) -> u64

A well-distributed integer derived from the data.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T, U> OverrideFrom<Option<&T>> for U
where U: OverrideFrom<T>,

source§

fn override_from(self, layer: &Option<&T>) -> U

Override the configuration represented by Self with values from the given layer.
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> PreferredContainer for T
where T: Ord + Clone + 'static,

§

type Container = Vec<T>

The preferred container for the type.
source§

impl<T> ProgressEventTimestamp for T
where T: Data + Debug + Any,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Upcasts this ProgressEventTimestamp to Any. Read more
source§

fn type_name(&self) -> &'static str

Returns the name of the concrete type of this object. Read more
source§

impl<P, R> ProtoType<R> for P
where R: RustType<P>,

source§

impl<R, T> PushInto<FlatStack<R>> for T
where R: Region + Clone + 'static, T: CopyOnto<R>,

source§

fn push_into(self, target: &mut FlatStack<R>)

Push self into the target container.
source§

impl<T> PushInto<Vec<T>> for T

source§

fn push_into(self, target: &mut Vec<T>)

Push self into the target container.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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§

default 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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> Data for T
where T: Clone + 'static,

source§

impl<T> Data for T
where T: Send + Sync + Any + Serialize + for<'a> Deserialize<'a> + 'static,

source§

impl<T> Data for T
where T: Data + Ord + Debug,

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> ExchangeData for T
where T: Data + Data,

source§

impl<T> ExchangeData for T
where T: ExchangeData + Ord + Debug,

source§

impl<T> Sequence for T
where T: Eq + Hash,