-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
Description
Describe the bug
Also related to the Decimal. Currently, the constructor DataType::Decimal128/256(precision: usize, scale: usize) is unsound, because users can put any value in it. Also this leads to 2 kinds of bug in the code:
1. forget to check the value of precision and scale
2. redundant checking.
Expected behavior
I’d like to eliminate this unsoundness by using stronger type, which means create a new type for precision and scale:
struct DecimalInfo{
precision: usize,
scale: usize,
}
impl DecimalInfo{
fn new(precision: usize, scale: usize) -> Self {
assert (precision <= max_precision);
assert (scale <= max_precision);
assert (scale <= precision);
Self {precision, scale}
}
fn get_precision {...}
fn get_scale {...}
fn set_scale {...}
fn set_precision {...}
}
enum DataType {
Decimal128(DecimalInfo),
...
}
Additional context
Reactions are currently unavailable