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(expr): fix interval div float #3631

Merged
merged 9 commits into from
Jul 4, 2022
Merged

fix(expr): fix interval div float #3631

merged 9 commits into from
Jul 4, 2022

Conversation

shmiwy
Copy link
Contributor

@shmiwy shmiwy commented Jul 4, 2022

Signed-off-by: Shmiwy wyf000219@126.com

I hereby agree to the terms of the Singularity Data, Inc. Contributor License Agreement.

What's changed and what's your intention?

select interval '1' year / 5;
        ?column?         
-------------------------
 2 mons 11 days 24:00:00
(1 row)

where we should get 2 mons 12 days 00:00:00

https://github.com/singularity-data/risingwave/blob/722ba98b33fe87e8de028d31d57f7bd63d6bcd63/src/common/src/types/interval.rs#L199

float are not exact in computer, so it is not advisable to use float numbers directly for mod and division operations. Thus, the month numbers are inexact. As in the example above, where we should get 12.0, but often we get 11.99999999

Checklist

  • I have written necessary docs and comments
  • I have added necessary unit tests and integration tests
  • All checks passed in ./risedev check (or alias, ./risedev c)

Refer to a related PR or issue link (optional)

#3341

Signed-off-by: Shmiwy <wyf000219@126.com>
@shmiwy shmiwy requested review from jon-chuang and xiangjinwu and removed request for jon-chuang July 4, 2022 10:01
@shmiwy shmiwy requested a review from skyzh July 4, 2022 10:34
@codecov
Copy link

codecov bot commented Jul 4, 2022

Codecov Report

Merging #3631 (ab84dd7) into main (927fae2) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #3631   +/-   ##
=======================================
  Coverage   74.37%   74.37%           
=======================================
  Files         776      776           
  Lines      110155   110163    +8     
=======================================
+ Hits        81927    81934    +7     
- Misses      28228    28229    +1     
Flag Coverage Δ
rust 74.37% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/common/src/types/interval.rs 79.80% <100.00%> (+0.54%) ⬆️
src/common/src/types/ordered_float.rs 24.70% <0.00%> (-0.20%) ⬇️
src/meta/src/manager/id.rs 95.50% <0.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

Copy link
Contributor

@skyzh skyzh left a comment

Choose a reason for hiding this comment

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

Rest LGTM

@@ -196,7 +196,10 @@ impl IntervalUnit {
}

let months = (self.months as f64) / rhs;
let days = (self.days as f64) / rhs + (months % 1.0) * 30.0;
let mut days = (self.days as f64) / rhs + (months % 1.0) * 30.0;
if (days - days.round()).abs() <= 0.0000001 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shmiwy added 6 commits July 4, 2022 19:29
Signed-off-by: Shmiwy <wyf000219@126.com>
Signed-off-by: Shmiwy <wyf000219@126.com>
Signed-off-by: Shmiwy <wyf000219@126.com>
Signed-off-by: Shmiwy <wyf000219@126.com>
@skyzh skyzh added the mergify/can-merge Indicates that the PR can be added to the merge queue label Jul 4, 2022
@mergify mergify bot merged commit fe8142a into risingwavelabs:main Jul 4, 2022
@shmiwy shmiwy deleted the interval_mul_float branch July 4, 2022 15:29
nasnoisaac pushed a commit to nasnoisaac/risingwave that referenced this pull request Aug 9, 2022
* fix(expr): fix interval div float

Signed-off-by: Shmiwy <wyf000219@126.com>

* fix(expr): fix interval div float

Signed-off-by: Shmiwy <wyf000219@126.com>

* fix(expr): fix interval div float

Signed-off-by: Shmiwy <wyf000219@126.com>

* fix(expr): fix interval div float

Signed-off-by: Shmiwy <wyf000219@126.com>

* fix(expr): fix interval div float

Signed-off-by: Shmiwy <wyf000219@126.com>

* fix(expr): fix interval div float

Signed-off-by: Shmiwy <wyf000219@126.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mergify/can-merge Indicates that the PR can be added to the merge queue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants