proof_of_sql/sql/proof_plans/
dyn_proof_plan.rs1use super::{
2 AggregateExec, EmptyExec, FilterExec, GroupByExec, LegacyFilterExec, ProjectionExec, SliceExec,
3 SortMergeJoinExec, TableExec, UnionExec,
4};
5use crate::{
6 base::{
7 database::{ColumnField, ColumnRef, LiteralValue, Table, TableEvaluation, TableRef},
8 map::{IndexMap, IndexSet},
9 proof::{PlaceholderResult, ProofError},
10 scalar::Scalar,
11 },
12 sql::{
13 proof::{
14 FinalRoundBuilder, FirstRoundBuilder, ProofPlan, ProverEvaluate, VerificationBuilder,
15 },
16 proof_exprs::{AliasedDynProofExpr, ColumnExpr, DynProofExpr, TableExpr},
17 AnalyzeResult,
18 },
19};
20use alloc::{boxed::Box, vec::Vec};
21use bumpalo::Bump;
22use serde::{Deserialize, Serialize};
23use sqlparser::ast::Ident;
24
25#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
27#[enum_dispatch::enum_dispatch]
28pub enum DynProofPlan {
29 Empty(EmptyExec),
31 Table(TableExec),
33 Projection(ProjectionExec),
38 GroupBy(GroupByExec),
48 Aggregate(AggregateExec),
59 LegacyFilter(LegacyFilterExec),
64 Filter(FilterExec),
70 Slice(SliceExec),
75 Union(UnionExec),
85 SortMergeJoin(SortMergeJoinExec),
91}
92
93impl DynProofPlan {
94 #[must_use]
96 pub fn new_empty() -> Self {
97 Self::Empty(EmptyExec::new())
98 }
99
100 #[must_use]
102 pub fn new_table(table_ref: TableRef, schema: Vec<ColumnField>) -> Self {
103 Self::Table(TableExec::new(table_ref, schema))
104 }
105
106 #[must_use]
108 pub fn new_projection(aliased_results: Vec<AliasedDynProofExpr>, input: DynProofPlan) -> Self {
109 Self::Projection(ProjectionExec::new(aliased_results, Box::new(input)))
110 }
111
112 #[must_use]
114 pub fn new_legacy_filter(
115 aliased_results: Vec<AliasedDynProofExpr>,
116 input: TableExpr,
117 filter_expr: DynProofExpr,
118 ) -> Self {
119 Self::LegacyFilter(LegacyFilterExec::new(aliased_results, input, filter_expr))
120 }
121
122 #[must_use]
124 pub fn try_new_group_by(
125 group_by_exprs: Vec<ColumnExpr>,
126 sum_expr: Vec<AliasedDynProofExpr>,
127 count_alias: Ident,
128 table: TableExpr,
129 where_clause: DynProofExpr,
130 ) -> Option<Self> {
131 GroupByExec::try_new(group_by_exprs, sum_expr, count_alias, table, where_clause)
132 .map(Self::GroupBy)
133 }
134
135 #[must_use]
137 pub fn try_new_aggregate(
138 group_by_exprs: Vec<AliasedDynProofExpr>,
139 sum_expr: Vec<AliasedDynProofExpr>,
140 count_alias: Ident,
141 input: DynProofPlan,
142 where_clause: DynProofExpr,
143 ) -> Option<Self> {
144 AggregateExec::try_new(
145 group_by_exprs,
146 sum_expr,
147 count_alias,
148 Box::new(input),
149 where_clause,
150 )
151 .map(Self::Aggregate)
152 }
153
154 #[must_use]
156 pub fn new_slice(input: DynProofPlan, skip: usize, fetch: Option<usize>) -> Self {
157 Self::Slice(SliceExec::new(Box::new(input), skip, fetch))
158 }
159
160 pub fn try_new_union(inputs: Vec<DynProofPlan>) -> AnalyzeResult<Self> {
162 UnionExec::try_new(inputs).map(Self::Union)
163 }
164
165 #[must_use]
167 pub fn new_filter(
168 aliased_results: Vec<AliasedDynProofExpr>,
169 input: DynProofPlan,
170 filter_expr: DynProofExpr,
171 ) -> Self {
172 Self::Filter(FilterExec::new(
173 aliased_results,
174 Box::new(input),
175 filter_expr,
176 ))
177 }
178
179 pub(crate) fn get_column_result_fields_as_references(&self) -> IndexSet<ColumnRef> {
181 self.get_column_result_fields()
182 .into_iter()
183 .map(|f| ColumnRef::new(TableRef::from_names(None, ""), f.name(), f.data_type()))
184 .collect()
185 }
186}