-
-
Notifications
You must be signed in to change notification settings - Fork 28
fix: Decimal conversion with too many low digits #703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR, still have some questions / change requests though.
n | ||
} | ||
|
||
trait ToDecimal: | ||
FromRadix10 + FromRadix10Signed + Add<Output = Self> + Sub<Output = Self> + MulAssign + Ord | ||
FromRadix10 + FromRadix10Signed + Add<Output = Self> + Sub<Output = Self> + MulAssign + std::ops::Div<Output = Self> // Add Div requirement for right-shifting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Could we use
DivAssign
instead ofCopy
andDiv
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, no. Using DivAssign
instead of Div
and Copy
results in:
cannot divide `I` by `I`
consider further restricting type parameter `I` with trait `Div`: ` + std::ops::Div<Output = I>`
n | ||
} | ||
|
||
trait ToDecimal: | ||
FromRadix10 + FromRadix10Signed + Add<Output = Self> + Sub<Output = Self> + MulAssign + Ord | ||
FromRadix10 + FromRadix10Signed + Add<Output = Self> + Sub<Output = Self> + MulAssign + std::ops::Div<Output = Self> // Add Div requirement for right-shifting | ||
+ Ord |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need Ord
don't we only compare usize
if we count digits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, Ord
was a trait bound that already existed. I tried removing it, and some errors for equality occur:
binary operation `<` cannot be applied to type `I`
binary operation `==` cannot be applied to type `I`
We could use PartialEq
and PartialOrd
instead, but it's basically equivalent to Ord
anyway.
Merged and released, thanks for the contribution |
🗣 Description
For example, when performing an
avg()
query with a decimal source column, the output avg column receives a scale of(_, 6)
but the actual data received was a decimal with 16 fractional digits (e.g.12.3456789000000000
). In this example, we truncate the digits to the specified scale for the field leaving behind the actual data of12.345678
.Depending on the query, the existing behavior can result in panics from subtraction overflow. For example: spiceai/spiceai#1907