Skip to content

Commit

Permalink
refactor: remove dependency of column_operation on `MAX_SUPPORTED_P…
Browse files Browse the repository at this point in the history
…RECISION` (#275)

# Rationale for this change

`MAX_SUPPORTED_PRECISION` should not be relevant outside of the
`Precision` newtype

# What changes are included in this PR?

The `column_operation` module no longer uses `MAX_SUPPORTED_PRECISION`.

# Are these changes tested?
Yes, by existing tests.
  • Loading branch information
iajoiner authored Oct 17, 2024
2 parents b1179f6 + 2c22891 commit e98d9fc
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions crates/proof-of-sql/src/base/database/column_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 })
Expand All @@ -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 })
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand Down

0 comments on commit e98d9fc

Please sign in to comment.