realno commented on a change in pull request #1525: URL: https://github.com/apache/arrow-datafusion/pull/1525#discussion_r780582709
########## File path: datafusion/src/scalar.rs ########## @@ -526,6 +526,282 @@ macro_rules! eq_array_primitive { } impl ScalarValue { + /// Return true if the value is numeric + pub fn is_numeric(&self) -> bool { + matches!(self, + ScalarValue::Float32(_) + | ScalarValue::Float64(_) + | ScalarValue::Decimal128(_, _, _) + | ScalarValue::Int8(_) + | ScalarValue::Int16(_) + | ScalarValue::Int32(_) + | ScalarValue::Int64(_) + | ScalarValue::UInt8(_) + | ScalarValue::UInt16(_) + | ScalarValue::UInt32(_) + | ScalarValue::UInt64(_) + ) + } + + /// Add two numeric ScalarValues + pub fn add(lhs: &ScalarValue, rhs: &ScalarValue) -> Result<ScalarValue> { Review comment: Completely agree. My feeling is these basic operations could be implemented in ScalarValue since many operators will depend on them. I want to pick your brain (and other contributor's too) if you think this is a good idea - this deserves a seperate discussion. Also with the way ScalarValue is implemented currently each operator needs a huge match block, maybe using generics can make it a little easier? Here are some options I propose: 1. Remove the redundency, I can either move sum to Scalavalue or the other direction is fine. Personally I prefer to have it in ScalarValue. 2. Leave the code as is until we have a discussion/conclusion around how to handle arithmetic operation for ScalarValue. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org