Struct mz_repr::RelationDesc
source · 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
§type Parameters = ()
type Parameters = ()
arbitrary_with
accepts for configuration
of the generated Strategy
. Parameters must implement Default
.§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
§type Item = (ColumnName, ColumnType)
type Item = (ColumnName, ColumnType)
§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
§type ArrowColumn = StructArray
type ArrowColumn = StructArray
§type Statistics = OptionStats<StructStats>
type Statistics = OptionStats<StructStats>
§type Decoder = RowColumnarDecoder
type Decoder = RowColumnarDecoder
T
from Self::ArrowColumn
.§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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default 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