The constructor `DataType::Decimal(usize, usize)` is unvalidated
- Dominant language
- Rust
- Stars
- 3.6k
- Forks
- 1.3k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 167
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**
Contributor guide
Research direction
Start by locating the DataType::Decimal128/256 definitions and all constructor call sites, then trace where precision and scale are validated. The work is done when DecimalInfo enforces the stated invariants and redundant or missing checks are removed without leaving invalid decimal values constructible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- data-engineering
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100