From 2c2289171d0eab3950b2a440b402630b06832018 Mon Sep 17 00:00:00 2001 From: Jay White Date: Wed, 16 Oct 2024 23:49:40 -0400 Subject: [PATCH] refactor: remove dependency on `MAX_SUPPORTED_PRECISION` --- .../src/base/database/column_operation.rs | 50 ++++++++++++++++--- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/crates/proof-of-sql/src/base/database/column_operation.rs b/crates/proof-of-sql/src/base/database/column_operation.rs index be6a2fdde..9a18e8e07 100644 --- a/crates/proof-of-sql/src/base/database/column_operation.rs +++ b/crates/proof-of-sql/src/base/database/column_operation.rs @@ -2,7 +2,7 @@ use super::{ColumnOperationError, ColumnOperationResult}; use crate::base::{ database::ColumnType, - math::decimal::{scale_scalar, DecimalError, Precision, MAX_SUPPORTED_PRECISION}, + math::decimal::{scale_scalar, DecimalError, Precision}, scalar::Scalar, }; use alloc::{format, string::ToString, vec::Vec}; @@ -535,7 +535,13 @@ where // If scale difference is above max decimal precision values // are equal if they are both zero and unequal otherwise let upscale = max_scale - lhs_scale; - if upscale > MAX_SUPPORTED_PRECISION as i8 { + if i8::try_from( + right_column_type + .precision_value() + .expect("Decimal types have scale"), + ) + .is_ok_and(|precision| upscale > precision) + { lhs.iter() .zip(rhs.iter()) .map(|(l, r)| -> bool { l.is_zero() && *r == S::ZERO }) @@ -550,7 +556,13 @@ where } } else if rhs_scale < max_scale { let upscale = max_scale - rhs_scale; - if upscale > MAX_SUPPORTED_PRECISION as i8 { + if i8::try_from( + left_column_type + .precision_value() + .expect("Numeric types have scale"), + ) + .is_ok_and(|precision| upscale > precision) + { lhs.iter() .zip(rhs.iter()) .map(|(l, r)| -> bool { l.is_zero() && *r == S::ZERO }) @@ -596,7 +608,13 @@ where // always have larger absolute value than the other one as long as it is nonzero // Hence a (extremely upscaled) <= b if and only if a < 0 or (a == 0 and b >= 0) let upscale = max_scale - lhs_scale; - if upscale > MAX_SUPPORTED_PRECISION as i8 { + if i8::try_from( + right_column_type + .precision_value() + .expect("Decimal types have scale"), + ) + .is_ok_and(|precision| upscale > precision) + { lhs.iter() .zip(rhs.iter()) .map(|(l, r)| -> bool { @@ -616,7 +634,13 @@ where } } else if rhs_scale < max_scale { let upscale = max_scale - rhs_scale; - if upscale > MAX_SUPPORTED_PRECISION as i8 { + if i8::try_from( + left_column_type + .precision_value() + .expect("Numeric types have scale"), + ) + .is_ok_and(|precision| upscale > precision) + { // Similarly with extreme scaling we have // a <= (extremely upscaled) b if and only if a < 0 or (a == 0 and b >= 0) lhs.iter() @@ -669,7 +693,13 @@ where // always have larger absolute value than the other one as long as it is nonzero // Hence a (extremely upscaled) >= b if and only if a > 0 or (a == 0 and b <= 0) let upscale = max_scale - lhs_scale; - if upscale > MAX_SUPPORTED_PRECISION as i8 { + if i8::try_from( + right_column_type + .precision_value() + .expect("Decimal types have scale"), + ) + .is_ok_and(|precision| upscale > precision) + { lhs.iter() .zip(rhs.iter()) .map(|(l, r)| -> bool { @@ -689,7 +719,13 @@ where } } else if rhs_scale < max_scale { let upscale = max_scale - rhs_scale; - if upscale > MAX_SUPPORTED_PRECISION as i8 { + if i8::try_from( + left_column_type + .precision_value() + .expect("Numeric types have scale"), + ) + .is_ok_and(|precision| upscale > precision) + { // Similarly with extreme scaling we have // a >= (extremely upscaled) b if and only if b < 0 or (a >= 0 and b == 0) lhs.iter()