Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

waynexia
Copy link
Member

@waynexia waynexia commented Jan 14, 2025

…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:

  • fix the logic of checking if a value is negative.
  • implement get_extreme_value for decimal 128 and 256 types

Are these changes tested?

adding test

Are there any user-facing changes?

@waynexia waynexia changed the title fix: add support for Decimal128 and Decimal256 types in interval arit… fix: add support for Decimal128 and Decimal256 types in interval arithmetic Jan 14, 2025
@waynexia waynexia requested a review from Copilot January 14, 2025 13:12

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]>
Copy link
Contributor

@comphead comphead left a 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]>
@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Jan 15, 2025
@waynexia
Copy link
Member Author

thanks @waynexia I feed we can also add the initial problematic query into .slt file?

SELECT ('0.54321543215432154321543215432154321'::DECIMAL(35,35) + 10000)::VARCHAR

Done 👍, added one in select.slt

Copy link
Contributor

@alamb alamb left a 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)
Copy link
Contributor

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 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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 9s...

Copy link
Member Author

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

Copy link
Member Author

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?

Copy link
Contributor

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

  1. copy/pasting the value into DataFusion for now
  2. File a ticket in arrow-rs to make it public (or maybe even a PR!)
  3. leave a comment next to the copy in DataFUsion referencing the upstream ticket

Copy link
Contributor

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:

evenyag added a commit to GreptimeTeam/greptimedb that referenced this pull request Jan 16, 2025
@alamb alamb marked this pull request as draft January 17, 2025 15:22
@alamb alamb marked this pull request as ready for review January 17, 2025 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Regression] Panic when handling Decimal128 overflow
3 participants