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 constant_value(&self) -> Option<&Value>
pub fn constant_value(&self) -> Option<&Value>
The one value, for a constant vector, and None for any other form.
A kernel comparing a column against a literal wants the literal once rather than 1024
times, and Self::value_at on a constant clones it on every call because it has to be
able to hand back a Value for any form. This is the accessor that lets the specialized
path hoist the clone out of the loop.
Sourcepub fn dictionary_parts(&self) -> Option<(&[u32], &Self)>
pub fn dictionary_parts(&self) -> Option<(&[u32], &Self)>
The codes and the values, for a dictionary vector, and None for any other form.
The reason a kernel needs this rather than reading the dictionary through
Self::value_at is the entire argument for the form existing. A filter against a
dictionary column of 1024 rows and 40 distinct values is 40 comparisons and 1024 lookups,
not 1024 comparisons, and there is no way to write that loop without seeing the codes.
Note what the validity of the returned vector means. A dictionary keeps its nulls in the
vector it points at, and the dictionary’s own validity says nothing about them, so a caller
deciding whether row i is null has to ask the value vector about codes[i] rather than
asking this vector about i. Self::flatten has the same note on it for the same
reason, because getting this wrong is a null that survives being selected and comes out as
a zero.
Sourcepub fn sequence_parts(&self) -> Option<(i64, i64)>
pub fn sequence_parts(&self) -> Option<(i64, i64)>
The start and the step, for a sequence vector, and None for any other form.
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.
Sourcepub fn gather(&self, indices: &[u32]) -> Result<Self>
pub fn gather(&self, indices: &[u32]) -> Result<Self>
The values at the given positions, copied, in a form that does not point back at this vector.
This is the copying counterpart to Self::dictionary, and the two are the two halves of
the decision spec/07-execution.md section 7.1 describes. Which half is right is measured
rather than argued, and Chunk::compact is where the measurement
is written down.
A dictionary chain is walked to its leaf first and the codes composed on the way down, so the
copy runs once over the data rather than once per level, and a position that is null at any
level comes out null here. The copy is a typed loop per physical layout rather than a Value
per row, which is the whole point of it and is what Self::flatten now goes through too.
§Errors
If the type has no flat layout, which today means the nested types.