Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: proof_of_sql_parser::intermediate_ast::ResourceId with sqlparser::ast::ObjectName in the proof-of-sql crate #449

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions crates/proof-of-sql/benches/scaffold/benchmark_accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'a, C: Commitment> BenchmarkAccessor<'a, C> {
setup: &C::PublicSetup<'_>,
) {
self.table_schemas.insert(
table_ref,
table_ref.clone(),
columns
.iter()
.map(|(id, col)| (id.clone(), col.column_type()))
Expand All @@ -44,15 +44,17 @@ impl<'a, C: Commitment> BenchmarkAccessor<'a, C> {
let mut length = None;
for (column, commitment) in columns.iter().zip(commitments) {
self.columns.insert(
ColumnRef::new(table_ref, column.0.clone(), column.1.column_type()),
ColumnRef::new(&table_ref, column.0.clone(), column.1.column_type()),
column.1,
);
self.commitments.insert(
ColumnRef::new(table_ref, column.0.clone(), column.1.column_type()),
ColumnRef::new(&table_ref, column.0.clone(), column.1.column_type()),
commitment,
);
self.column_types
.insert((table_ref, column.0.clone()), column.1.column_type());
self.column_types.insert(
(table_ref.clone(), column.0.clone()),
column.1.column_type(),
);

if let Some(len) = length {
assert!(len == column.1.len());
Expand All @@ -76,10 +78,10 @@ impl<C: Commitment> MetadataAccessor for BenchmarkAccessor<'_, C> {
/// # Panics
///
/// Will panic if the table reference does not exist in the lengths map.
fn get_length(&self, table_ref: TableRef) -> usize {
fn get_length(&self, table_ref: &TableRef) -> usize {
*self.lengths.get(&table_ref).unwrap()
}
fn get_offset(&self, _table_ref: TableRef) -> usize {
fn get_offset(&self, _table_ref: &TableRef) -> usize {
0
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/proof-of-sql/benches/scaffold/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use benchmark_accessor::BenchmarkAccessor;
pub mod querys;
mod random_util;
use random_util::{generate_random_columns, OptionalRandBound};

use sqlparser::ast::Ident;
/// # Panics
///
/// Will panic if:
Expand All @@ -33,7 +33,8 @@ fn scaffold<'a, CP: CommitmentEvaluationProof>(
&generate_random_columns(alloc, rng, columns, size),
prover_setup,
);
let query = QueryExpr::try_new(query.parse().unwrap(), "bench".into(), accessor).unwrap();
let query =
QueryExpr::try_new(query.parse().unwrap(), Some(Ident::new("bench")), accessor).unwrap();
let result = VerifiableQueryResult::new(query.proof_expr(), accessor, prover_setup);
(query, result)
}
Expand Down
8 changes: 5 additions & 3 deletions crates/proof-of-sql/examples/albums/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use arrow_csv::{infer_schema_from_files, ReaderBuilder};
use proof_of_sql::{
base::database::{
arrow_schema_utility::get_posql_compatible_schema, OwnedTable, OwnedTableTestAccessor,
TestAccessor,
TableRef, TestAccessor,
},
proof_primitive::dory::{
DynamicDoryEvaluationProof, ProverSetup, PublicParameters, VerifierSetup,
Expand All @@ -19,6 +19,7 @@ use proof_of_sql::{
},
};
use rand::{rngs::StdRng, SeedableRng};
use sqlparser::ast::Ident;
use std::{fs::File, time::Instant};

// We generate the public parameters and the setups used by the prover and verifier for the Dory PCS.
Expand All @@ -38,7 +39,8 @@ fn prove_and_verify_query(
// Parse the query:
println!("Parsing the query: {sql}...");
let now = Instant::now();
let query_plan = QueryExpr::try_new(sql.parse().unwrap(), "albums".into(), accessor).unwrap();
let query_plan =
QueryExpr::try_new(sql.parse().unwrap(), Some(Ident::new("albums")), accessor).unwrap();
println!("Done in {} ms.", now.elapsed().as_secs_f64() * 1000.);

// Generate the proof and result:
Expand Down Expand Up @@ -87,7 +89,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
"albums.collection".parse().unwrap(),
&TableRef::from(&["albums", "collection"]),
OwnedTable::try_from(albums_batch).unwrap(),
0,
);
Expand Down
8 changes: 5 additions & 3 deletions crates/proof-of-sql/examples/avocado-prices/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use arrow::datatypes::SchemaRef;
use arrow_csv::{infer_schema_from_files, ReaderBuilder};
use proof_of_sql::{
base::database::{OwnedTable, OwnedTableTestAccessor},
base::database::{OwnedTable, OwnedTableTestAccessor, TableRef},
proof_primitive::dory::{
DynamicDoryEvaluationProof, ProverSetup, PublicParameters, VerifierSetup,
},
Expand All @@ -15,6 +15,7 @@ use proof_of_sql::{
},
};
use rand::{rngs::StdRng, SeedableRng};
use sqlparser::ast::Ident;
use std::{fs::File, time::Instant};

// We generate the public parameters and the setups used by the prover and verifier for the Dory PCS.
Expand Down Expand Up @@ -42,7 +43,8 @@ fn prove_and_verify_query(
// Parse the query:
println!("Parsing the query: {sql}...");
let now = Instant::now();
let query_plan = QueryExpr::try_new(sql.parse().unwrap(), "avocado".into(), accessor).unwrap();
let query_plan =
QueryExpr::try_new(sql.parse().unwrap(), Some(Ident::new("avocado")), accessor).unwrap();
println!("Done in {} ms.", now.elapsed().as_secs_f64() * 1000.);

// Generate the proof and result:
Expand Down Expand Up @@ -88,7 +90,7 @@ fn main() {

// Load the table into an "Accessor" so that the prover and verifier can access the data/commitments.
let accessor = OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_from_table(
"avocado.prices".parse().unwrap(),
&TableRef::from(&["avocado", "prices"]),
OwnedTable::try_from(data_batch).unwrap(),
0,
&prover_setup,
Expand Down
9 changes: 5 additions & 4 deletions crates/proof-of-sql/examples/books/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
//!
//! NOTE: If this doesn't work because you do not have the appropriate GPU drivers installed,
//! you can run `cargo run --release --example books --no-default-features --features="arrow cpu-perf"` instead. It will be slower for proof generation.
use arrow::datatypes::SchemaRef;
use arrow_csv::{infer_schema_from_files, ReaderBuilder};
use proof_of_sql::{
base::database::{
arrow_schema_utility::get_posql_compatible_schema, OwnedTable, OwnedTableTestAccessor,
TestAccessor,
TableRef, TestAccessor,
},
proof_primitive::dory::{
DynamicDoryEvaluationProof, ProverSetup, PublicParameters, VerifierSetup,
Expand All @@ -19,6 +18,7 @@ use proof_of_sql::{
},
};
use rand::{rngs::StdRng, SeedableRng};
use sqlparser::ast::Ident;
use std::{fs::File, time::Instant};

// We generate the public parameters and the setups used by the prover and verifier for the Dory PCS.
Expand All @@ -38,7 +38,8 @@ fn prove_and_verify_query(
// Parse the query:
println!("Parsing the query: {sql}...");
let now = Instant::now();
let query_plan = QueryExpr::try_new(sql.parse().unwrap(), "books".into(), accessor).unwrap();
let query_plan =
QueryExpr::try_new(sql.parse().unwrap(), Some(Ident::new("books")), accessor).unwrap();
println!("Done in {} ms.", now.elapsed().as_secs_f64() * 1000.);

// Generate the proof and result:
Expand Down Expand Up @@ -88,7 +89,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
"books.books".parse().unwrap(),
&TableRef::from(&["books", "books"]),
OwnedTable::try_from(books_batch).unwrap(),
0,
);
Expand Down
9 changes: 5 additions & 4 deletions crates/proof-of-sql/examples/brands/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
//!
//! NOTE: If this doesn't work because you do not have the appropriate GPU drivers installed,
//! you can run `cargo run --release --example brands --no-default-features --features="arrow cpu-perf"` instead. It will be slower for proof generation.
use arrow::datatypes::SchemaRef;
use arrow_csv::{infer_schema_from_files, ReaderBuilder};
use proof_of_sql::{
base::database::{
arrow_schema_utility::get_posql_compatible_schema, OwnedTable, OwnedTableTestAccessor,
TestAccessor,
TableRef, TestAccessor,
},
proof_primitive::dory::{
DynamicDoryEvaluationProof, ProverSetup, PublicParameters, VerifierSetup,
Expand All @@ -19,6 +18,7 @@ use proof_of_sql::{
},
};
use rand::{rngs::StdRng, SeedableRng};
use sqlparser::ast::Ident;
use std::{fs::File, time::Instant};

// We generate the public parameters and the setups used by the prover and verifier for the Dory PCS.
Expand All @@ -38,7 +38,8 @@ fn prove_and_verify_query(
// Parse the query:
println!("Parsing the query: {sql}...");
let now = Instant::now();
let query_plan = QueryExpr::try_new(sql.parse().unwrap(), "brands".into(), accessor).unwrap();
let query_plan =
QueryExpr::try_new(sql.parse().unwrap(), Some(Ident::new("brands")), accessor).unwrap();
println!("Done in {} ms.", now.elapsed().as_secs_f64() * 1000.);

// Generate the proof and result:
Expand Down Expand Up @@ -88,7 +89,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
"brands.global_brands".parse().unwrap(),
&TableRef::from(&["brands", "global_brands"]),
OwnedTable::try_from(brands_batch).unwrap(),
0,
);
Expand Down
9 changes: 5 additions & 4 deletions crates/proof-of-sql/examples/census/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use arrow::datatypes::SchemaRef;
use arrow_csv::{infer_schema_from_files, ReaderBuilder};
use proof_of_sql::{
base::database::{OwnedTable, OwnedTableTestAccessor},
base::database::{OwnedTable, OwnedTableTestAccessor, TableRef},
proof_primitive::dory::{
DynamicDoryEvaluationProof, ProverSetup, PublicParameters, VerifierSetup,
},
Expand All @@ -18,8 +18,8 @@ use proof_of_sql::{
},
};
use rand::{rngs::StdRng, SeedableRng};
use sqlparser::ast::Ident;
use std::{fs::File, time::Instant};

// We generate the public parameters and the setups used by the prover and verifier for the Dory PCS.
// The `max_nu` should be set such that the maximum table size is less than `2^(2*max_nu-1)`.
// For a sampling:
Expand All @@ -45,7 +45,8 @@ fn prove_and_verify_query(
// Parse the query:
println!("Parsing the query: {sql}...");
let now = Instant::now();
let query_plan = QueryExpr::try_new(sql.parse().unwrap(), "census".into(), accessor).unwrap();
let query_plan =
QueryExpr::try_new(sql.parse().unwrap(), Some(Ident::new("census")), accessor).unwrap();
println!("Done in {} ms.", now.elapsed().as_secs_f64() * 1000.);

// Generate the proof and result:
Expand Down Expand Up @@ -91,7 +92,7 @@ fn main() {

// Load the table into an "Accessor" so that the prover and verifier can access the data/commitments.
let accessor = OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_from_table(
"census.income".parse().unwrap(),
&TableRef::from(&["census", "income"]),
OwnedTable::try_from(census_income_batch).unwrap(),
0,
&prover_setup,
Expand Down
14 changes: 9 additions & 5 deletions crates/proof-of-sql/examples/countries/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
//!
//! NOTE: If this doesn't work because you do not have the appropriate GPU drivers installed,
//! you can run `cargo run --release --example countries --no-default-features --features="arrow cpu-perf"` instead. It will be slower for proof generation.
use arrow::datatypes::SchemaRef;
use arrow_csv::{infer_schema_from_files, ReaderBuilder};
use proof_of_sql::{
base::database::{
arrow_schema_utility::get_posql_compatible_schema, OwnedTable, OwnedTableTestAccessor,
TestAccessor,
TableRef, TestAccessor,
},
proof_primitive::dory::{
DynamicDoryEvaluationProof, ProverSetup, PublicParameters, VerifierSetup,
Expand All @@ -19,6 +18,7 @@ use proof_of_sql::{
},
};
use rand::{rngs::StdRng, SeedableRng};
use sqlparser::ast::Ident;
use std::{fs::File, time::Instant};

// We generate the public parameters and the setups used by the prover and verifier for the Dory PCS.
Expand All @@ -38,8 +38,12 @@ fn prove_and_verify_query(
// Parse the query:
println!("Parsing the query: {sql}...");
let now = Instant::now();
let query_plan =
QueryExpr::try_new(sql.parse().unwrap(), "countries".into(), accessor).unwrap();
let query_plan = QueryExpr::try_new(
sql.parse().unwrap(),
Some(Ident::new("countries")),
accessor,
)
.unwrap();
println!("Done in {} ms.", now.elapsed().as_secs_f64() * 1000.);

// Generate the proof and result:
Expand Down Expand Up @@ -89,7 +93,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
"countries.countries".parse().unwrap(),
&TableRef::from(&["countries", "countries"]),
OwnedTable::try_from(countries_batch).unwrap(),
0,
);
Expand Down
14 changes: 9 additions & 5 deletions crates/proof-of-sql/examples/dinosaurs/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
//!
//! NOTE: If this doesn't work because you do not have the appropriate GPU drivers installed,
//! you can run `cargo run --release --example dinosaurs --no-default-features --features="arrow cpu-perf"` instead. It will be slower for proof generation.

use arrow::datatypes::SchemaRef;
use arrow_csv::{infer_schema_from_files, ReaderBuilder};
use proof_of_sql::{
base::database::{
arrow_schema_utility::get_posql_compatible_schema, OwnedTable, OwnedTableTestAccessor,
TestAccessor,
TableRef, TestAccessor,
},
proof_primitive::dory::{
DynamicDoryEvaluationProof, ProverSetup, PublicParameters, VerifierSetup,
Expand All @@ -19,6 +18,7 @@ use proof_of_sql::{
},
};
use rand::{rngs::StdRng, SeedableRng};
use sqlparser::ast::Ident;
use std::{fs::File, time::Instant};

// We generate the public parameters and the setups used by the prover and verifier for the Dory PCS.
Expand All @@ -38,8 +38,12 @@ fn prove_and_verify_query(
// Parse the query:
println!("Parsing the query: {sql}...");
let now = Instant::now();
let query_plan =
QueryExpr::try_new(sql.parse().unwrap(), "dinosaurs".into(), accessor).unwrap();
let query_plan = QueryExpr::try_new(
sql.parse().unwrap(),
Some(Ident::new("dinosaurs")),
accessor,
)
.unwrap();
println!("Done in {} ms.", now.elapsed().as_secs_f64() * 1000.);

// Generate the proof and result:
Expand Down Expand Up @@ -89,7 +93,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
"dinosaurs.dinosaurs".parse().unwrap(),
&TableRef::from(&["dinosaurs", "dinosaurs"]),
OwnedTable::try_from(dinosaurs_batch).unwrap(),
0,
);
Expand Down
14 changes: 9 additions & 5 deletions crates/proof-of-sql/examples/dog_breeds/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
//!
//! NOTE: If this doesn't work because you do not have the appropriate GPU drivers installed,
//! you can run `cargo run --release --example dog_breeds --no-default-features --features="arrow cpu-perf"` instead. It will be slower for proof generation.

use arrow::datatypes::SchemaRef;
use arrow_csv::{infer_schema_from_files, ReaderBuilder};
use proof_of_sql::{
base::database::{OwnedTable, OwnedTableTestAccessor, TestAccessor},
base::database::{OwnedTable, OwnedTableTestAccessor, TableRef, TestAccessor},
proof_primitive::dory::{
DynamicDoryEvaluationProof, ProverSetup, PublicParameters, VerifierSetup,
},
Expand All @@ -16,6 +15,7 @@ use proof_of_sql::{
},
};
use rand::{rngs::StdRng, SeedableRng};
use sqlparser::ast::Ident;
use std::{fs::File, time::Instant};

// We generate the public parameters and the setups used by the prover and verifier for the Dory PCS.
Expand All @@ -35,8 +35,12 @@ fn prove_and_verify_query(
// Parse the query:
println!("Parsing the query: {sql}...");
let now = Instant::now();
let query_plan =
QueryExpr::try_new(sql.parse().unwrap(), "dog_breeds".into(), accessor).unwrap();
let query_plan = QueryExpr::try_new(
sql.parse().unwrap(),
Some(Ident::new("dog_breeds")),
accessor,
)
.unwrap();
println!("Done in {} ms.", now.elapsed().as_secs_f64() * 1000.);

// Generate the proof and result:
Expand Down Expand Up @@ -84,7 +88,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
"dog_breeds.breeds".parse().unwrap(),
&TableRef::from(&["dog_breeds", "breeds"]),
OwnedTable::try_from(dog_breeds_batch).unwrap(),
0,
);
Expand Down
Loading
Loading