Struct mz_repr::RelationDesc

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

A description of the shape of a relation.

It bundles a RelationType with the name of each column in the relation. Individual column names are optional.

§Examples

A RelationDescs is typically constructed via its builder API:

use mz_repr::{ColumnType, RelationDesc, ScalarType};

let desc = RelationDesc::empty()
    .with_column("id", ScalarType::Int64.nullable(false))
    .with_column("price", ScalarType::Float64.nullable(true));

In more complicated cases, like when constructing a RelationDesc in response to user input, it may be more convenient to construct a relation type first, and imbue it with column names to form a RelationDesc later:

use mz_repr::RelationDesc;

let relation_type = plan_query("SELECT * FROM table");
let names = (0..relation_type.arity()).map(|i| match i {
    0 => "first",
    1 => "second",
    _ => "unknown",
});
let desc = RelationDesc::new(relation_type, names);

Implementations§

source§

impl RelationDesc

source

pub fn empty() -> Self

Constructs a new RelationDesc that represents the empty relation with no columns and no keys.

source

pub fn is_empty(&self) -> bool

Check if the RelationDesc is empty.

source

pub fn new<I, N>(typ: RelationType, names: I) -> Self
where I: IntoIterator<Item = N>, N: Into<ColumnName>,

Constructs a new RelationDesc from a RelationType and an iterator over column names.

§Panics

Panics if the arity of the RelationType is not equal to the number of items in names.

source

pub fn from_names_and_types<I, T, N>(iter: I) -> Self
where I: IntoIterator<Item = (N, T)>, T: Into<ColumnType>, N: Into<ColumnName>,

source

pub fn concat(self, other: Self) -> Self

Concatenates a RelationDesc onto the end of this RelationDesc.

source

pub fn with_column<N>(self, name: N, column_type: ColumnType) -> Self
where N: Into<ColumnName>,

Appends a column with the specified name and type.

source

pub fn with_key(self, indices: Vec<usize>) -> Self

Adds a new key for the relation.

source

pub fn without_keys(self) -> Self

Drops all existing keys.

source

pub fn with_names<I, N>(self, names: I) -> Self
where I: IntoIterator<Item = N>, N: Into<ColumnName>,

Builds a new relation description with the column names replaced with new names.

§Panics

Panics if the arity of the relation type does not match the number of items in names.

source

pub fn arity(&self) -> usize

Computes the number of columns in the relation.

source

pub fn typ(&self) -> &RelationType

Returns the relation type underlying this relation description.

source

pub fn iter(&self) -> impl Iterator<Item = (&ColumnName, &ColumnType)>

Returns an iterator over the columns in this relation.

source

pub fn iter_types(&self) -> impl Iterator<Item = &ColumnType>

Returns an iterator over the types of the columns in this relation.

source

pub fn iter_names(&self) -> impl Iterator<Item = &ColumnName>

Returns an iterator over the names of the columns in this relation.

source

pub fn iter_similar_names<'a>( &'a self, name: &'a ColumnName ) -> impl Iterator<Item = &'a ColumnName>

Returns an iterator over the names of the columns in this relation that are “similar” to the provided name.

source

pub fn get_by_name(&self, name: &ColumnName) -> Option<(usize, &ColumnType)>

Finds a column by name.

Returns the index and type of the column named name. If no column with the specified name exists, returns None. If multiple columns have the specified name, the leftmost column is returned.

source

pub fn get_name(&self, i: usize) -> &ColumnName

Gets the name of the ith column.

§Panics

Panics if i is not a valid column index.

source

pub fn get_name_mut(&mut self, i: usize) -> &mut ColumnName

Mutably gets the name of the ith column.

§Panics

Panics if i is not a valid column index.

source

pub fn get_unambiguous_name(&self, i: usize) -> Option<&ColumnName>

Gets the name of the ith column if that column name is unambiguous.

If at least one other column has the same name as the ith column, returns None. If the ith column has no name, returns None.

§Panics

Panics if i is not a valid column index.

source

pub fn constraints_met( &self, i: usize, d: &Datum<'_> ) -> Result<(), NotNullViolation>

Verifies that d meets all of the constraints for the ith column of self.

n.b. The only constraint MZ currently supports in NOT NULL, but this structure will be simple to extend.

source§

impl RelationDesc

source

pub fn decoder<V>(&self, part: ColumnsRef<V>) -> Result<(V, RowDecoder), String>

source

pub fn encoder<'a, V>( &self, part: ColumnsMut<'a, V> ) -> Result<(V, RowEncoder<'a>), String>

Trait Implementations§

source§

impl Arbitrary for RelationDesc

§

type Parameters = (<RelationType as Arbitrary>::Parameters, <Vec<ColumnName> as Arbitrary>::Parameters)

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

type Strategy = Map<(<RelationType as Arbitrary>::Strategy, <Vec<ColumnName> as Arbitrary>::Strategy), fn(_: (RelationType, Vec<ColumnName>)) -> RelationDesc>

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

fn arbitrary_with(_top: 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 RelationDesc

source§

fn clone(&self) -> RelationDesc

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 Debug for RelationDesc

source§

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

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

impl<'de> Deserialize<'de> for RelationDesc

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 Hash for RelationDesc

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 IntoIterator for RelationDesc

§

type Item = (ColumnName, ColumnType)

The type of the elements being iterated over.
§

type IntoIter = Zip<IntoIter<ColumnName>, IntoIter<ColumnType>>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl MzReflect for RelationDesc

source§

fn add_to_reflected_type_info(rti: &mut ReflectedTypeInfo)

Adds names and types of the fields of the struct or enum to rti. Read more
source§

impl PartialEq for RelationDesc

source§

fn eq(&self, other: &RelationDesc) -> 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 RustType<ProtoRelationDesc> for RelationDesc

source§

fn into_proto(&self) -> ProtoRelationDesc

Convert a Self into a Proto value.
source§

fn from_proto(proto: ProtoRelationDesc) -> 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 = 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<'a>) -> Result<Self::Encoder<'a>, String>

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

impl Serialize for RelationDesc

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 Eq for RelationDesc

source§

impl StructuralPartialEq for RelationDesc

Auto Trait Implementations§

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> CollectionExt<T> for T
where T: IntoIterator,

source§

fn into_first(self) -> <T as IntoIterator>::Item

Consumes the collection and returns its first element. Read more
source§

fn into_last(self) -> <T as IntoIterator>::Item

Consumes the collection and returns its last element. Read more
source§

fn expect_element<Err>( self, msg_fn: impl FnOnce() -> Err ) -> <T as IntoIterator>::Item
where Err: Display,

Consumes the collection and returns its only element. Read more
source§

fn into_element(self) -> <T as IntoIterator>::Item

Consumes the collection and returns its only element. Read more
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> 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> 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, 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

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

source§

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