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::{ColumnField, ColumnRef, OwnedTable, Table, TableEvaluation, TableRef},
8 map::{IndexMap, IndexSet},
9 proof::ProofError,
10 scalar::Scalar,
11 },
12 sql::{
13 proof::{
14 FinalRoundBuilder, FirstRoundBuilder, ProofPlan, ProverEvaluate, VerificationBuilder,
15 },
16 proof_exprs::{AliasedDynProofExpr, ColumnExpr, DynProofExpr, TableExpr},
17 },
18};
19use alloc::{boxed::Box, vec::Vec};
20use bumpalo::Bump;
21use serde::{Deserialize, Serialize};
22use sqlparser::ast::Ident;
23
24#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
26#[enum_dispatch::enum_dispatch]
27pub enum DynProofPlan {
28 Empty(EmptyExec),
30 Table(TableExec),
32 Projection(ProjectionExec),
37 GroupBy(GroupByExec),
47 Filter(FilterExec),
52 Slice(SliceExec),
57 Union(UnionExec),
67 SortMergeJoin(SortMergeJoinExec),
73}
74
75impl DynProofPlan {
76 #[must_use]
78 pub fn new_empty() -> Self {
79 Self::Empty(EmptyExec::new())
80 }
81
82 #[must_use]
84 pub fn new_table(table_ref: TableRef, schema: Vec<ColumnField>) -> Self {
85 Self::Table(TableExec::new(table_ref, schema))
86 }
87
88 #[must_use]
90 pub fn new_projection(aliased_results: Vec<AliasedDynProofExpr>, input: DynProofPlan) -> Self {
91 Self::Projection(ProjectionExec::new(aliased_results, Box::new(input)))
92 }
93
94 #[must_use]
96 pub fn new_filter(
97 aliased_results: Vec<AliasedDynProofExpr>,
98 input: TableExpr,
99 filter_expr: DynProofExpr,
100 ) -> Self {
101 Self::Filter(FilterExec::new(aliased_results, input, filter_expr))
102 }
103
104 #[must_use]
106 pub fn new_group_by(
107 group_by_exprs: Vec<ColumnExpr>,
108 sum_expr: Vec<AliasedDynProofExpr>,
109 count_alias: Ident,
110 table: TableExpr,
111 where_clause: DynProofExpr,
112 ) -> Self {
113 Self::GroupBy(GroupByExec::new(
114 group_by_exprs,
115 sum_expr,
116 count_alias,
117 table,
118 where_clause,
119 ))
120 }
121
122 #[must_use]
124 pub fn new_slice(input: DynProofPlan, skip: usize, fetch: Option<usize>) -> Self {
125 Self::Slice(SliceExec::new(Box::new(input), skip, fetch))
126 }
127
128 #[must_use]
130 pub fn new_union(inputs: Vec<DynProofPlan>, schema: Vec<ColumnField>) -> Self {
131 Self::Union(UnionExec::new(inputs, schema))
132 }
133}