Skip to content

Commit c65f130

Browse files
feat: add div-mod constraints
1 parent c30038f commit c65f130

File tree

8 files changed

+901
-26
lines changed

8 files changed

+901
-26
lines changed

crates/proof-of-sql/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ zerocopy = { workspace = true }
6767
arrow-csv = { workspace = true }
6868
criterion = { workspace = true, features = ["html_reports"] }
6969
merlin = { workspace = true }
70+
mockall = "0.13.1"
7071
opentelemetry = { workspace = true }
7172
opentelemetry-jaeger = { workspace = true }
7273
rand = { workspace = true, default-features = false, features = ["std"] }

crates/proof-of-sql/src/base/database/column.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,7 @@ impl ColumnType {
426426
/// Returns `None` if the type is not a signed integer.
427427
/// `sqrt_negative_min(NumericalType) = floor(sqrt(-NumericalType::MIN))`
428428
#[must_use]
429-
#[cfg_attr(not(test), expect(dead_code))]
430-
#[expect(clippy::trivially_copy_pass_by_ref)]
431-
fn sqrt_negative_min(&self) -> Option<u64> {
429+
pub(crate) fn sqrt_negative_min(self) -> Option<u64> {
432430
match self {
433431
ColumnType::TinyInt => Some(11),
434432
ColumnType::SmallInt => Some(181),
@@ -440,7 +438,7 @@ impl ColumnType {
440438
}
441439

442440
/// Returns the number of bits in the integer type if it is an integer type. Otherwise, return None.
443-
fn to_integer_bits(self) -> Option<usize> {
441+
pub(crate) fn to_integer_bits(self) -> Option<usize> {
444442
match self {
445443
ColumnType::Uint8 | ColumnType::TinyInt => Some(8),
446444
ColumnType::SmallInt => Some(16),

crates/proof-of-sql/src/base/database/column_type_operation.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ pub fn try_multiply_column_types(
115115
/// Determine the output type of a divide/modulo operation if it is possible
116116
/// to divide and modulo the two input types. If the types are not compatible, return
117117
/// an error.
118-
#[cfg_attr(not(test), expect(dead_code))]
119-
fn try_divide_modulo_column_types(
118+
pub fn try_divide_modulo_column_types(
120119
lhs: ColumnType,
121120
rhs: ColumnType,
122121
) -> ColumnOperationResult<(ColumnType, ColumnType)> {

crates/proof-of-sql/src/base/database/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ mod slice_decimal_operation;
1414

1515
mod column_type_operation;
1616
pub use column_type_operation::{
17-
try_add_subtract_column_types, try_divide_column_types, try_multiply_column_types,
17+
try_add_subtract_column_types, try_divide_column_types, try_divide_modulo_column_types,
18+
try_multiply_column_types,
1819
};
1920

2021
mod column_arithmetic_operation;

crates/proof-of-sql/src/sql/proof_exprs/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ pub(crate) use comparison_util::scale_and_subtract;
5353

5454
mod numerical_util;
5555
pub(crate) use numerical_util::{
56-
add_subtract_columns, multiply_columns, scale_and_add_subtract_eval,
56+
add_subtract_columns, columns_to_scalar_slice, divide_columns, modulo_columns,
57+
multiply_columns, scale_and_add_subtract_eval,
5758
};
58-
#[cfg(test)]
59-
pub(crate) use numerical_util::{divide_columns, modulo_columns};
6059

6160
mod equals_expr;
6261
pub(crate) use equals_expr::EqualsExpr;

crates/proof-of-sql/src/sql/proof_exprs/numerical_util.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ pub(crate) fn multiply_columns<'a, S: Scalar>(
134134
})
135135
}
136136

137+
/// Convert column to scalar slice.
138+
#[expect(clippy::missing_panics_doc)]
139+
pub(crate) fn columns_to_scalar_slice<'a, S: Scalar>(
140+
column: &Column<'a, S>,
141+
alloc: &'a Bump,
142+
) -> &'a [S] {
143+
alloc.alloc_slice_fill_with(column.len(), |i| column.scalar_at(i).unwrap())
144+
}
145+
137146
#[expect(dead_code)]
138147
/// Multiply two [`ColumnarValues`] together.
139148
/// # Panics
@@ -270,7 +279,6 @@ fn modulo_integer_columns<
270279
/// # Panics
271280
/// Panics if: `lhs` and `rhs` are not of the same length or column type division is unsupported.
272281
#[expect(clippy::too_many_lines)]
273-
#[cfg_attr(not(test), expect(dead_code))]
274282
pub(crate) fn divide_columns<'a, S: Scalar>(
275283
lhs: &Column<'a, S>,
276284
rhs: &Column<'a, S>,
@@ -394,7 +402,6 @@ pub(crate) fn divide_columns<'a, S: Scalar>(
394402
/// Take the modulo of one column against another.
395403
/// # Panics
396404
/// Panics if: `lhs` and `rhs` are not of the same length.
397-
#[cfg_attr(not(test), expect(dead_code))]
398405
pub(crate) fn modulo_columns<'a, S: Scalar>(
399406
lhs: &Column<'a, S>,
400407
rhs: &Column<'a, S>,

0 commit comments

Comments
 (0)