-
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.
feat: add aggregation-related intermediate AST conversions
- add `AggregateExpr` which allows expressions such as `sum(a+b)` to become `ProvableExprPlan` - allow `Expression` -> `ProvableExprPlan` for aggregations
- Loading branch information
Showing
7 changed files
with
159 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
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 proof_of_sql_parser::intermediate_ast::AggregationOperator; | ||
use serde::{Deserialize, Serialize}; | ||
use std::collections::HashSet; | ||
|
||
/// Provable aggregate expression | ||
/// | ||
/// Currently it doesn't do much since aggregation logic is implemented elsewhere | ||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct AggregateExpr<C: Commitment> { | ||
op: AggregationOperator, | ||
expr: Box<ProvableExprPlan<C>>, | ||
} | ||
|
||
impl<C: Commitment> AggregateExpr<C> { | ||
/// Create a new aggregate expression | ||
pub fn new(op: AggregationOperator, expr: Box<ProvableExprPlan<C>>) -> Self { | ||
Self { op, expr } | ||
} | ||
} | ||
|
||
impl<C: Commitment> ProvableExpr<C> for AggregateExpr<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 = "AggregateExpr::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 = "AggregateExpr::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) | ||
} | ||
} |
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
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