ump45nose commented on code in PR #3522:
URL: https://github.com/apache/iceberg-rust/pull/3522#discussion_r4578522456
##########
crates/iceberg/src/spec/values/primitive.rs:
##########
@@ -159,3 +161,18 @@ impl PrimitiveLiteral {
}
}
}
+
+pub(crate) const MICROSECONDS_PER_DAY: i64 = 86_400_000_000;
+pub(crate) const NANOSECONDS_PER_DAY: i64 = 86_400_000_000_000;
+
+/// Converts `days` from the epoch to a timestamp literal in units of
`units_per_day`.
+pub(crate) fn date_to_timestamp(
Review Comment:
Moved in 4adddcc. The day constants and the conversion now live in
`spec/values/temporal.rs` under `date` as `days_to_microseconds` /
`days_to_nanoseconds` (both return `None` on `i64` overflow, next to
`date_to_days` and friends). `datum.rs` keeps only a small private
`date_to_timestamp(days, target)` that picks the unit from `target` and turns
the overflow into `DataInvalid`, which both the 4-byte bound decode and
`Datum::promote_to` use.
(AI-assisted reply.)
##########
crates/iceberg/src/spec/values/datum.rs:
##########
@@ -1230,14 +1250,45 @@ impl Datum {
}
/// Returns a copy whose literal is widened to `target` for the value
- /// promotions `int` -> `long` and `float` -> `double`, so a value written
- /// under the narrower type compares against a predicate bound to the wider
- /// one. Returns `None` when `target` does not widen this value (decimals
- /// already compare across precisions), so callers can avoid a copy.
- pub(crate) fn promote_to(&self, target: &PrimitiveType) -> Option<Datum> {
- self.literal
- .promote_to(target)
- .map(|literal| Datum::new(target.clone(), literal))
+ /// promotions `int` -> `long`, `float` -> `double`, and `date` ->
`timestamp` /
+ /// `timestamp_ns`, so a value written under the narrower type compares
against
+ /// a predicate bound to the wider one. Returns `Ok(None)` when `target`
does not
+ /// widen this value (decimals already compare across precisions), so
callers
+ /// can avoid a copy.
+ ///
+ /// Matches on `(self.data_type(), target)` so an `int` literal is not
treated as
+ /// a date.
+ ///
+ /// # Errors
+ /// Returns `DataInvalid` if a date is outside the range of the target
timestamp
+ /// type.
+ pub(crate) fn promote_to(&self, target: &PrimitiveType) ->
Result<Option<Datum>> {
Review Comment:
Added a paragraph to `PrimitiveLiteral::promote_to` in 4adddcc: a bare
literal does not know its source type, so it only covers `int -> long` and
`float -> double`, and it points to `Datum::promote_to`, which matches on the
source type and adds `date -> timestamp` / `timestamp_ns`.
(AI-assisted reply.)
--
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]