Skip to main content

QueryResult

Struct QueryResult 

Source
pub struct QueryResult {
    pub columns: Vec<String>,
    pub rows: Vec<Row>,
    /* private fields */
}
Expand description

Query result containing column names and rows.

Invariant: rows.len() == row_group_keys.len(). Always. Mutating either field directly will violate this; use the helper methods (add_row, add_aggregate_row, truncate, sort_by, etc.) that keep both vectors in lockstep. The invariant is enforced at runtime with assert_eq! inside sort_by.

Fields§

§columns: Vec<String>

Column names.

§rows: Vec<Row>

Result rows.

Implementations§

Source§

impl QueryResult

Source

pub const fn new(columns: Vec<String>) -> Self

Create a new empty result.

Source

pub fn add_row(&mut self, row: Row)

Add a row to the result with no GROUP BY context (non-aggregate path). The sidecar (row_group_keys) records None for this row, so the text renderer applies no per-currency quantization (issue #988). Aggregate paths must use Self::add_aggregate_row instead.

Source

pub fn add_aggregate_row(&mut self, row: Row, group_key: Vec<Value>)

Add a row produced by aggregation, recording the GROUP BY key values alongside it. The renderer consults the key to quantize numeric aggregates against the per-currency display precision (issue #988).

Multi-column GROUP BY note: when several columns are grouped (e.g. GROUP BY account, currency), the entire key is preserved here. The renderer’s currency-hint extraction (currency_hint_for_row in rustledger/src/cmd/query/output.rs) takes the first currency-shaped string in iteration order — so put the currency column first if both are currency-shaped, which is rare in practice but possible.

Source

pub fn group_key(&self, row_idx: usize) -> Option<&[Value]>

Get the GROUP BY key for a given row, if it was produced by aggregation. Returns None for non-aggregate rows or when the row index is out of range. This is the public read-side of the row_group_keys sidecar — prefer it over reaching into the field directly.

Returns &[Value] rather than &Vec<Value> so callers aren’t tied to the specific container type.

Source

pub fn has_aggregate_rows(&self) -> bool

Whether any row in the result was produced by aggregation. Lets downstream renderers short-circuit per-row hint lookups when the cache would be all None anyway (issue #988 follow-up).

Source

pub fn truncate(&mut self, len: usize)

Truncate to the first len rows, keeping row_group_keys in lockstep so the parallel-vector invariant survives LIMIT.

Source

pub fn sort_by<F>(&mut self, compare: F)
where F: FnMut(&Row, &Row) -> Ordering,

Sort rows by a comparator, keeping row_group_keys in lockstep. Pair-sort prevents the sidecar from desynchronizing after ORDER BY (otherwise text rendering would apply the wrong currency hint to a row).

Source

pub const fn len(&self) -> usize

Number of rows.

Source

pub const fn is_empty(&self) -> bool

Whether the result is empty.

Trait Implementations§

Source§

impl Clone for QueryResult

Source§

fn clone(&self) -> QueryResult

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QueryResult

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> OrderedSeq<'_, T> for T
where T: Clone,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<'p, T> Seq<'p, T> for T
where T: Clone,

Source§

type Item<'a> = &'a T where T: 'a

The item yielded by the iterator.
Source§

type Iter<'a> = Once<&'a T> where T: 'a

An iterator over the items within this container, by reference.
Source§

fn seq_iter(&self) -> <T as Seq<'p, T>>::Iter<'_>

Iterate over the elements of the container.
Source§

fn contains(&self, val: &T) -> bool
where T: PartialEq,

Check whether an item is contained within this sequence.
Source§

fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>
where 'p: 'b,

Convert an item of the sequence into a MaybeRef.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.