proof_of_sql/sql/proof_plans/
dyn_proof_plan.rs1use super::{
2 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 LegacyFilter(LegacyFilterExec),
53 Filter(FilterExec),
59 Slice(SliceExec),
64 Union(UnionExec),
74 SortMergeJoin(SortMergeJoinExec),
80}
81
82impl DynProofPlan {
83 #[must_use]
85 pub fn new_empty() -> Self {
86 Self::Empty(EmptyExec::new())
87 }
88
89 #[must_use]
91 pub fn new_table(table_ref: TableRef, schema: Vec<ColumnField>) -> Self {
92 Self::Table(TableExec::new(table_ref, schema))
93 }
94
95 #[must_use]
97 pub fn new_projection(aliased_results: Vec<AliasedDynProofExpr>, input: DynProofPlan) -> Self {
98 Self::Projection(ProjectionExec::new(aliased_results, Box::new(input)))
99 }
100
101 #[must_use]
103 pub fn new_legacy_filter(
104 aliased_results: Vec<AliasedDynProofExpr>,
105 input: TableExpr,
106 filter_expr: DynProofExpr,
107 ) -> Self {
108 Self::LegacyFilter(LegacyFilterExec::new(aliased_results, input, filter_expr))
109 }
110
111 #[must_use]
113 pub fn try_new_group_by(
114 group_by_exprs: Vec<ColumnExpr>,
115 sum_expr: Vec<AliasedDynProofExpr>,
116 count_alias: Ident,
117 table: TableExpr,
118 where_clause: DynProofExpr,
119 ) -> Option<Self> {
120 GroupByExec::try_new(group_by_exprs, sum_expr, count_alias, table, where_clause)
121 .map(Self::GroupBy)
122 }
123
124 #[must_use]
126 pub fn new_slice(input: DynProofPlan, skip: usize, fetch: Option<usize>) -> Self {
127 Self::Slice(SliceExec::new(Box::new(input), skip, fetch))
128 }
129
130 pub fn try_new_union(inputs: Vec<DynProofPlan>) -> AnalyzeResult<Self> {
132 UnionExec::try_new(inputs).map(Self::Union)
133 }
134
135 #[must_use]
137 pub fn new_filter(
138 aliased_results: Vec<AliasedDynProofExpr>,
139 input: DynProofPlan,
140 filter_expr: DynProofExpr,
141 ) -> Self {
142 Self::Filter(FilterExec::new(
143 aliased_results,
144 Box::new(input),
145 filter_expr,
146 ))
147 }
148}