Struct mz_repr::relation::RelationDesc
source · [−]pub struct RelationDesc {
typ: RelationType,
names: Vec<ColumnName>,
}
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 RelationDesc
s 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);
Fields
typ: RelationType
names: Vec<ColumnName>
Implementations
sourceimpl RelationDesc
impl RelationDesc
sourcepub fn empty() -> Self
pub fn empty() -> Self
Constructs a new RelationDesc
that represents the empty relation
with no columns and no keys.
sourcepub fn new<I, N>(typ: RelationType, names: I) -> Self where
I: IntoIterator<Item = N>,
N: Into<ColumnName>,
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
.
pub fn from_names_and_types<I, T, N>(iter: I) -> Self where
I: IntoIterator<Item = (N, T)>,
T: Into<ColumnType>,
N: Into<ColumnName>,
sourcepub fn concat(self, other: Self) -> Self
pub fn concat(self, other: Self) -> Self
Concatenates a RelationDesc
onto the end of this RelationDesc
.
sourcepub fn with_column<N>(self, name: N, column_type: ColumnType) -> Self where
N: Into<ColumnName>,
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.
sourcepub fn without_keys(self) -> Self
pub fn without_keys(self) -> Self
Drops all existing keys.
sourcepub fn with_names<I, N>(self, names: I) -> Self where
I: IntoIterator<Item = N>,
N: Into<ColumnName>,
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
.
sourcepub fn typ(&self) -> &RelationType
pub fn typ(&self) -> &RelationType
Returns the relation type underlying this relation description.
sourcepub fn iter(&self) -> impl Iterator<Item = (&ColumnName, &ColumnType)>
pub fn iter(&self) -> impl Iterator<Item = (&ColumnName, &ColumnType)>
Returns an iterator over the columns in this relation.
sourcepub fn iter_types(&self) -> impl Iterator<Item = &ColumnType>
pub fn iter_types(&self) -> impl Iterator<Item = &ColumnType>
Returns an iterator over the types of the columns in this relation.
sourcepub fn iter_names(&self) -> impl Iterator<Item = &ColumnName>
pub fn iter_names(&self) -> impl Iterator<Item = &ColumnName>
Returns an iterator over the names of the columns in this relation.
sourcepub fn get_by_name(&self, name: &ColumnName) -> Option<(usize, &ColumnType)>
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.
sourcepub fn get_name(&self, i: usize) -> &ColumnName
pub fn get_name(&self, i: usize) -> &ColumnName
sourcepub fn get_unambiguous_name(&self, i: usize) -> Option<&ColumnName>
pub fn get_unambiguous_name(&self, i: usize) -> Option<&ColumnName>
Gets the name of the i
th column if that column name is unambiguous.
If at least one other column has the same name as the i
th column,
returns None
. If the i
th column has no name, returns None
.
Panics
Panics if i
is not a valid column index.
sourcepub fn constraints_met(
&self,
i: usize,
d: &Datum<'_>
) -> Result<(), NotNullViolation>
pub fn constraints_met(
&self,
i: usize,
d: &Datum<'_>
) -> Result<(), NotNullViolation>
Verifies that d
meets all of the constraints for the i
th column of self
.
n.b. The only constraint MZ currently supports in NOT NULL, but this structure will be simple to extend.
Trait Implementations
sourceimpl Arbitrary for RelationDesc
impl Arbitrary for RelationDesc
type Parameters = (<RelationType as Arbitrary>::Parameters, <Vec<ColumnName> as Arbitrary>::Parameters)
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
. Read more
type Strategy = Map<(<RelationType as Arbitrary>::Strategy, <Vec<ColumnName> as Arbitrary>::Strategy), fn(_: (RelationType, Vec<ColumnName>)) -> Self>
type Strategy = Map<(<RelationType as Arbitrary>::Strategy, <Vec<ColumnName> as Arbitrary>::Strategy), fn(_: (RelationType, Vec<ColumnName>)) -> Self>
sourcefn arbitrary_with(_top: Self::Parameters) -> Self::Strategy
fn arbitrary_with(_top: Self::Parameters) -> Self::Strategy
sourceimpl Clone for RelationDesc
impl Clone for RelationDesc
sourcefn clone(&self) -> RelationDesc
fn clone(&self) -> RelationDesc
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for RelationDesc
impl Debug for RelationDesc
sourceimpl<'de> Deserialize<'de> for RelationDesc
impl<'de> Deserialize<'de> for RelationDesc
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Hash for RelationDesc
impl Hash for RelationDesc
sourceimpl IntoIterator for RelationDesc
impl IntoIterator for RelationDesc
type Item = (ColumnName, ColumnType)
type Item = (ColumnName, ColumnType)
The type of the elements being iterated over.
type IntoIter = Zip<IntoIter<ColumnName>, IntoIter<ColumnType>>
type IntoIter = Zip<IntoIter<ColumnName>, IntoIter<ColumnType>>
Which kind of iterator are we turning this into?
sourceimpl MzReflect for RelationDesc
impl MzReflect for RelationDesc
sourcefn add_to_reflected_type_info(rti: &mut ReflectedTypeInfo)
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
sourceimpl PartialEq<RelationDesc> for RelationDesc
impl PartialEq<RelationDesc> for RelationDesc
sourcefn eq(&self, other: &RelationDesc) -> bool
fn eq(&self, other: &RelationDesc) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &RelationDesc) -> bool
fn ne(&self, other: &RelationDesc) -> bool
This method tests for !=
.
sourceimpl RustType<ProtoRelationDesc> for RelationDesc
impl RustType<ProtoRelationDesc> for RelationDesc
sourcefn into_proto(&self) -> ProtoRelationDesc
fn into_proto(&self) -> ProtoRelationDesc
Convert a Self
into a Proto
value.
sourcefn from_proto(proto: ProtoRelationDesc) -> Result<Self, TryFromProtoError>
fn from_proto(proto: ProtoRelationDesc) -> Result<Self, TryFromProtoError>
Consume and convert a Proto
back into a Self
value. Read more
sourceimpl Serialize for RelationDesc
impl Serialize for RelationDesc
impl Eq for RelationDesc
impl StructuralEq for RelationDesc
impl StructuralPartialEq for RelationDesc
Auto Trait Implementations
impl RefUnwindSafe for RelationDesc
impl Send for RelationDesc
impl Sync for RelationDesc
impl Unpin for RelationDesc
impl UnwindSafe for RelationDesc
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CallHasher for T where
T: Hash + ?Sized,
impl<T> CallHasher for T where
T: Hash + ?Sized,
sourceimpl<T> CollectionExt<T> for T where
T: IntoIterator,
impl<T> CollectionExt<T> for T where
T: IntoIterator,
sourcefn into_first(self) -> <T as IntoIterator>::Item
fn into_first(self) -> <T as IntoIterator>::Item
Consumes the collection and returns its first element. Read more
sourcefn into_last(self) -> <T as IntoIterator>::Item
fn into_last(self) -> <T as IntoIterator>::Item
Consumes the collection and returns its last element. Read more
sourcefn expect_element<Err>(self, msg: Err) -> <T as IntoIterator>::Item where
Err: Display,
fn expect_element<Err>(self, msg: Err) -> <T as IntoIterator>::Item where
Err: Display,
Consumes the collection and returns its only element. Read more
sourcefn into_element(self) -> <T as IntoIterator>::Item
fn into_element(self) -> <T as IntoIterator>::Item
Consumes the collection and returns its only element. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> FutureExt for T
impl<T> FutureExt for T
sourcefn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
sourcefn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message T
in a tonic::Request
sourceimpl<T> ProgressEventTimestamp for T where
T: Data + Debug + Any,
impl<T> ProgressEventTimestamp for T where
T: Data + Debug + Any,
sourceimpl<P, R> ProtoType<R> for P where
R: RustType<P>,
impl<P, R> ProtoType<R> for P where
R: RustType<P>,
sourcefn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
See RustType::from_proto
.
sourcefn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
See RustType::into_proto
.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more