proof_of_sql/sql/postprocessing/
owned_table_postprocessing.rs1use super::{
2 GroupByPostprocessing, OrderByPostprocessing, PostprocessingResult, PostprocessingStep,
3 SelectPostprocessing, SlicePostprocessing,
4};
5use crate::base::{database::OwnedTable, scalar::Scalar};
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10pub enum OwnedTablePostprocessing {
11 Slice(SlicePostprocessing),
13 OrderBy(OrderByPostprocessing),
15 Select(SelectPostprocessing),
17 GroupBy(GroupByPostprocessing),
19}
20
21impl<S: Scalar> PostprocessingStep<S> for OwnedTablePostprocessing {
22 fn apply(&self, owned_table: OwnedTable<S>) -> PostprocessingResult<OwnedTable<S>> {
24 match self {
25 OwnedTablePostprocessing::Slice(slice_expr) => slice_expr.apply(owned_table),
26 OwnedTablePostprocessing::OrderBy(order_by_expr) => order_by_expr.apply(owned_table),
27 OwnedTablePostprocessing::Select(select_expr) => select_expr.apply(owned_table),
28 OwnedTablePostprocessing::GroupBy(group_by_expr) => group_by_expr.apply(owned_table),
29 }
30 }
31}
32
33impl OwnedTablePostprocessing {
34 #[must_use]
36 pub fn new_slice(slice_expr: SlicePostprocessing) -> Self {
37 Self::Slice(slice_expr)
38 }
39 #[must_use]
41 pub fn new_order_by(order_by_expr: OrderByPostprocessing) -> Self {
42 Self::OrderBy(order_by_expr)
43 }
44 #[must_use]
46 pub fn new_select(select_expr: SelectPostprocessing) -> Self {
47 Self::Select(select_expr)
48 }
49 #[must_use]
51 pub fn new_group_by(group_by_postprocessing: GroupByPostprocessing) -> Self {
52 Self::GroupBy(group_by_postprocessing)
53 }
54}
55
56pub fn apply_postprocessing_steps<S: Scalar>(
58 owned_table: OwnedTable<S>,
59 postprocessing_steps: &[OwnedTablePostprocessing],
60) -> PostprocessingResult<OwnedTable<S>> {
61 let mut current_table = owned_table;
63 for step in postprocessing_steps {
64 current_table = step.apply(current_table)?;
65 }
66 Ok(current_table)
67}