diff --git a/crates/proof-of-sql/src/base/database/table.rs b/crates/proof-of-sql/src/base/database/table.rs index ecf7f67e3..e570e8adc 100644 --- a/crates/proof-of-sql/src/base/database/table.rs +++ b/crates/proof-of-sql/src/base/database/table.rs @@ -43,14 +43,10 @@ impl<'a, S: Scalar> Table<'a, S> { pub fn num_columns(&self) -> usize { self.table.len() } - /// Number of rows in the table. + /// Number of rows in the table. For an empty table, this will return `None`. #[must_use] - pub fn num_rows(&self) -> usize { - if self.table.is_empty() { - 0 - } else { - self.table[0].len() - } + pub fn num_rows(&self) -> Option { + (!self.table.is_empty()).then(|| self.table[0].len()) } /// Whether the table has no columns. #[must_use] diff --git a/crates/proof-of-sql/src/base/database/table_test.rs b/crates/proof-of-sql/src/base/database/table_test.rs index 43946adb1..515de66fa 100644 --- a/crates/proof-of-sql/src/base/database/table_test.rs +++ b/crates/proof-of-sql/src/base/database/table_test.rs @@ -1,10 +1,7 @@ -use crate::{ - base::{ - database::{table_utility::*, Column, Table, TableError}, - map::IndexMap, - scalar::test_scalar::TestScalar, - }, - proof_primitive::dory::DoryScalar, +use crate::base::{ + database::{table_utility::*, Column, Table, TableError}, + map::IndexMap, + scalar::test_scalar::TestScalar, }; use bumpalo::Bump; use proof_of_sql_parser::{ @@ -16,11 +13,12 @@ use proof_of_sql_parser::{ fn we_can_create_a_table_with_no_columns() { let table = Table::::try_new(IndexMap::default()).unwrap(); assert_eq!(table.num_columns(), 0); + assert_eq!(table.num_rows(), None); } #[test] fn we_can_create_an_empty_table() { let alloc = Bump::new(); - let borrowed_table = table::([ + let borrowed_table = table::([ borrowed_bigint("bigint", [0; 0], &alloc), borrowed_int128("decimal", [0; 0], &alloc), borrowed_varchar("varchar", ["0"; 0], &alloc), @@ -46,7 +44,7 @@ fn we_can_create_an_empty_table() { fn we_can_create_a_table_with_data() { let alloc = Bump::new(); - let borrowed_table = table::([ + let borrowed_table = table::([ borrowed_bigint( "bigint", [0_i64, 1, 2, 3, 4, 5, 6, i64::MIN, i64::MAX], @@ -102,14 +100,14 @@ fn we_can_create_a_table_with_data() { .map(|&s| alloc.alloc_str(s) as &str) .collect(); let varchar_str_slice = alloc.alloc_slice_clone(&varchar_data); - let varchar_scalars: Vec = varchar_data.iter().map(Into::into).collect(); + let varchar_scalars: Vec = varchar_data.iter().map(Into::into).collect(); let varchar_scalars_slice = alloc.alloc_slice_clone(&varchar_scalars); expected_table.insert( Identifier::try_new("varchar").unwrap(), Column::VarChar((varchar_str_slice, varchar_scalars_slice)), ); - let scalar_data: Vec = (0..=8).map(DoryScalar::from).collect(); + let scalar_data: Vec = (0..=8).map(TestScalar::from).collect(); let scalar_slice = alloc.alloc_slice_copy(&scalar_data); expected_table.insert( Identifier::try_new("scalar").unwrap(), @@ -165,7 +163,7 @@ fn we_get_inequality_between_tables_with_differing_column_order() { fn we_get_inequality_between_tables_with_differing_data() { let alloc = Bump::new(); - let table_a: Table<'_, DoryScalar> = table([ + let table_a: Table<'_, TestScalar> = table([ borrowed_bigint("a", [0], &alloc), borrowed_int128("b", [0], &alloc), borrowed_varchar("c", ["0"], &alloc), @@ -179,7 +177,7 @@ fn we_get_inequality_between_tables_with_differing_data() { ), ]); - let table_b: Table<'_, DoryScalar> = table([ + let table_b: Table<'_, TestScalar> = table([ borrowed_bigint("a", [1], &alloc), borrowed_int128("b", [0], &alloc), borrowed_varchar("c", ["0"], &alloc), diff --git a/crates/proof-of-sql/src/base/database/table_test_accessor.rs b/crates/proof-of-sql/src/base/database/table_test_accessor.rs index 8053fa2d8..705c19c6c 100644 --- a/crates/proof-of-sql/src/base/database/table_test_accessor.rs +++ b/crates/proof-of-sql/src/base/database/table_test_accessor.rs @@ -111,7 +111,12 @@ impl MetadataAccessor for TableTestAccessor<'_, C /// /// Will panic if the `table_ref` is not found in `self.tables`, indicating that an invalid reference was provided. fn get_length(&self, table_ref: TableRef) -> usize { - self.tables.get(&table_ref).unwrap().0.num_rows() + self.tables + .get(&table_ref) + .unwrap() + .0 + .num_rows() + .unwrap_or(0) } /// /// # Panics diff --git a/crates/proof-of-sql/src/base/database/table_utility.rs b/crates/proof-of-sql/src/base/database/table_utility.rs index 1db5e8e0d..5273f04a8 100644 --- a/crates/proof-of-sql/src/base/database/table_utility.rs +++ b/crates/proof-of-sql/src/base/database/table_utility.rs @@ -141,7 +141,6 @@ pub fn borrowed_int( /// /// # Panics /// - Panics if `name.parse()` fails to convert the name into an `Identifier`. -#[allow(clippy::missing_panics_doc)] pub fn borrowed_bigint( name: impl Deref, data: impl IntoIterator>,