Skip to content

Commit

Permalink
refactor!: proof_of_sql_parser::intermediate_ast::ResourceId with sql…
Browse files Browse the repository at this point in the history
…parser::ast::ObjectName in the proof-of-sql crate
  • Loading branch information
varshith257 committed Jan 3, 2025
1 parent 91173a3 commit f971384
Show file tree
Hide file tree
Showing 79 changed files with 1,659 additions and 1,547 deletions.
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
4 changes: 2 additions & 2 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 Down Expand Up @@ -87,7 +87,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
4 changes: 2 additions & 2 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 Down Expand Up @@ -88,7 +88,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
4 changes: 2 additions & 2 deletions crates/proof-of-sql/examples/books/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 Down Expand Up @@ -88,7 +88,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
4 changes: 2 additions & 2 deletions crates/proof-of-sql/examples/brands/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 Down Expand Up @@ -88,7 +88,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
4 changes: 2 additions & 2 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 Down Expand Up @@ -91,7 +91,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
4 changes: 2 additions & 2 deletions crates/proof-of-sql/examples/countries/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 Down Expand Up @@ -89,7 +89,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
4 changes: 2 additions & 2 deletions crates/proof-of-sql/examples/dinosaurs/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 Down Expand Up @@ -89,7 +89,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
4 changes: 2 additions & 2 deletions crates/proof-of-sql/examples/dog_breeds/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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 Down Expand Up @@ -84,7 +84,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
4 changes: 2 additions & 2 deletions crates/proof-of-sql/examples/hello_world/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ark_std::test_rng;
use proof_of_sql::{
base::database::{
owned_table_utility::{bigint, owned_table, varchar},
OwnedTableTestAccessor, TestAccessor,
OwnedTableTestAccessor, TableRef, TestAccessor,
},
proof_primitive::dory::{
DynamicDoryEvaluationProof, ProverSetup, PublicParameters, VerifierSetup,
Expand Down Expand Up @@ -53,7 +53,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
"sxt.table".parse().unwrap(),
&TableRef::from(&["sxt", "table"]),
owned_table([
bigint("a", [1, 2, 3, 2]),
varchar("b", ["hi", "hello", "there", "world"]),
Expand Down
4 changes: 2 additions & 2 deletions crates/proof-of-sql/examples/plastics/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 Down Expand Up @@ -87,7 +87,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
"plastics.types".parse().unwrap(),
&TableRef::from(&["plastics", "types"]),
OwnedTable::try_from(plastics_batch).unwrap(),
0,
);
Expand Down
8 changes: 4 additions & 4 deletions crates/proof-of-sql/examples/posql_db/commit_accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ impl<C: Commitment + Serialize + for<'a> Deserialize<'a>> CommitAccessor<C> {
fs::write(path, postcard::to_allocvec(commit)?)?;
Ok(())
}
pub fn load_commit(&mut self, table_ref: TableRef) -> Result<(), Box<dyn Error>> {
pub fn load_commit(&mut self, table_ref: &TableRef) -> Result<(), Box<dyn Error>> {
let path = self.base_path.join(format!("{table_ref}.commit"));
let commit = postcard::from_bytes(&fs::read(path)?)?;
self.inner.insert(table_ref, commit);
self.inner.insert(table_ref.clone(), commit);
Ok(())
}
pub fn get_commit(&self, table_ref: &TableRef) -> Option<&TableCommitment<C>> {
Expand All @@ -43,11 +43,11 @@ impl<C: Commitment> CommitmentAccessor<C> for CommitAccessor<C> {
}
}
impl<C: Commitment> MetadataAccessor for CommitAccessor<C> {
fn get_length(&self, table_ref: proof_of_sql::base::database::TableRef) -> usize {
fn get_length(&self, table_ref: &proof_of_sql::base::database::TableRef) -> usize {
self.inner.get_length(table_ref)
}

fn get_offset(&self, table_ref: proof_of_sql::base::database::TableRef) -> usize {
fn get_offset(&self, table_ref: &proof_of_sql::base::database::TableRef) -> usize {
self.inner.get_offset(table_ref)
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/proof-of-sql/examples/posql_db/csv_accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ impl<S: Scalar> DataAccessor<S> for CsvDataAccessor {
}
}
impl MetadataAccessor for CsvDataAccessor {
fn get_length(&self, table_ref: TableRef) -> usize {
fn get_length(&self, table_ref: &TableRef) -> usize {
self.inner.get_length(table_ref)
}
fn get_offset(&self, table_ref: TableRef) -> usize {
fn get_offset(&self, table_ref: &TableRef) -> usize {
self.inner.get_offset(table_ref)
}
}
Expand Down
17 changes: 10 additions & 7 deletions crates/proof-of-sql/examples/posql_db/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ fn main() {
CommitAccessor::<DynamicDoryCommitment>::new(PathBuf::from(args.path.clone()));
let csv_accessor = CsvDataAccessor::new(PathBuf::from(args.path));
commit_accessor
.load_commit(table_name)
.load_commit(&table_name)
.expect("Failed to load commit");
let mut table_commitment = commit_accessor.get_commit(&table_name).unwrap().clone();
let schema = Schema::new(
commit_accessor
.lookup_schema(table_name)
.lookup_schema(table_name.clone())
.iter()
.map(|(i, t)| Field::new(i.value.as_str(), t.into(), false))
.collect::<Vec<_>>(),
Expand All @@ -228,13 +228,16 @@ fn main() {
CommitAccessor::<DynamicDoryCommitment>::new(PathBuf::from(args.path.clone()));
let mut csv_accessor = CsvDataAccessor::new(PathBuf::from(args.path.clone()));
let tables = query.get_table_references("example".parse().unwrap());
for table in tables.into_iter().map(TableRef::new) {
for table in tables
.into_iter()
.map(|resource_id| TableRef::new(resource_id.into()))
{
commit_accessor
.load_commit(table)
.load_commit(&table)
.expect("Failed to load commit");
let schema = Schema::new(
commit_accessor
.lookup_schema(table)
.lookup_schema(table.clone())
.iter()
.map(|(i, t)| Field::new(i.value.as_str(), t.into(), false))
.collect::<Vec<_>>(),
Expand Down Expand Up @@ -262,9 +265,9 @@ fn main() {
CommitAccessor::<DynamicDoryCommitment>::new(PathBuf::from(args.path.clone()));
let table_refs = query.get_table_references("example".parse().unwrap());
for table_ref in table_refs {
let table_name = TableRef::new(table_ref);
let table_name = TableRef::new(table_ref.into());
commit_accessor
.load_commit(table_name)
.load_commit(&table_name)
.expect("Failed to load commit");
}
let query = QueryExpr::try_new(query, "example".into(), &commit_accessor).unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ impl<S: Scalar> DataAccessor<S> for RecordBatchAccessor {
}
}
impl MetadataAccessor for RecordBatchAccessor {
fn get_length(&self, table_ref: TableRef) -> usize {
fn get_length(&self, table_ref: &TableRef) -> usize {
self.tables
.get(&table_ref)
.expect("Table not found.")
.num_rows()
}

fn get_offset(&self, table_ref: TableRef) -> usize {
fn get_offset(&self, table_ref: &TableRef) -> usize {
assert!(self.tables.contains_key(&table_ref), "Table not found.");
0
}
Expand Down
4 changes: 2 additions & 2 deletions crates/proof-of-sql/examples/programming_books/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 Down Expand Up @@ -86,7 +86,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
"programming_books.books".parse().unwrap(),
&TableRef::from(&["programming_books", "books"]),
OwnedTable::try_from(books_extra_batch).unwrap(),
0,
);
Expand Down
4 changes: 2 additions & 2 deletions crates/proof-of-sql/examples/rockets/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 Down Expand Up @@ -88,7 +88,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
"rockets.launch_vehicles".parse().unwrap(),
&TableRef::from(&["rockets", "launch_vehicles"]),
OwnedTable::try_from(rockets_batch).unwrap(),
0,
);
Expand Down
6 changes: 3 additions & 3 deletions crates/proof-of-sql/examples/space/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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 Down Expand Up @@ -100,12 +100,12 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
"space.travellers".parse().unwrap(),
&TableRef::from(&["space", "travellers"]),
OwnedTable::try_from(space_travellers_batch).unwrap(),
0,
);
accessor.add_table(
"space.planets".parse().unwrap(),
&TableRef::from(&["space", "planets"]),
OwnedTable::try_from(planets_batch).unwrap(),
0,
);
Expand Down
Loading

0 comments on commit f971384

Please sign in to comment.