CTTY commented on code in PR #3522:
URL: https://github.com/apache/iceberg-rust/pull/3522#discussion_r4571931088


##########
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:
   we should move this to temporal.rs, there are already conversions like this



##########
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:
   `PrimitiveLiteral::promote_to` and `Datum::promote_to` now cover different 
promotion sets under the same name. we could add some doc to 
`PrimitiveLiteral::promote_to` to help differentiate them



-- 
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