Skip to content

The constructor DataType::Decimal(usize, usize) is unvalidated #2362

@HaoYang670

Description

@HaoYang670

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions