-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add `AliasedProvableExprPlan` and `AggregateFunctionExpr` - generalize `GroupByExpr`
- Loading branch information
Showing
12 changed files
with
252 additions
and
202 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
crates/proof-of-sql/src/sql/ast/aggregate_function_expr.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use super::ProvableExprPlan; | ||
use crate::base::commitment::Commitment; | ||
use proof_of_sql_parser::intermediate_ast::AggregationOperator; | ||
|
||
use super::{ProvableExpr, ProvableExprPlan}; | ||
use crate::{ | ||
base::{ | ||
commitment::Commitment, | ||
database::{Column, ColumnRef, ColumnType, CommitmentAccessor, DataAccessor}, | ||
proof::ProofError, | ||
}, | ||
sql::proof::{CountBuilder, ProofBuilder, VerificationBuilder}, | ||
}; | ||
use bumpalo::Bump; | ||
use serde::{Deserialize, Serialize}; | ||
use std::collections::HashSet; | ||
|
||
/// Provable aggregate function expression | ||
/// | ||
/// Currently it doesn't do much since aggregation logic is implemented elsewhere | ||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct AggregateFunctionExpr<C: Commitment> { | ||
op: AggregationOperator, | ||
expr: Box<ProvableExprPlan<C>>, | ||
} | ||
|
||
impl<C: Commitment> AggregateFunctionExpr<C> { | ||
/// Create a new aggregate function expression | ||
pub fn new(op: AggregationOperator, expr: Box<ProvableExprPlan<C>>) -> Self { | ||
Self { op, exprs } | ||
} | ||
} | ||
|
||
impl<C: Commitment> ProvableExpr<C> for NotExpr<C> { | ||
fn count(&self, builder: &mut CountBuilder) -> Result<(), ProofError> { | ||
Ok(()) | ||
} | ||
|
||
fn data_type(&self) -> ColumnType { | ||
match self.op { | ||
AggregationOperator::Count => ColumnType::BigInt, | ||
AggregationOperator::Sum => self.expr.data_type(), | ||
_ => todo!("Aggregation operator not supported here yet"), | ||
} | ||
} | ||
|
||
#[tracing::instrument(name = "AggregateFunctionExpr::result_evaluate", level = "debug", skip_all)] | ||
fn result_evaluate<'a>( | ||
&self, | ||
table_length: usize, | ||
alloc: &'a Bump, | ||
accessor: &'a dyn DataAccessor<C::Scalar>, | ||
) -> Column<'a, C::Scalar> { | ||
self.expr.result_evaluate(table_length, alloc, accessor) | ||
} | ||
|
||
#[tracing::instrument(name = "AggregateFunctionExpr::prover_evaluate", level = "debug", skip_all)] | ||
fn prover_evaluate<'a>( | ||
&self, | ||
builder: &mut ProofBuilder<'a, C::Scalar>, | ||
alloc: &'a Bump, | ||
accessor: &'a dyn DataAccessor<C::Scalar>, | ||
) -> Column<'a, C::Scalar> { | ||
self.expr.prover_evaluate(builder, alloc, accessor) | ||
} | ||
|
||
fn verifier_evaluate( | ||
&self, | ||
builder: &mut VerificationBuilder<C>, | ||
accessor: &dyn CommitmentAccessor<C>, | ||
) -> Result<C::Scalar, ProofError> { | ||
self.expr.verifier_evaluate(builder, accessor) | ||
} | ||
|
||
fn get_column_references(&self, columns: &mut HashSet<ColumnRef>) { | ||
self.expr.get_column_references(columns) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
crates/proof-of-sql/src/sql/ast/aliased_provable_expr_plan.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use super::ProvableExprPlan; | ||
use crate::base::commitment::Commitment; | ||
use proof_of_sql_parser::Identifier; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// A `ProvableExprPlan` with an alias. | ||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct AliasedProvableExprPlan<C: Commitment> { | ||
pub expr: ProvableExprPlan<C>, | ||
pub alias: Identifier, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.