Rewrite Decimal and DecimalArray using const_generic#2383
Rewrite Decimal and DecimalArray using const_generic#2383tustvold merged 3 commits intoapache:masterfrom
Decimal and DecimalArray using const_generic#2383Conversation
Signed-off-by: remzi <[email protected]>
Decimal and DecimalArray using const_genericDecimal and DecimalArray using const_generic
|
Seems like there are some unrelated errors in |
Signed-off-by: remzi <[email protected]>
| data.buffers().len(), | ||
| 1, | ||
| "Decimal128Array data should contain 1 buffer only (values)" | ||
| "DecimalArray data should contain 1 buffer only (values)" |
There was a problem hiding this comment.
We may show Decimal128Array or Decimal256Array based on byte width.
| mod private_decimal { | ||
| pub trait DecimalArrayPrivate { | ||
| fn raw_value_data_ptr(&self) -> *const u8; | ||
| } | ||
| } |
| const DEFAULT_TYPE: DataType; | ||
| const MAX_PRECISION: usize; | ||
| const MAX_SCALE: usize; | ||
| pub struct BasicDecimalArray<const BYTE_WIDTH: usize> { |
There was a problem hiding this comment.
We still have no idea how to constrain byte width, right?
There was a problem hiding this comment.
We could also seal the byte_width in this way:
https://users.rust-lang.org/t/how-to-seal-the-const-generic/77947/2
| pub const DEFAULT_TYPE: DataType = BasicDecimal::<BYTE_WIDTH>::DEFAULT_TYPE; | ||
| pub const MAX_PRECISION: usize = BasicDecimal::<BYTE_WIDTH>::MAX_PRECISION; | ||
| pub const MAX_SCALE: usize = BasicDecimal::<BYTE_WIDTH>::MAX_SCALE; | ||
| pub const TYPE_CONSTRUCTOR: fn(usize, usize) -> DataType = |
There was a problem hiding this comment.
Can TYPE_CONSTRUCTOR be non-public?
| DataType::Decimal256, | ||
| DataType::Decimal256(DECIMAL256_MAX_PRECISION, DECIMAL_DEFAULT_SCALE), | ||
| ), | ||
| _ => panic!("invalid byte width"), |
There was a problem hiding this comment.
We could constrain the byte width here. When compile the constant items, the compiler will give error if byte width != 16 or 32.
@viirya
There was a problem hiding this comment.
Maybe mention what is valid byte width in the message.
tustvold
left a comment
There was a problem hiding this comment.
Really cool, was going to do something similar so awesome you've already done it. Will review in more detail later today
|
|
||
| impl<const BYTE_WIDTH: usize> BasicDecimal<BYTE_WIDTH> { | ||
| #[allow(clippy::type_complexity)] | ||
| const _MAX_PRECISION_SCALE_CONSTRUCTOR_DEFAULT_TYPE: ( |
There was a problem hiding this comment.
As this is not pub, I think MAX_PRECISION_SCALE_CONSTRUCTOR_DEFAULT_TYPE might be okay. A _ prefix seems redundant.
viirya
left a comment
There was a problem hiding this comment.
I have a few comments as above. Otherwise it looks good to me. Thanks for the refactoring.
|
I assume that this PR will not introduce performance regression. But we need more test because weird things often happen. |
Thanks for your concern about performance, that is why I submit these two pr about decimal optimization. #2360 #2357 In our service, there are many columns with decimal data type. |
tustvold
left a comment
There was a problem hiding this comment.
Looks good, will run benchmarks to double check
| impl Decimal128Array { | ||
| /// Creates a [Decimal128Array] with default precision and scale, | ||
| /// based on an iterator of `i128` values without nulls | ||
| pub fn from_iter_values<I: IntoIterator<Item = i128>>(iter: I) -> Self { |
There was a problem hiding this comment.
For the record this method is unsound, but was unsound before. There is a broader issue here
Signed-off-by: remzi <[email protected]>
|
So we don't actually have any decimal benchmarks that I can find... Created #2388 |
|
I'm going to get this in as I think it is a valuable cleanup, and we can continue to iterate on performance in subsequent PRs |
|
Benchmark runs are scheduled for baseline = 56f7904 and contender = 77c814c. 77c814c is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
|
Thank you for your review @viirya @tustvold @liukun4515 |
|
It wasn't 100% clear to me -- but @liukun4515 this PR may have improved decimal validation performance. Perhaps you can run your benchmarks again now to see if things have improved. |
|
I guess one point from @tustvold is that using fixed length slices when constructing decimals would help the compiler elide bounds checks, the performance gain might come from it. |
|
Opened a minor PR #2389 to clean up some comments not addressed yet. |
Signed-off-by: remzi [email protected]
Which issue does this PR close?
This is a subtask of #2384 .
Rationale for this change
What changes are included in this PR?
Are there any user-facing changes?