-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: add support for Decimal128 and Decimal256 types in interval arithmetic #14126
base: main
Are you sure you want to change the base?
Conversation
…hmetic Signed-off-by: Ruihang Xia <[email protected]>
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.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
Signed-off-by: Ruihang Xia <[email protected]>
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.
thanks @waynexia
I feed we can also add the initial problematic query into .slt
file?
SELECT ('0.54321543215432154321543215432154321'::DECIMAL(35,35) + 10000)::VARCHAR
Signed-off-by: Ruihang Xia <[email protected]>
Done 👍, added one in |
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.
Thank you for the bug fix @waynexia
I am not sure about the code for min/max extremes however
@@ -76,6 +76,14 @@ macro_rules! get_extreme_value { | |||
DataType::Interval(IntervalUnit::MonthDayNano) => { | |||
ScalarValue::IntervalMonthDayNano(Some(IntervalMonthDayNano::$extreme)) | |||
} | |||
DataType::Decimal128(precision, scale) => { | |||
ScalarValue::Decimal128(Some(i128::$extreme), *precision, *scale) |
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.
Is this correct for min/max of i128? It seems like the minimum value of Decimal128(precision, scale) would be the minimum value for the precision and scale separately rather than the min value of the overall i128 🤔
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 dug around in arrow a bit and I think these are the min/max values for each decimal precision
https://docs.rs/arrow/latest/arrow/datatypes/constant.MIN_DECIMAL_FOR_EACH_PRECISION.html
https://docs.rs/arrow/latest/arrow/datatypes/constant.MAX_DECIMAL_FOR_EACH_PRECISION.html
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.
Ahh, that makes sense. These huge arrays remind me it should be all of 9
s...
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.
sadly the decimal 256 version is not public 😢 let me find a workaround
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.
maybe get_extreme_value
should be part of arrow?
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.
sadly the decimal 256 version is not public 😢 let me find a workaround
I recommend
- copy/pasting the value into DataFusion for now
- File a ticket in arrow-rs to make it public (or maybe even a PR!)
- leave a comment next to the copy in DataFUsion referencing the upstream ticket
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 filed a PR in arrow to expose these constants:
wait for apache/datafusion#14126 to fix this
…hmetic
Which issue does this PR close?
Closes #14124
Rationale for this change
Fixes the panic when decimal computation overflows
What changes are included in this PR?
This patch contains two fixes:
get_extreme_value
for decimal 128 and 256 typesAre these changes tested?
adding test
Are there any user-facing changes?