LorrensP-2158466 commented on code in PR #11084:
URL: https://github.com/apache/datafusion/pull/11084#discussion_r1650523030


##########
datafusion/common/src/scalar/mod.rs:
##########
@@ -1177,40 +1185,103 @@ impl ScalarValue {
             | ScalarValue::Float64(None) => Ok(self.clone()),
             ScalarValue::Float64(Some(v)) => 
Ok(ScalarValue::Float64(Some(-v))),
             ScalarValue::Float32(Some(v)) => 
Ok(ScalarValue::Float32(Some(-v))),
-            ScalarValue::Int8(Some(v)) => Ok(ScalarValue::Int8(Some(-v))),
-            ScalarValue::Int16(Some(v)) => Ok(ScalarValue::Int16(Some(-v))),
-            ScalarValue::Int32(Some(v)) => Ok(ScalarValue::Int32(Some(-v))),
-            ScalarValue::Int64(Some(v)) => Ok(ScalarValue::Int64(Some(-v))),
+            ScalarValue::Int8(Some(v)) => 
Ok(ScalarValue::Int8(Some(v.neg_checked()?))),
+            ScalarValue::Int16(Some(v)) => 
Ok(ScalarValue::Int16(Some(v.neg_checked()?))),
+            ScalarValue::Int32(Some(v)) => 
Ok(ScalarValue::Int32(Some(v.neg_checked()?))),
+            ScalarValue::Int64(Some(v)) => 
Ok(ScalarValue::Int64(Some(v.neg_checked()?))),
             ScalarValue::IntervalYearMonth(Some(v)) => {
-                Ok(ScalarValue::IntervalYearMonth(Some(-v)))
+                Ok(ScalarValue::IntervalYearMonth(Some(neg_checked_with_ctx(
+                    *v,
+                    format!("In negation of IntervalYearMonth({v})"),
+                )?)))
             }
             ScalarValue::IntervalDayTime(Some(v)) => {
                 let (days, ms) = IntervalDayTimeType::to_parts(*v);
-                let val = IntervalDayTimeType::make_value(-days, -ms);
+                let val = IntervalDayTimeType::make_value(
+                    neg_checked_with_ctx(
+                        days,
+                        format!("In negation of days {days} in 
IntervalDayTime"),

Review Comment:
   Yeah, I first tried that, but I didn't like repeating the same thing for 
every case. But this went over my head, I'll fix this back to `map_err`. Thanks 
for the tip!



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