Skip to content

Commit

Permalink
meta: code style
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <[email protected]>
  • Loading branch information
tareknaser committed Oct 8, 2024
1 parent 87e0eea commit cda4220
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 26 deletions.
2 changes: 1 addition & 1 deletion crates/proof-of-sql/src/base/commitment/column_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub struct ColumnBoundsMismatch {

/// Column metadata storing the bounds for column types that have order.
///
/// Other Ord column variants do exist (like Scalar/Boolean, FixedSizeBinary, etc).
/// Other Ord column variants do exist (like Scalar/Boolean, `FixedSizeBinary`, etc).
/// However, bounding these is useless unless we are performing indexing on these columns.
/// This functionality only be considered after we support them in the user-facing sql.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ mod tests {
assert_eq!(varchar_metadata.bounds(), &ColumnBounds::NoOrder);

let byte_width = 16;
let fixed_size_binary_data = vec![
let fixed_size_binary_data = [
vec![0u8; byte_width],
vec![1u8; byte_width],
vec![2u8; byte_width],
Expand Down
11 changes: 6 additions & 5 deletions crates/proof-of-sql/src/base/commitment/committable_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ pub enum CommittableColumn<'a> {
/// Borrowed byte column, mapped to `u8`. This is not a `PoSQL`
/// type, we need this to commit to words in the range check.
RangeCheckWord(&'a [u8]),
/// Borrowed FixedSizeBinary column, mapped to a slice of bytes.
/// Borrowed `FixedSizeBinary` column, mapped to a slice of bytes.
/// - The i32 specifies the number of bytes per value.
FixedSizeBinary(i32, &'a [u8]),
}

impl<'a> CommittableColumn<'a> {
/// Returns the length of the column.
#[must_use]
#[allow(clippy::missing_panics_doc)]
pub fn len(&self) -> usize {
match self {
CommittableColumn::TinyInt(col) => col.len(),
Expand Down Expand Up @@ -436,7 +437,7 @@ mod tests {
);

// Non-empty case
let fixed_size_binary_data = vec![
let fixed_size_binary_data = [
vec![0u8; byte_width as usize],
vec![1u8; byte_width as usize],
vec![2u8; byte_width as usize],
Expand Down Expand Up @@ -651,7 +652,7 @@ mod tests {
);

// Non-empty case
let fixed_size_binary_data = vec![
let fixed_size_binary_data = [
vec![0u8; byte_width as usize],
vec![1u8; byte_width as usize],
vec![2u8; byte_width as usize],
Expand Down Expand Up @@ -821,7 +822,7 @@ mod tests {
);

// Non-empty case
let fixed_size_binary_data = vec![
let fixed_size_binary_data = [
vec![0u8; byte_width as usize],
vec![1u8; byte_width as usize],
vec![2u8; byte_width as usize],
Expand Down Expand Up @@ -1080,7 +1081,7 @@ mod tests {
assert_eq!(commitment_buffer[0], CompressedRistretto::default());

// Non-empty case
let fixed_size_binary_data = vec![
let fixed_size_binary_data = [
vec![0u8; byte_width as usize],
vec![1u8; byte_width as usize],
vec![2u8; byte_width as usize],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl Commitment for NaiveCommitment {
CommittableColumn::FixedSizeBinary(byte_width, bytes) => bytes
// Chunk the bytes into `byte_width`-sized chunks and convert each chunk into a scalar
.chunks(*byte_width as usize)
.map(|chunk| TestScalar::from(chunk))
.map(TestScalar::from)
.collect(),
};
vectors.append(&mut existing_scalars);
Expand Down
6 changes: 3 additions & 3 deletions crates/proof-of-sql/src/base/database/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ mod tests {
assert!(!column.is_empty());

let byte_width = 16;
let fixed_size_binary_data = vec![
let fixed_size_binary_data = [
vec![0u8; byte_width],
vec![1u8; byte_width],
vec![2u8; byte_width],
Expand Down Expand Up @@ -1130,7 +1130,7 @@ mod tests {

// FixedSizeBinary
let byte_width = 16;
let fixed_size_binary_data = vec![
let fixed_size_binary_data = [
vec![0u8; byte_width],
vec![1u8; byte_width],
vec![2u8; byte_width],
Expand Down Expand Up @@ -1206,7 +1206,7 @@ mod tests {
assert_eq!(column.column_type().bit_size(), 64);

let byte_width: usize = 16;
let fixed_size_binary_data = vec![
let fixed_size_binary_data = [
vec![0u8; byte_width],
vec![1u8; byte_width],
vec![2u8; byte_width],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum ColumnOperationError {
len_b: usize,
},

/// Mismatched byte sizes in FixedSizeBinary columns
/// Mismatched byte sizes in `FixedSizeBinary` columns
#[snafu(display(
"FixedSizeBinary columns have different byte sizes: {byte_size_a} != {byte_size_b}"
))]
Expand Down
1 change: 1 addition & 0 deletions crates/proof-of-sql/src/base/database/owned_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub enum OwnedColumn<S: Scalar> {
impl<S: Scalar> OwnedColumn<S> {
/// Returns the length of the column.
#[must_use]
#[allow(clippy::missing_panics_doc)]
pub fn len(&self) -> usize {
match self {
OwnedColumn::Boolean(col) => col.len(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1635,12 +1635,12 @@ mod test {
);

let byte_width = 16;
let lhs_data = vec![
let lhs_data = [
vec![0u8; byte_width],
vec![1u8; byte_width],
vec![2u8; byte_width],
];
let rhs_data = vec![
let rhs_data = [
vec![0u8; byte_width],
vec![2u8; byte_width],
vec![2u8; byte_width],
Expand Down Expand Up @@ -1924,7 +1924,7 @@ mod test {
let rhs = OwnedColumn::<Curve25519Scalar>::VarChar(
["Space", "and", "Time"]
.iter()
.map(|s| s.to_string())
.map(std::string::ToString::to_string)
.collect(),
);
let result = lhs.element_wise_le(&rhs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use proof_of_sql_parser::posql_time::PoSQLTimeUnit;
use rand::{
distributions::{Distribution, Uniform},
rngs::StdRng,
Rng,
};
use std::sync::Arc;

Expand Down Expand Up @@ -175,11 +176,13 @@ pub fn make_random_test_accessor_data(
.map(|_| (0..*byte_width).map(|_| rng.gen::<u8>()).collect())
.collect();

let flat_binary_values: Vec<u8> = binary_values.iter().flatten().cloned().collect();
let flat_binary_values: Vec<u8> = binary_values.iter().flatten().copied().collect();

columns.push(Arc::new(
FixedSizeBinaryArray::try_from_iter(flat_binary_values.chunks(*byte_width))
.unwrap(),
FixedSizeBinaryArray::try_from_iter(
flat_binary_values.chunks(*byte_width as usize),
)
.unwrap(),
));
}
}
Expand Down
17 changes: 9 additions & 8 deletions crates/proof-of-sql/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,26 +395,27 @@ fn we_can_prove_a_basic_equality_with_out_of_order_results_with_fixed_size_binar
owned_table([
fixed_size_binary(
"binary_data",
byte_width,
[vec![0u8; byte_width], vec![1u8; byte_width]],
),
int128("amount", [115, -79]),
]),
0,
);

// Query to select rows where binary_data matches a specific pattern
// Directly include the binary pattern in the query
let binary_pattern = vec![1u8; byte_width];
let query_string = format!(
"select binary_data, amount from public.test_table where binary_data = {binary_pattern:?};"
);

let query = QueryExpr::try_new(
"select binary_data, amount from public.test_table where binary_data = ?;"
.parse()
.unwrap(),
query_string.parse().unwrap(),
"public".parse().unwrap(),
&accessor,
)
.unwrap();

// Assuming you have a way to set the parameter for the query
query.set_parameter(0, vec![1u8; byte_width]);

let (proof, serialized_result) =
QueryProof::<InnerProductProof>::new(query.proof_expr(), &accessor, &());
let owned_table_result = proof
Expand All @@ -426,7 +427,7 @@ fn we_can_prove_a_basic_equality_with_out_of_order_results_with_fixed_size_binar

// Expected result with the matching FixedSizeBinary entry
let expected_result = owned_table([
fixed_size_binary("binary_data", [vec![1u8; byte_width]]),
fixed_size_binary("binary_data", byte_width, [vec![1u8; byte_width]]),
int128("amount", [-79]),
]);

Expand Down

0 comments on commit cda4220

Please sign in to comment.