proof_of_sql/sql/proof_plans/
dyn_proof_plan.rs1use super::{
2    EmptyExec, FilterExec, GroupByExec, ProjectionExec, SliceExec, SortMergeJoinExec, TableExec,
3    UnionExec,
4};
5use crate::{
6    base::{
7        database::{
8            ColumnField, ColumnRef, LiteralValue, OwnedTable, Table, TableEvaluation, TableRef,
9        },
10        map::{IndexMap, IndexSet},
11        proof::{PlaceholderResult, ProofError},
12        scalar::Scalar,
13    },
14    sql::{
15        proof::{
16            FinalRoundBuilder, FirstRoundBuilder, ProofPlan, ProverEvaluate, VerificationBuilder,
17        },
18        proof_exprs::{AliasedDynProofExpr, ColumnExpr, DynProofExpr, TableExpr},
19        AnalyzeResult,
20    },
21};
22use alloc::{boxed::Box, vec::Vec};
23use bumpalo::Bump;
24use serde::{Deserialize, Serialize};
25use sqlparser::ast::Ident;
26
27#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
29#[enum_dispatch::enum_dispatch]
30pub enum DynProofPlan {
31    Empty(EmptyExec),
33    Table(TableExec),
35    Projection(ProjectionExec),
40    GroupBy(GroupByExec),
50    Filter(FilterExec),
55    Slice(SliceExec),
60    Union(UnionExec),
70    SortMergeJoin(SortMergeJoinExec),
76}
77
78impl DynProofPlan {
79    #[must_use]
81    pub fn new_empty() -> Self {
82        Self::Empty(EmptyExec::new())
83    }
84
85    #[must_use]
87    pub fn new_table(table_ref: TableRef, schema: Vec<ColumnField>) -> Self {
88        Self::Table(TableExec::new(table_ref, schema))
89    }
90
91    #[must_use]
93    pub fn new_projection(aliased_results: Vec<AliasedDynProofExpr>, input: DynProofPlan) -> Self {
94        Self::Projection(ProjectionExec::new(aliased_results, Box::new(input)))
95    }
96
97    #[must_use]
99    pub fn new_filter(
100        aliased_results: Vec<AliasedDynProofExpr>,
101        input: TableExpr,
102        filter_expr: DynProofExpr,
103    ) -> Self {
104        Self::Filter(FilterExec::new(aliased_results, input, filter_expr))
105    }
106
107    #[must_use]
109    pub fn new_group_by(
110        group_by_exprs: Vec<ColumnExpr>,
111        sum_expr: Vec<AliasedDynProofExpr>,
112        count_alias: Ident,
113        table: TableExpr,
114        where_clause: DynProofExpr,
115    ) -> Self {
116        Self::GroupBy(GroupByExec::new(
117            group_by_exprs,
118            sum_expr,
119            count_alias,
120            table,
121            where_clause,
122        ))
123    }
124
125    #[must_use]
127    pub fn new_slice(input: DynProofPlan, skip: usize, fetch: Option<usize>) -> Self {
128        Self::Slice(SliceExec::new(Box::new(input), skip, fetch))
129    }
130
131    pub fn try_new_union(inputs: Vec<DynProofPlan>) -> AnalyzeResult<Self> {
133        UnionExec::try_new(inputs).map(Self::Union)
134    }
135}