liurenjie1024 commented on code in PR #1146:
URL: https://github.com/apache/iceberg-rust/pull/1146#discussion_r2018832174


##########
crates/iceberg/src/transform/temporal.rs:
##########
@@ -337,12 +337,12 @@ pub struct Hour;
 impl Hour {
     #[inline]
     fn hour_timestamp_micro(v: i64) -> i32 {
-        (v / MICROSECONDS_PER_HOUR) as i32
+        (v as f64 / MICROSECONDS_PER_HOUR).floor() as i32
     }
 
     #[inline]
     fn hour_timestamp_nano(v: i64) -> i32 {
-        (v / NANOSECONDS_PER_HOUR) as i32
+        (v as f64 / NANOSECONDS_PER_HOUR).floor() as i32

Review Comment:
   Ditto.



##########
crates/iceberg/src/transform/temporal.rs:
##########
@@ -337,12 +337,12 @@ pub struct Hour;
 impl Hour {
     #[inline]
     fn hour_timestamp_micro(v: i64) -> i32 {
-        (v / MICROSECONDS_PER_HOUR) as i32
+        (v as f64 / MICROSECONDS_PER_HOUR).floor() as i32

Review Comment:
   ```suggestion
          (v.div_euclid(MICROSECONDS_PER_HOUR)) as i32
   ```
   There is a 
[`div_euclid`](https://doc.rust-lang.org/std/primitive.i64.html#method.div_euclid)
 which could help use to do this. The 
[`div_floor`](https://doc.rust-lang.org/std/primitive.i64.html#method.div_floor)
 method seems better, but it's unstable. Give `MICROSECONDS_PER_HOUR` is always 
positive, div_euclid is good enough here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to