Struct mz_repr::row::Row

source ·
pub struct Row {
    data: CompactBytes,
}
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: CompactBytes

Implementations§

source§

impl Row

source

const SIZE: usize = 23usize

source

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

A variant of Row::from_proto that allows for reuse of internal allocs and validates the decoding against a provided RelationDesc.

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: &[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 data_len(&self) -> usize

The length of the encoded row in bytes. Does not include the size of the Row struct itself.

source

pub fn byte_capacity(&self) -> usize

Returns the total capacity in bytes used by this row.

source

pub fn as_row_ref(&self) -> &RowRef

Extracts a Row slice containing the entire 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 RowRef is empty.

source

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

Iterate the Datum elements of the RowRef.

source

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

For debugging only.

source

pub fn is_empty(&self) -> bool

True iff there is no data in this RowRef.

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 AsRef<RowRef> for Row

source§

fn as_ref(&self) -> &RowRef

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<RowRef> for Row

source§

fn borrow(&self) -> &RowRef

Immutably borrows from an owned value. 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], schema: &RelationDesc) -> 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>, schema: &RelationDesc, ) -> Result<(), String>

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

fn validate(row: &Self, desc: &Self::Schema) -> Result<(), String>

Checks that the given value matches the provided schema. Read more
source§

fn encode_schema(schema: &Self::Schema) -> Bytes

Encode a schema for permanent storage. Read more
source§

fn decode_schema(buf: &Bytes) -> Self::Schema

Decode a schema previous encoded with this codec’s Self::encode_schema. Read more
source§

fn encode_to_vec(&self) -> Vec<u8>

Encode a key or value to a Vec. Read more
source§

impl ColumnDecoder<Row> for RowColumnarDecoder

source§

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

Decode the value at idx into the buffer val. Read more
source§

fn is_null(&self, idx: usize) -> bool

Returns if the value at idx is null.
source§

fn stats(&self) -> StructStats

Returns statistics for the column. This structure is defined by Persist, but the contents are determined by the client; Persist will preserve them in the part metadata and make them available to readers. Read more
source§

impl ColumnEncoder<Row> for RowColumnarEncoder

§

type FinishedColumn = StructArray

Type of column that this encoder returns when finalized.
source§

fn goodbytes(&self) -> usize

The amount of “actual data” encoded by this encoder so far.
source§

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

Appends val onto this encoder.
source§

fn append_null(&mut self)

Appends a null value onto this encoder.
source§

fn finish(self) -> Self::FinishedColumn

Finish this encoder, returning an immutable column.
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

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 IntoRowIterator for Row

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 PartialEq for Row

source§

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

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

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

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

impl PartialOrd for Row

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

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

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

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

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§

fn into_proto_owned(self) -> Proto

A zero clone version of Self::into_proto that types can optionally implement, otherwise, the default implementation delegates to Self::into_proto.
source§

impl Schema2<Row> for RelationDesc

§

type ArrowColumn = StructArray

The type of column we decode from, and encoder will finish into.
§

type Statistics = OptionStats<StructStats>

Statistics we collect for a schema of this type.
§

type Decoder = RowColumnarDecoder

Type that is able to decode values of T from Self::ArrowColumn.
§

type Encoder = RowColumnarEncoder

Type that is able to encoder values of T.
source§

fn decoder(&self, col: Self::ArrowColumn) -> Result<Self::Decoder, Error>

Returns a type that is able to decode instances of T from the provider column.
source§

fn encoder(&self) -> Result<Self::Encoder, Error>

Returns a type that can encode values of T.
source§

fn decoder_any(&self, col: &dyn Array) -> Result<Self::Decoder, Error>

Returns a type that is able to decode instances of T from a type erased arrow::array::Array, erroring if the provided array is not Self::ArrowColumn.
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<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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<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<T> Same for T

§

type Output = T

Should always be Self
source§

impl<'a, S, T> Semigroup<&'a S> for T
where T: Semigroup<S>,

source§

fn plus_equals(&mut self, rhs: &&'a S)

The method of std::ops::AddAssign, for types that do not implement AddAssign.
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> Allocation for T
where T: RefUnwindSafe + Send + Sync,

source§

impl<T> Data for T
where T: Clone + '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,