Struct mz_repr::row::Row

source ·
pub struct Row {
    data: SmallVec<[u8; 24]>,
}
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().

Fields§

§data: SmallVec<[u8; 24]>

Implementations§

source§

impl Row

source

const SIZE: usize = 24usize

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

Methods from Deref<Target = RowRef>§

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
1.0.0 · 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 Schema = RelationDesc

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

fn codec_name() -> String

Name of the codec. 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 Deref for Row

§

type Target = RowRef

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
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

Debug representation using the internal datums

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 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) -> Selfwhere Self: Sized,

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

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

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

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

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

impl<'a> PartDecoder<'a, Row> for RowDecoder<'a>

source§

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

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

impl<'a> PartEncoder<'a, Row> for RowEncoder<'a>

source§

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

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

impl PartialEq<Row> 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<Row> 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<'a> = RowEncoder<'a>

The associated PartEncoder implementor.
§

type Decoder<'a> = RowDecoder<'a>

The associated PartDecoder implementor.
source§

fn columns(&self) -> Vec<(String, DataType, StatsFn)>

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

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

Returns a [Self::Decoder<’a>] for the given columns.
source§

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

Returns a [Self::Encoder<’a>] 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 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 StructuralEq for Row

source§

impl StructuralPartialEq for Row

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for Twhere T: Clone,

source§

impl<Q, K> Equivalent<K> for Qwhere 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

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromRef<T> for Twhere 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 Twhere 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 Twhere U: From<T>,

const: unstable · 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> ProgressEventTimestamp for Twhere 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 Pwhere R: RustType<P>,

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<V, T> VZip<V> for Twhere 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 Twhere T: Clone + 'static,

source§

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

source§

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

source§

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

source§

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

source§

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