pub struct RelationDesc {
typ: RelationType,
metadata: BTreeMap<ColumnIndex, ColumnMetadata>,
}
Expand description
A description of the shape of a relation.
It bundles a RelationType
with the name of each column in the relation.
§Examples
A RelationDesc
s is typically constructed via its builder API:
use mz_repr::{ColumnType, RelationDesc, ScalarType};
let desc = RelationDesc::builder()
.with_column("id", ScalarType::Int64.nullable(false))
.with_column("price", ScalarType::Float64.nullable(true))
.finish();
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
§metadata: BTreeMap<ColumnIndex, ColumnMetadata>
Implementations§
Source§impl RelationDesc
impl RelationDesc
Sourcepub fn builder() -> RelationDescBuilder
pub fn builder() -> RelationDescBuilder
Returns a RelationDescBuilder
that can be used to construct a 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
pub fn new<I, N>(typ: RelationType, names: I) -> Self
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
Sourcepub fn concat(self, other: Self) -> Self
pub fn concat(self, other: Self) -> Self
Concatenates a RelationDesc
onto the end of this RelationDesc
.
§Panics
Panics if either self
or other
have columns that were added at a
RelationVersion
other than RelationVersion::root
or if any
columns were dropped.
TODO(parkmycar): Move this method to RelationDescBuilder
.
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
pub fn with_names<I, N>(self, names: I) -> Self
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 iter_similar_names<'a>(
&'a self,
name: &'a ColumnName,
) -> impl Iterator<Item = &'a ColumnName>
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
.
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_name_mut(&mut self, i: usize) -> &mut ColumnName
pub fn get_name_mut(&mut self, i: usize) -> &mut 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§
Source§impl Arbitrary for RelationDesc
impl Arbitrary for RelationDesc
Source§type Parameters = ()
type Parameters = ()
arbitrary_with
accepts for configuration
of the generated Strategy
. Parameters must implement Default
.Source§type Strategy = BoxedStrategy<RelationDesc>
type Strategy = BoxedStrategy<RelationDesc>
Strategy
used to generate values of type Self
.Source§fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl Clone for RelationDesc
impl Clone for RelationDesc
Source§fn clone(&self) -> RelationDesc
fn clone(&self) -> RelationDesc
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for RelationDesc
impl Debug for RelationDesc
Source§impl<'de> Deserialize<'de> for RelationDesc
impl<'de> Deserialize<'de> for RelationDesc
Source§fn 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>,
Source§impl Hash for RelationDesc
impl Hash for RelationDesc
Source§impl IntoIterator for RelationDesc
impl IntoIterator for RelationDesc
Source§type Item = (ColumnName, ColumnType)
type Item = (ColumnName, ColumnType)
Source§type IntoIter = Box<dyn Iterator<Item = (ColumnName, ColumnType)>>
type IntoIter = Box<dyn Iterator<Item = (ColumnName, ColumnType)>>
Source§impl MzReflect for RelationDesc
impl MzReflect for RelationDesc
Source§fn add_to_reflected_type_info(rti: &mut ReflectedTypeInfo)
fn add_to_reflected_type_info(rti: &mut ReflectedTypeInfo)
rti
. Read moreSource§impl PartialEq for RelationDesc
impl PartialEq for RelationDesc
Source§impl RustType<ProtoRelationDesc> for RelationDesc
impl RustType<ProtoRelationDesc> for RelationDesc
Source§fn into_proto(&self) -> ProtoRelationDesc
fn into_proto(&self) -> ProtoRelationDesc
Self
into a Proto
value.Source§fn from_proto(proto: ProtoRelationDesc) -> Result<Self, TryFromProtoError>
fn from_proto(proto: ProtoRelationDesc) -> Result<Self, TryFromProtoError>
Source§fn into_proto_owned(self) -> Proto
fn into_proto_owned(self) -> Proto
Self::into_proto
that types can
optionally implement, otherwise, the default implementation
delegates to Self::into_proto
.Source§impl Schema2<Row> for RelationDesc
impl Schema2<Row> for RelationDesc
Source§type ArrowColumn = StructArray
type ArrowColumn = StructArray
Source§type Statistics = OptionStats<StructStats>
type Statistics = OptionStats<StructStats>
Source§type Decoder = RowColumnarDecoder
type Decoder = RowColumnarDecoder
T
from Self::ArrowColumn
.Source§type Encoder = RowColumnarEncoder
type Encoder = RowColumnarEncoder
T
.Source§fn decoder(&self, col: Self::ArrowColumn) -> Result<Self::Decoder, Error>
fn decoder(&self, col: Self::ArrowColumn) -> Result<Self::Decoder, Error>
T
from the provider column.Source§fn decoder_any(&self, col: &dyn Array) -> Result<Self::Decoder, Error>
fn decoder_any(&self, col: &dyn Array) -> Result<Self::Decoder, Error>
T
from a type erased
arrow::array::Array
, erroring if the provided array is not Self::ArrowColumn
.Source§impl Serialize for RelationDesc
impl Serialize for RelationDesc
impl Eq for RelationDesc
impl StructuralPartialEq for RelationDesc
Auto Trait Implementations§
impl Freeze for RelationDesc
impl RefUnwindSafe for RelationDesc
impl Send for RelationDesc
impl Sync for RelationDesc
impl Unpin for RelationDesc
impl UnwindSafe for RelationDesc
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<T> CollectionExt<T> for Twhere
T: IntoIterator,
impl<T> CollectionExt<T> for Twhere
T: IntoIterator,
Source§fn into_first(self) -> <T as IntoIterator>::Item
fn into_first(self) -> <T as IntoIterator>::Item
Source§fn into_last(self) -> <T as IntoIterator>::Item
fn into_last(self) -> <T as IntoIterator>::Item
Source§fn expect_element<Err>(
self,
msg_fn: impl FnOnce() -> Err,
) -> <T as IntoIterator>::Itemwhere
Err: Display,
fn expect_element<Err>(
self,
msg_fn: impl FnOnce() -> Err,
) -> <T as IntoIterator>::Itemwhere
Err: Display,
Source§fn into_element(self) -> <T as IntoIterator>::Item
fn into_element(self) -> <T as IntoIterator>::Item
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<T, U> OverrideFrom<Option<&T>> for Uwhere
U: OverrideFrom<T>,
impl<T, U> OverrideFrom<Option<&T>> for Uwhere
U: OverrideFrom<T>,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ProgressEventTimestamp for T
impl<T> ProgressEventTimestamp for T
Source§impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
Source§fn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
RustType::from_proto
.Source§fn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
RustType::into_proto
.Source§impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
Source§fn plus_equals(&mut self, rhs: &&'a S)
fn plus_equals(&mut self, rhs: &&'a S)
std::ops::AddAssign
, for types that do not implement AddAssign
.Source§impl<I> ToStream<<I as IntoIterator>::Item> for I
impl<I> ToStream<<I as IntoIterator>::Item> for I
Source§fn to_stream<S>(
self,
scope: &mut S,
) -> StreamCore<S, Vec<<I as IntoIterator>::Item>>where
S: Scope,
fn to_stream<S>(
self,
scope: &mut S,
) -> StreamCore<S, Vec<<I as IntoIterator>::Item>>where
S: Scope,
Stream
. Read more