pub struct Vector { /* private fields */ }Expand description
A type, a length, a validity representation and some data.
Implementations§
Source§impl Vector
impl Vector
Sourcepub fn flat(ty: LogicalType, data: Data) -> Result<Self>
pub fn flat(ty: LogicalType, data: Data) -> Result<Self>
A flat vector of data, all valid.
§Errors
If the data’s physical layout is not the one the type calls for. That check is here rather than left to the caller because a vector whose type and layout disagree is a wrong answer waiting to be read out, and it costs one comparison at construction to prevent.
Sourcepub fn from_values(ty: LogicalType, values: &[Value]) -> Result<Self>
pub fn from_values(ty: LogicalType, values: &[Value]) -> Result<Self>
A flat vector built from single values, with the nulls among them turning into validity.
The slow way in, and the only way in that anything outside this crate has. It is what an
INSERT, a VALUES clause and a test build a column with, all of which arrive holding
values rather than a run of i32. Nothing on a scan path calls it: a scan produces a run of
data directly and hands it to Self::flat.
§Errors
If a value is not one the type can hold, or if the type is one that cannot be stored flat yet, which today means the nested types.
Sourcepub fn constant(ty: LogicalType, value: Value, len: usize) -> Self
pub fn constant(ty: LogicalType, value: Value, len: usize) -> Self
A vector of len copies of one value.
Costs one value regardless of the length, which is what makes a literal in a predicate free and what makes a projection of a constant free.
Sourcepub fn sequence(start: i64, step: i64, len: usize) -> Self
pub fn sequence(start: i64, step: i64, len: usize) -> Self
A vector of len values starting at start and stepping by step.
This is what a row identifier column is, and it costs sixteen bytes rather than eight kilobytes. A scan that produces row ids for a later fetch produces one of these.
Sourcepub fn dictionary(codes: Vec<u32>, values: Vector) -> Result<Self>
pub fn dictionary(codes: Vec<u32>, values: Vector) -> Result<Self>
A vector of codes into a smaller vector of distinct values.
The form the whole M3 thesis rests on. A dictionary vector handed to a group by is an integer column, and an aggregate over one is an aggregate over integers no matter what the logical type says.
§Errors
If any code is past the end of the value vector.
Sourcepub fn with_validity(self, validity: Validity) -> Self
pub fn with_validity(self, validity: Validity) -> Self
The same vector with a different validity.
Sourcepub fn logical_type(&self) -> &LogicalType
pub fn logical_type(&self) -> &LogicalType
What kind of values these are.
Sourcepub fn data(&self) -> Option<&Data>
pub fn data(&self) -> Option<&Data>
The data, for a flat vector, and None for any other form.
A kernel that wants a slice asks for it and takes the flat path if it gets one. A kernel
that can do better on a constant or a dictionary checks Self::form first.
Sourcepub fn value_at(&self, index: usize) -> Value
pub fn value_at(&self, index: usize) -> Value
The value at index, as a single value.
This is the slow path on purpose. It is what a result set is read out with and what a test asserts on, and an operator that calls it per row is an operator that has already lost the argument the vector interface exists to win.
Sourcepub fn flatten(&self) -> Result<Self>
pub fn flatten(&self) -> Result<Self>
The same values in flat form.
Flattening a vector that is already flat is free. Flattening any other form costs a copy, which is exactly why the other forms exist and why nothing on the hot path should call this. It is here for the operators that genuinely cannot do better and for the tests that check the other forms against it.
§Errors
If the type is one this crate cannot store flat yet, which today means the nested types.