Struct repr::RelationDesc [−][src]
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 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 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
Constructs a new RelationDesc
that represents the empty relation
with no columns and no keys.
pub 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>,
Concatenates a RelationDesc
onto the end of this RelationDesc
.
pub 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.
Drops all existing keys.
pub 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
.
Returns the relation type underlying this relation description.
Returns an iterator over the columns in this relation.
Returns an iterator over the types of the columns in this relation.
Returns an iterator over the names of the columns in this relation.
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.
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.
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
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>,
Deserialize this value from the given Serde deserializer. Read more
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?
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
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
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more