use crate::{
db::diagnostics::{ExecutionMetrics, ExecutionTrace},
value::OutputValue,
};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct GroupedRow {
group_key: Vec<OutputValue>,
aggregate_values: Vec<OutputValue>,
}
impl GroupedRow {
#[must_use]
pub fn new<I, J, K, L>(group_key: I, aggregate_values: J) -> Self
where
I: IntoIterator<Item = K>,
J: IntoIterator<Item = L>,
K: Into<OutputValue>,
L: Into<OutputValue>,
{
Self {
group_key: group_key.into_iter().map(Into::into).collect(),
aggregate_values: aggregate_values.into_iter().map(Into::into).collect(),
}
}
#[must_use]
pub const fn group_key(&self) -> &[OutputValue] {
self.group_key.as_slice()
}
#[must_use]
pub const fn aggregate_values(&self) -> &[OutputValue] {
self.aggregate_values.as_slice()
}
}
#[derive(Clone, Debug)]
pub struct PagedGroupedExecution {
rows: Vec<GroupedRow>,
continuation_cursor: Option<Vec<u8>>,
}
impl PagedGroupedExecution {
#[must_use]
pub const fn new(rows: Vec<GroupedRow>, continuation_cursor: Option<Vec<u8>>) -> Self {
Self {
rows,
continuation_cursor,
}
}
#[must_use]
pub const fn rows(&self) -> &[GroupedRow] {
self.rows.as_slice()
}
#[must_use]
pub fn continuation_cursor(&self) -> Option<&[u8]> {
self.continuation_cursor.as_deref()
}
#[must_use]
pub fn into_parts(self) -> (Vec<GroupedRow>, Option<Vec<u8>>) {
(self.rows, self.continuation_cursor)
}
}
#[derive(Clone, Debug)]
pub struct PagedGroupedExecutionWithTrace {
rows: Vec<GroupedRow>,
continuation_cursor: Option<Vec<u8>>,
execution_trace: Option<ExecutionTrace>,
}
impl PagedGroupedExecutionWithTrace {
#[must_use]
pub const fn new(
rows: Vec<GroupedRow>,
continuation_cursor: Option<Vec<u8>>,
execution_trace: Option<ExecutionTrace>,
) -> Self {
Self {
rows,
continuation_cursor,
execution_trace,
}
}
#[must_use]
pub const fn rows(&self) -> &[GroupedRow] {
self.rows.as_slice()
}
#[must_use]
pub fn continuation_cursor(&self) -> Option<&[u8]> {
self.continuation_cursor.as_deref()
}
#[must_use]
pub const fn execution_trace(&self) -> Option<&ExecutionTrace> {
self.execution_trace.as_ref()
}
#[must_use]
pub fn execution_metrics(&self) -> Option<ExecutionMetrics> {
self.execution_trace.as_ref().map(ExecutionTrace::metrics)
}
#[must_use]
pub fn into_execution(self) -> PagedGroupedExecution {
PagedGroupedExecution {
rows: self.rows,
continuation_cursor: self.continuation_cursor,
}
}
#[must_use]
pub fn into_parts(self) -> (Vec<GroupedRow>, Option<Vec<u8>>, Option<ExecutionTrace>) {
(self.rows, self.continuation_cursor, self.execution_trace)
}
}