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

Update IntervalMonthDayNanoType::make_value() to conform to specifications #2235

Merged
merged 4 commits into from
Aug 1, 2022

Conversation

avantgardnerio
Copy link
Contributor

Which issue does this PR close?

Closes #2234.

Rationale for this change

Fix bug that will cause users to generate incorrect interval values.

What changes are included in this PR?

Revised implementation of IntervalMonthDayNanoType::make_value() and better inline documentation.

Are there any user-facing changes?

Erroneous durations will be fixed.

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jul 29, 2022
@avantgardnerio
Copy link
Contributor Author

avantgardnerio commented Jul 29, 2022

@alamb I could use a second set of eyes to make sure it is correct this time. Sincere apologies for merging non-conforming code.

@codecov-commenter
Copy link

codecov-commenter commented Jul 30, 2022

Codecov Report

Merging #2235 (5c4d400) into master (bedeb4f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2235   +/-   ##
=======================================
  Coverage   82.31%   82.31%           
=======================================
  Files         240      241    +1     
  Lines       62445    62455   +10     
=======================================
+ Hits        51400    51410   +10     
  Misses      11045    11045           
Impacted Files Coverage Δ
arrow/src/datatypes/types.rs 97.93% <100.00%> (+0.46%) ⬆️
...rquet/src/arrow/record_reader/definition_levels.rs 88.60% <0.00%> (-0.43%) ⬇️
parquet/src/arrow/array_reader/builder.rs 99.29% <0.00%> (-0.06%) ⬇️
arrow/src/array/mod.rs 100.00% <0.00%> (ø)
parquet/src/arrow/schema.rs 96.93% <0.00%> (ø)
integration-testing/src/lib.rs 0.00% <0.00%> (ø)
arrow/src/datatypes/datatype.rs 63.00% <0.00%> (ø)
arrow/src/array/array_fixed_size_binary.rs 90.37% <0.00%> (ø)
arrow/src/compute/kernels/cast.rs 95.82% <0.00%> (+<0.01%) ⬆️
arrow/src/datatypes/ffi.rs 76.65% <0.00%> (+0.09%) ⬆️
... and 4 more

Help us with your feedback. Take ten seconds to tell us how you rate us.

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.

Thanks @avantgardnerio -- the pictures are 😍

Can you please add some unit tests (maybe showing that values make it through roundtrip)?

LIke

let value = IntervalMonthDayNanoType::make_value(1, 2, 3);
assert_eq!(IntervalMonthDayNanoType::to_parts(value), (1,2,3));

I think that type of test would would have caught this bug in the first place as well

@@ -232,6 +232,16 @@ impl IntervalDayTimeType {
days: i32,
millis: i32,
) -> <IntervalDayTimeType as ArrowPrimitiveType>::Native {
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

Comment on lines +302 to +304
let months = (i >> 96) as i32;
let days = (i >> 64) as i32;
let nanos = i as i64;
Copy link
Contributor

Choose a reason for hiding this comment

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

Re-reading this now with your great pictures, I was wondering if we had to mask off the remaining bits in the other fields -- otherwise the days will also include the months

However, after some thought, I think the truncation done via as i32 and as i64 should be good enough

@avantgardnerio
Copy link
Contributor Author

Can you please add some unit tests

I did, and they indeed caught another bug. I was failing to mask the nanos during make_value() ☹️

@avantgardnerio avantgardnerio requested a review from alamb July 31, 2022 18:30
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.

LGTM -- Thanks again @avantgardnerio

@tustvold tustvold merged commit d4f038a into apache:master Aug 1, 2022
@ursabot
Copy link

ursabot commented Aug 1, 2022

Benchmark runs are scheduled for baseline = 2c09ba4 and contender = d4f038a. d4f038a is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

@avantgardnerio avantgardnerio deleted the bg_fix_mdn branch August 2, 2022 22:57
mcheshkov added a commit to cube-js/arrow-rs that referenced this pull request Aug 21, 2024
This implementation was aligned with https://github.com/cube-js/arrow-datafusion/blob/370f91fda4a7e9387dded4edaf2425c447e76fbd/datafusion/physical-expr/src/expressions/binary_distinct.rs#L306-L353

Can drop this after rebase on commit d4f038a " Update IntervalMonthDayNanoType::make_value() to conform to specifications (apache#2235)", first released in 20.0.0
mcheshkov added a commit to cube-js/arrow-rs that referenced this pull request Aug 21, 2024
This implementation was aligned with https://github.com/cube-js/arrow-datafusion/blob/370f91fda4a7e9387dded4edaf2425c447e76fbd/datafusion/physical-expr/src/expressions/binary_distinct.rs#L306-L353

Can drop this after rebase on commit d4f038a " Update IntervalMonthDayNanoType::make_value() to conform to specifications (apache#2235)", first released in 20.0.0
mcheshkov added a commit to cube-js/arrow-rs that referenced this pull request Aug 21, 2024
This implementation was aligned with https://github.com/cube-js/arrow-datafusion/blob/370f91fda4a7e9387dded4edaf2425c447e76fbd/datafusion/physical-expr/src/expressions/binary_distinct.rs#L306-L353

Can drop this after rebase on commit d4f038a " Update IntervalMonthDayNanoType::make_value() to conform to specifications (apache#2235)", first released in 20.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IntervalMonthDayNanoType::make_value() does not match C implementation
7 participants