mbutrovich commented on code in PR #3574:
URL: https://github.com/apache/iceberg-rust/pull/3574#discussion_r4802409958


##########
crates/iceberg/src/spec/values/datum.rs:
##########
@@ -1132,25 +1132,19 @@ impl Datum {
         match target_type {
             Type::Primitive(target_primitive_type) => {
                 match (&self.literal, &self.r#type, target_primitive_type) {
-                    (PrimitiveLiteral::Int(val), _, PrimitiveType::Int) => 
Ok(Datum::int(*val)),
-                    (PrimitiveLiteral::Int(val), _, PrimitiveType::Date) => 
Ok(Datum::date(*val)),
-                    (PrimitiveLiteral::Int(val), _, PrimitiveType::Long) => 
Ok(Datum::long(*val)),
-                    (PrimitiveLiteral::Long(val), _, PrimitiveType::Int) => {
-                        Ok(Datum::i64_to_i32(*val))
+                    (_, self_type, target_type) if self_type == target_type => 
Ok(self),
+                    (PrimitiveLiteral::Int(val), source_type, target_type) => {
+                        convert_int(*val, source_type, target_type)
+                    }
+                    (PrimitiveLiteral::Long(val), source_type, target_type) => 
{
+                        convert_long(*val, source_type, target_type)
                     }
                     (PrimitiveLiteral::Double(val), _, PrimitiveType::Float) 
=> {
                         Ok(Datum::f64_to_f32(val.0))
                     }
                     (PrimitiveLiteral::Float(val), _, PrimitiveType::Double) 
=> {
                         Ok(Datum::double(val.0 as f64))
                     }
-                    (PrimitiveLiteral::Long(val), _, PrimitiveType::Timestamp) 
=> {
-                        Ok(Datum::timestamp_micros(*val))
-                    }
-                    (PrimitiveLiteral::Long(val), _, 
PrimitiveType::Timestamptz) => {
-                        Ok(Datum::timestamptz_micros(*val))
-                    }

Review Comment:
   > Updated.
   
   Thanks. Could the description and title describe the change against `main`? 
On `main`, `timestamp_ns` to `date` already returns an error, so that example 
isn't something this PR removes. The arms this PR removes convert any 
`long`-backed literal (`long`, `time`, and every timestamp type) to `timestamp` 
or `timestamptz` and keep the raw value 
([datum.rs#L1167-L1172](https://github.com/apache/iceberg-rust/blob/6cca8cdec6881d057581bdf9cc21c3ad426c0283/crates/iceberg/src/spec/values/datum.rs#L1167-L1172)).
 For the precision case, `timestamp_ns` to `timestamp` is a better example, 
because `main` keeps the nanosecond count as microseconds there.
   
   The title only names what the PR adds. A caller that binds a `long`, `time`, 
or other-zone timestamp literal to a timestamp column now gets an error, so a 
title like `fix: convert date literals to timestamps and reject unsafe 
timestamp conversions` would put that in the changelog.



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