andygrove commented on code in PR #3370:
URL: https://github.com/apache/arrow-datafusion/pull/3370#discussion_r963813756
##########
datafusion/common/src/scalar.rs:
##########
@@ -710,24 +710,26 @@ impl ScalarValue {
}
/// Calculate arithmetic negation for a scalar value
- pub fn arithmetic_negate(&self) -> Self {
+ pub fn arithmetic_negate(&self) -> Result<Self> {
match self {
- ScalarValue::Boolean(None)
- | ScalarValue::Int8(None)
+ ScalarValue::Int8(None)
| ScalarValue::Int16(None)
| ScalarValue::Int32(None)
| ScalarValue::Int64(None)
- | ScalarValue::Float32(None) => self.clone(),
- ScalarValue::Float64(Some(v)) => ScalarValue::Float64(Some(-v)),
- ScalarValue::Float32(Some(v)) => ScalarValue::Float32(Some(-v)),
- ScalarValue::Int8(Some(v)) => ScalarValue::Int8(Some(-v)),
- ScalarValue::Int16(Some(v)) => ScalarValue::Int16(Some(-v)),
- ScalarValue::Int32(Some(v)) => ScalarValue::Int32(Some(-v)),
- ScalarValue::Int64(Some(v)) => ScalarValue::Int64(Some(-v)),
+ | ScalarValue::Float32(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::Decimal128(Some(v), precision, scale) => {
- ScalarValue::Decimal128(Some(-v), *precision, *scale)
+ Ok(ScalarValue::Decimal128(Some(-v), *precision, *scale))
}
- _ => panic!("Cannot run arithmetic negate on scalar value: {:?}",
self),
+ value => Err(DataFusionError::Internal(format!(
Review Comment:
Thanks!
--
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]