kevinjqliu commented on code in PR #3323:
URL: https://github.com/apache/iceberg-rust/pull/3323#discussion_r4179297030
##########
crates/iceberg/src/transform/temporal.rs:
##########
@@ -2650,6 +2651,48 @@ mod test {
test_timestamp_ns_and_tz_transform("2017-12-01T10:30:42.123000", &day,
Datum::date(17501));
}
+ #[test]
+ fn test_transform_days_pre_epoch() {
+ let day = Box::new(super::Day) as BoxedTransformFunction;
+ let expected = [-1, -2, -2, -2, -2, -366, -365];
+
+ let micros = vec![
+ -500_000, // 1969-12-31T23:59:59.500000
+ -86_400_000_001, // 1969-12-30T23:59:59.999999
+ -86_400_000_002, // 1969-12-30T23:59:59.999998
+ -86_400_500_000, // 1969-12-30T23:59:59.500000
+ -86_401_000_000, // 1969-12-30T23:59:59.000000
+ -31_536_000_500_000, // 1968-12-31T23:59:59.500000
+ -31_535_999_000_001, // 1969-01-01T00:00:00.999999, Iceberg Java
gives -366
Review Comment:
this is a bug on the java side
see https://github.com/apache/iceberg/issues/18371
##########
crates/iceberg/src/transform/temporal.rs:
##########
@@ -205,50 +205,13 @@ pub struct Day;
impl Day {
#[inline]
- fn day_timestamp_micro(v: i64) -> Result<i32> {
- let secs = v / MICROS_PER_SECOND;
-
- let (nanos, offset) = if v >= 0 {
- let nanos = (v.rem_euclid(MICROS_PER_SECOND) * 1_000) as u32;
- let offset = 0i64;
- (nanos, offset)
- } else {
- let v = v + 1;
- let nanos = (v.rem_euclid(MICROS_PER_SECOND) * 1_000) as u32;
- let offset = 1i64;
- (nanos, offset)
- };
-
- let delta = Duration::new(secs, nanos).ok_or_else(|| {
- invalid_data!("Failed to create 'TimeDelta' from seconds {secs}
and nanos {nanos}")
- })?;
-
- let days = (delta.num_days() - offset) as i32;
-
- Ok(days)
+ fn day_timestamp_micro(v: i64) -> i32 {
Review Comment:
I don't think we need to document this in the code comment.
This seems like a bug on the java side (`DateTimeUtil.convertMicros`),
rust's behavior matches the spec. Lets just open an issue in on java instead
Opened one: https://github.com/apache/iceberg/issues/18371
--
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]