proof_of_sql/sql/proof_plans/
dyn_proof_plan.rs1use super::{
2 EmptyExec, FilterExec, GeneralizedFilterExec, GroupByExec, ProjectionExec, SliceExec,
3 SortMergeJoinExec, TableExec, 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 GeneralizedFilter(GeneralizedFilterExec),
61 Slice(SliceExec),
66 Union(UnionExec),
76 SortMergeJoin(SortMergeJoinExec),
82}
83
84impl DynProofPlan {
85 #[must_use]
87 pub fn new_empty() -> Self {
88 Self::Empty(EmptyExec::new())
89 }
90
91 #[must_use]
93 pub fn new_table(table_ref: TableRef, schema: Vec<ColumnField>) -> Self {
94 Self::Table(TableExec::new(table_ref, schema))
95 }
96
97 #[must_use]
99 pub fn new_projection(aliased_results: Vec<AliasedDynProofExpr>, input: DynProofPlan) -> Self {
100 Self::Projection(ProjectionExec::new(aliased_results, Box::new(input)))
101 }
102
103 #[must_use]
105 pub fn new_filter(
106 aliased_results: Vec<AliasedDynProofExpr>,
107 input: TableExpr,
108 filter_expr: DynProofExpr,
109 ) -> Self {
110 Self::Filter(FilterExec::new(aliased_results, input, filter_expr))
111 }
112
113 #[must_use]
115 pub fn new_group_by(
116 group_by_exprs: Vec<ColumnExpr>,
117 sum_expr: Vec<AliasedDynProofExpr>,
118 count_alias: Ident,
119 table: TableExpr,
120 where_clause: DynProofExpr,
121 ) -> Self {
122 Self::GroupBy(GroupByExec::new(
123 group_by_exprs,
124 sum_expr,
125 count_alias,
126 table,
127 where_clause,
128 ))
129 }
130
131 #[must_use]
133 pub fn new_slice(input: DynProofPlan, skip: usize, fetch: Option<usize>) -> Self {
134 Self::Slice(SliceExec::new(Box::new(input), skip, fetch))
135 }
136
137 pub fn try_new_union(inputs: Vec<DynProofPlan>) -> AnalyzeResult<Self> {
139 UnionExec::try_new(inputs).map(Self::Union)
140 }
141
142 #[must_use]
144 pub fn new_generalized_filter(
145 aliased_results: Vec<AliasedDynProofExpr>,
146 input: DynProofPlan,
147 filter_expr: DynProofExpr,
148 ) -> Self {
149 Self::GeneralizedFilter(GeneralizedFilterExec::new(
150 aliased_results,
151 Box::new(input),
152 filter_expr,
153 ))
154 }
155}