pub struct RelationDesc {
typ: SqlRelationType,
metadata: BTreeMap<ColumnIndex, ColumnMetadata>,
}Expand description
A description of the shape of a relation.
It bundles a SqlRelationType with ColumnMetadata for each column in
the relation.
§Examples
A RelationDescs is typically constructed via its builder API:
use mz_repr::{SqlColumnType, RelationDesc, SqlScalarType};
let desc = RelationDesc::builder()
.with_column("id", SqlScalarType::Int64.nullable(false))
.with_column("price", SqlScalarType::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);Next to the SqlRelationType we maintain a map of ColumnIndex to
ColumnMetadata, where ColumnIndex is a stable identifier for a
column throughout the lifetime of the relation. This allows a
RelationDesc to represent a projection over a version of itself.
use std::collections::BTreeSet;
use mz_repr::{ColumnIndex, RelationDesc, SqlScalarType};
let desc = RelationDesc::builder()
.with_column("name", SqlScalarType::String.nullable(false))
.with_column("email", SqlScalarType::String.nullable(false))
.finish();
// Project away the second column.
let demands = BTreeSet::from([1]);
let proj = desc.apply_demand(&demands);
// We projected away the first column.
assert!(!proj.contains_index(&ColumnIndex::from_raw(0)));
// But retained the second.
assert!(proj.contains_index(&ColumnIndex::from_raw(1)));
// The underlying `SqlRelationType` also contains a single column.
assert_eq!(proj.typ().arity(), 1);To maintain this stable mapping and track the lifetime of a column (e.g.
when adding or dropping a column) we use ColumnMetadata. It maintains
the index in SqlRelationType that corresponds to a given column, and the
version at which this column was added or dropped.
Fields§
§typ: SqlRelationType§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 len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of columns in this RelationDesc.
Sourcepub fn new<I, N>(typ: SqlRelationType, names: I) -> Self
pub fn new<I, N>(typ: SqlRelationType, names: I) -> Self
Constructs a new RelationDesc from a SqlRelationType and an iterator
over column names.
§Panics
Panics if the arity of the SqlRelationType 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) -> &SqlRelationType
pub fn typ(&self) -> &SqlRelationType
Returns the relation type underlying this relation description.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&ColumnName, &SqlColumnType)>
pub fn iter(&self) -> impl Iterator<Item = (&ColumnName, &SqlColumnType)>
Returns an iterator over the columns in this relation.
Sourcepub fn iter_types(&self) -> impl Iterator<Item = &SqlColumnType>
pub fn iter_types(&self) -> impl Iterator<Item = &SqlColumnType>
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_all(
&self,
) -> impl Iterator<Item = (&ColumnIndex, &ColumnName, &SqlColumnType)>
pub fn iter_all( &self, ) -> impl Iterator<Item = (&ColumnIndex, &ColumnName, &SqlColumnType)>
Returns an iterator over the columns in this relation, with all their metadata.
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 contains_index(&self, idx: &ColumnIndex) -> bool
pub fn contains_index(&self, idx: &ColumnIndex) -> bool
Returns whether this RelationDesc contains a column at the specified index.
Sourcepub fn get_by_name(&self, name: &ColumnName) -> Option<(usize, &SqlColumnType)>
pub fn get_by_name(&self, name: &ColumnName) -> Option<(usize, &SqlColumnType)>
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
Gets the name of the ith column.
§Panics
Panics if i is not a valid column index.
TODO(parkmycar): Migrate all uses of this to RelationDesc::get_name_idx.
Sourcepub fn get_name_idx(&self, idx: &ColumnIndex) -> &ColumnName
pub fn get_name_idx(&self, idx: &ColumnIndex) -> &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_type(&self, idx: &ColumnIndex) -> &SqlColumnType
pub fn get_type(&self, idx: &ColumnIndex) -> &SqlColumnType
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 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.
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 ith column of self.
n.b. The only constraint MZ currently supports in NOT NULL, but this structure will be simple to extend.
Sourcepub fn apply_demand(&self, demands: &BTreeSet<usize>) -> RelationDesc
pub fn apply_demand(&self, demands: &BTreeSet<usize>) -> RelationDesc
Creates a new RelationDesc retaining only the columns specified in demands.
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, SqlColumnType)
type Item = (ColumnName, SqlColumnType)
Source§type IntoIter = Box<dyn Iterator<Item = (ColumnName, SqlColumnType)>>
type IntoIter = Box<dyn Iterator<Item = (ColumnName, SqlColumnType)>>
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 Schema<Row> for RelationDesc
impl Schema<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§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§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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§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::RequestSource§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> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
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<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
Source§fn decompression(self) -> Decompression<Self>where
Self: Sized,
fn decompression(self) -> Decompression<Self>where
Self: Sized,
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
Source§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
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