Skip to content

Commit

Permalink
refactor!: simplify TableRef usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
varshith257 committed Jan 8, 2025
1 parent 41b65fd commit 5eac880
Show file tree
Hide file tree
Showing 53 changed files with 382 additions and 356 deletions.
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/albums/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["albums", "collection"]),
&TableRef::new("albums", "collection"),
OwnedTable::try_from(albums_batch).unwrap(),
0,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/avocado-prices/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,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(
&TableRef::from(&["avocado", "prices"]),
&TableRef::new("avocado", "prices"),
OwnedTable::try_from(data_batch).unwrap(),
0,
&prover_setup,
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/books/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["books", "books"]),
&TableRef::new("books", "books"),
OwnedTable::try_from(books_batch).unwrap(),
0,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/brands/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["brands", "global_brands"]),
&TableRef::new("brands", "global_brands"),
OwnedTable::try_from(brands_batch).unwrap(),
0,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/census/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,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(
&TableRef::from(&["census", "income"]),
&TableRef::new("census", "income"),
OwnedTable::try_from(census_income_batch).unwrap(),
0,
&prover_setup,
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/countries/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["countries", "countries"]),
&TableRef::new("countries", "countries"),
OwnedTable::try_from(countries_batch).unwrap(),
0,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/dinosaurs/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["dinosaurs", "dinosaurs"]),
&TableRef::new("dinosaurs", "dinosaurs"),
OwnedTable::try_from(dinosaurs_batch).unwrap(),
0,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/dog_breeds/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["dog_breeds", "breeds"]),
&TableRef::new("dog_breeds", "breeds"),
OwnedTable::try_from(dog_breeds_batch).unwrap(),
0,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/hello_world/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["sxt", "table"]),
&TableRef::new("sxt", "table"),
owned_table([
bigint("a", [1, 2, 3, 2]),
varchar("b", ["hi", "hello", "there", "world"]),
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/plastics/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["plastics", "types"]),
&TableRef::new("plastics", "types"),
OwnedTable::try_from(plastics_batch).unwrap(),
0,
);
Expand Down
15 changes: 4 additions & 11 deletions crates/proof-of-sql/examples/posql_db/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ fn main() {
let append_batch =
read_record_batch_from_csv(schema, &file_path).expect("Failed to read csv file.");
csv_accessor
.append_batch(&table_name, &append_batch)
.append_batch(&table_name.clone(), &append_batch)
.expect("Failed to write batch");
let timer = start_timer("Updating Commitment");
table_commitment
Expand All @@ -228,12 +228,7 @@ 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(|resource_id| {
TableRef::new(
Some(Ident::new("example")),
Ident::new(resource_id.to_string()),
)
}) {
for table in tables.into_iter().map(Into::into) {
commit_accessor
.load_commit(&table)
.expect("Failed to load commit");
Expand All @@ -245,7 +240,7 @@ fn main() {
.collect::<Vec<_>>(),
);
csv_accessor
.load_table(table, schema)
.load_table(table.clone(), schema)
.expect("Failed to load table");
}
let query =
Expand All @@ -268,9 +263,7 @@ 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 schema_name = Some(Ident::new("example"));
let table_name = Ident::new(table_ref.to_string());
let table_name = TableRef::new(schema_name, table_name);
let table_name: TableRef = table_ref.into();
commit_accessor
.load_commit(&table_name)
.expect("Failed to load commit");
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/programming_books/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["programming_books", "books"]),
&TableRef::new("programming_books", "books"),
OwnedTable::try_from(books_extra_batch).unwrap(),
0,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/rockets/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["rockets", "launch_vehicles"]),
&TableRef::new("rockets", "launch_vehicles"),
OwnedTable::try_from(rockets_batch).unwrap(),
0,
);
Expand Down
4 changes: 2 additions & 2 deletions crates/proof-of-sql/examples/space/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["space", "travellers"]),
&TableRef::new("space", "travellers"),
OwnedTable::try_from(space_travellers_batch).unwrap(),
0,
);
accessor.add_table(
&TableRef::from(&["space", "planets"]),
&TableRef::new("space", "planets"),
OwnedTable::try_from(planets_batch).unwrap(),
0,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/stocks/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["stocks", "stocks"]),
&TableRef::new("stocks", "stocks"),
OwnedTable::try_from(stocks_batch).unwrap(),
0,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/sushi/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["sushi", "fish"]),
&TableRef::new("sushi", "fish"),
OwnedTable::try_from(fish_batch).unwrap(),
0,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/tech_gadget_prices/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.ok_or("No data found in CSV file")??;

let accessor = OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_from_table(
&TableRef::from(&["tech_gadget_prices", "prices"]),
&TableRef::new("tech_gadget_prices", "prices"),
OwnedTable::try_from(data_batch)?,
0,
&prover_setup,
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/vehicles/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["vehicles", "vehicles"]),
&TableRef::new("vehicles", "vehicles"),
OwnedTable::try_from(vehicles_batch).unwrap(),
0,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/wood_types/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn main() {
let mut accessor =
OwnedTableTestAccessor::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
&TableRef::from(&["wood_types", "woods"]),
&TableRef::new("wood_types", "woods"),
OwnedTable::try_from(wood_types_batch).unwrap(),
0,
);
Expand Down
22 changes: 11 additions & 11 deletions crates/proof-of-sql/src/base/commitment/query_commitments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,18 @@ mod tests {

let offset_commitment =
TableCommitment::<NaiveCommitment>::from_owned_table_with_offset(&table_a, 2, &());
let offset_table_id = TableRef::from(&["off", "table"]);
let offset_table_id = TableRef::new("off", "table");

let no_offset_commitment = TableCommitment::from_owned_table_with_offset(&table_b, 0, &());
let no_offset_id = TableRef::from(&["no", "off"]);
let no_offset_id = TableRef::new("no", "off");

let no_columns_commitment = TableCommitment::try_from_columns_with_offset(
Vec::<(&Ident, &OwnedColumn<TestScalar>)>::new(),
0,
&(),
)
.unwrap();
let no_columns_id = TableRef::from(&["no", "columns"]);
let no_columns_id = TableRef::new("no", "columns");

let no_rows_commitment = TableCommitment::try_from_columns_with_offset(
[(
Expand All @@ -180,7 +180,7 @@ mod tests {
&(),
)
.unwrap();
let no_rows_id = TableRef::from(&["no", "rows"]);
let no_rows_id = TableRef::new("no", "rows");

let query_commitments = QueryCommitments::from_iter([
(offset_table_id.clone(), offset_commitment),
Expand Down Expand Up @@ -220,10 +220,10 @@ mod tests {

let table_a_commitment =
TableCommitment::<NaiveCommitment>::from_owned_table_with_offset(&table_a, 2, &());
let table_a_id = TableRef::from(&["table", "a"]);
let table_a_id = TableRef::new("table", "a");

let table_b_commitment = TableCommitment::from_owned_table_with_offset(&table_b, 0, &());
let table_b_id = TableRef::from(&["table", "b"]);
let table_b_id = TableRef::new("table", "b");

let query_commitments = QueryCommitments::from_iter([
(table_a_id.clone(), table_a_commitment.clone()),
Expand Down Expand Up @@ -274,18 +274,18 @@ mod tests {

let table_a_commitment =
TableCommitment::<NaiveCommitment>::from_owned_table_with_offset(&table_a, 2, &());
let table_a_id = TableRef::from(&["table", "a"]);
let table_a_id = TableRef::new("table", "a");

let table_b_commitment = TableCommitment::from_owned_table_with_offset(&table_b, 0, &());
let table_b_id = TableRef::from(&["table", "b"]);
let table_b_id = TableRef::new("table", "b");

let no_columns_commitment = TableCommitment::try_from_columns_with_offset(
Vec::<(&Ident, &OwnedColumn<TestScalar>)>::new(),
0,
&(),
)
.unwrap();
let no_columns_id = TableRef::from(&["no", "columns"]);
let no_columns_id = TableRef::new("no", "columns");

let query_commitments = QueryCommitments::from_iter([
(table_a_id.clone(), table_a_commitment),
Expand Down Expand Up @@ -359,7 +359,7 @@ mod tests {

let mut table_a_commitment =
TableCommitment::from_owned_table_with_offset(&table_a, 0, &setup);
let table_a_id = TableRef::from(&["table", "a"]);
let table_a_id = TableRef::new("table", "a");
*table_a_commitment
.column_commitments_mut()
.column_metadata_mut()
Expand All @@ -369,7 +369,7 @@ mod tests {

let mut table_b_commitment =
TableCommitment::from_owned_table_with_offset(&table_b, 0, &setup);
let table_b_id = TableRef::from(&["table", "b"]);
let table_b_id = TableRef::new("table", "b");
*table_b_commitment
.column_commitments_mut()
.column_metadata_mut()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use proof_of_sql_parser::posql_time::{PoSQLTimeUnit, PoSQLTimeZone};
#[test]
fn we_can_query_the_length_of_a_table() {
let mut accessor = OwnedTableTestAccessor::<NaiveEvaluationProof>::new_empty_with_setup(());
let table_ref_1 = TableRef::from(&["sxt", "test1"]);
let table_ref_2 = TableRef::from(&["sxt", "test2"]);
let table_ref_1 = TableRef::new("sxt", "test1");
let table_ref_2 = TableRef::new("sxt", "test2");

let data1 = owned_table([bigint("a", [1, 2, 3]), bigint("b", [4, 5, 6])]);
accessor.add_table(&table_ref_1, data1, 0_usize);
Expand All @@ -33,8 +33,8 @@ fn we_can_query_the_length_of_a_table() {
#[test]
fn we_can_access_the_columns_of_a_table() {
let mut accessor = OwnedTableTestAccessor::<NaiveEvaluationProof>::new_empty_with_setup(());
let table_ref_1 = TableRef::from(&["sxt", "test1"]);
let table_ref_2 = TableRef::from(&["sxt", "test2"]);
let table_ref_1 = TableRef::new("sxt", "test1");
let table_ref_2 = TableRef::new("sxt", "test2");

let data1 = owned_table([bigint("a", [1, 2, 3]), bigint("b", [4, 5, 6])]);
accessor.add_table(&table_ref_1, data1, 0_usize);
Expand Down Expand Up @@ -127,8 +127,8 @@ fn we_can_access_the_columns_of_a_table() {
#[test]
fn we_can_access_the_commitments_of_table_columns() {
let mut accessor = OwnedTableTestAccessor::<NaiveEvaluationProof>::new_empty_with_setup(());
let table_ref_1 = TableRef::from(&["sxt", "test1"]);
let table_ref_2 = TableRef::from(&["sxt", "test2"]);
let table_ref_1 = TableRef::new("sxt", "test1");
let table_ref_2 = TableRef::new("sxt", "test2");

let data1 = owned_table([bigint("a", [1, 2, 3]), bigint("b", [4, 5, 6])]);
accessor.add_table(&table_ref_1, data1, 0_usize);
Expand Down Expand Up @@ -170,8 +170,8 @@ fn we_can_access_the_commitments_of_table_columns() {
#[test]
fn we_can_access_the_type_of_table_columns() {
let mut accessor = OwnedTableTestAccessor::<NaiveEvaluationProof>::new_empty_with_setup(());
let table_ref_1 = TableRef::from(&["sxt", "test1"]);
let table_ref_2 = TableRef::from(&["sxt", "test2"]);
let table_ref_1 = TableRef::new("sxt", "test1");
let table_ref_2 = TableRef::new("sxt", "test2");

let data1 = owned_table([bigint("a", [1, 2, 3]), bigint("b", [4, 5, 6])]);
accessor.add_table(&table_ref_1, data1, 0_usize);
Expand Down Expand Up @@ -211,7 +211,7 @@ fn we_can_access_the_type_of_table_columns() {
#[test]
fn we_can_access_schema_and_column_names() {
let mut accessor = OwnedTableTestAccessor::<NaiveEvaluationProof>::new_empty_with_setup(());
let table_ref_1 = TableRef::from(&["sxt", "test1"]);
let table_ref_1 = TableRef::new("sxt", "test1");

let data1 = owned_table([bigint("a", [1, 2, 3]), varchar("b", ["x", "y", "z"])]);
accessor.add_table(&table_ref_1, data1, 0_usize);
Expand All @@ -229,7 +229,7 @@ fn we_can_access_schema_and_column_names() {
#[test]
fn we_can_correctly_update_offsets() {
let mut accessor1 = OwnedTableTestAccessor::<NaiveEvaluationProof>::new_empty_with_setup(());
let table_ref = TableRef::from(&["sxt", "test1"]);
let table_ref = TableRef::new("sxt", "test1");

let data = owned_table([bigint("a", [1, 2, 3]), bigint("b", [123, 5, 123])]);
accessor1.add_table(&table_ref, data.clone(), 0_usize);
Expand Down
Loading

0 comments on commit 5eac880

Please sign in to comment.