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 date conversion if timestamp below unixtimestamp #4323

Merged
merged 2 commits into from
May 31, 2023

Conversation

comphead
Copy link
Contributor

Which issue does this PR close?

Closes #4211 .

Rationale for this change

Fix date conversion if timestamp below unixtimestamp

What changes are included in this PR?

Are there any user-facing changes?

No

@github-actions github-actions bot added the arrow Changes to the arrow crate label May 31, 2023
@comphead
Copy link
Contributor Author

@parthchandra @viirya

arrow-cast/src/cast.rs Outdated Show resolved Hide resolved
arrow-cast/src/cast.rs Outdated Show resolved Hide resolved
arrow-cast/src/cast.rs Outdated Show resolved Hide resolved
arrow-cast/src/cast.rs Outdated Show resolved Hide resolved
arrow-cast/src/cast.rs Outdated Show resolved Hide resolved
@comphead
Copy link
Contributor Author

Thanks @tustvold I will address the comments. Probably we need to review all tests for cast and use new syntax instead of downcast?

@@ -1853,7 +1853,7 @@ pub fn cast_with_options(
if time_array.is_null(i) {
b.append_null();
} else {
b.append_value((time_array.value(i) / from_size) as i32);
b.append_value(num::integer::div_floor::<i64>(time_array.value(i), from_size) as i32);
Copy link
Contributor

Choose a reason for hiding this comment

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

Something like

                    let pre_epoch_adjustment = if value(i) < 0 { -1 } else { 0 };
                    b.append_value(pre_epoch_adjustment + (time_array.value(i) / from_size) as i32);

might be faster (because it skips all the check made by div_floor) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

If you look at the implementation of div floor, that is what it is implemented as

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can this convo be resolved then?

Copy link
Contributor

Choose a reason for hiding this comment

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

@tustvold you'er right. My ide led me to the BigInt implementation of div_floor which is necessarily more complex, but not relevant here.

@comphead comphead requested a review from tustvold May 31, 2023 17:42
Copy link
Contributor

@tustvold tustvold 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, looks good to me

@@ -9172,4 +9172,41 @@ mod tests {
);
assert!(casted_array.is_err());
}

#[test]
fn test_cast_below_unixtimestamp() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I confirmed this test fails on master

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.

Casting Timestamp to date is off by one day for dates before 1970-01-01
3 participants