use crate::{
db::diagnostics::{ExecutionMetrics, ExecutionTrace},
value::Value,
};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct GroupedRow {
group_key: Vec<Value>,
aggregate_values: Vec<Value>,
}
impl GroupedRow {
#[must_use]
pub const fn new(group_key: Vec<Value>, aggregate_values: Vec<Value>) -> Self {
Self {
group_key,
aggregate_values,
}
}
#[must_use]
pub fn from_parts<I, J>(group_key: I, aggregate_values: J) -> Self
where
I: IntoIterator<Item = Value>,
J: IntoIterator<Item = Value>,
{
Self {
group_key: group_key.into_iter().collect(),
aggregate_values: aggregate_values.into_iter().collect(),
}
}
#[must_use]
pub const fn group_key(&self) -> &[Value] {
self.group_key.as_slice()
}
#[must_use]
pub const fn aggregate_values(&self) -> &[Value] {
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)
}
}