houqp commented on a change in pull request #8846:
URL: https://github.com/apache/arrow/pull/8846#discussion_r537099150
##########
File path: rust/datafusion/src/physical_plan/expressions.rs
##########
@@ -1682,6 +1691,82 @@ pub fn not(
}
}
+/// Negative expression
+#[derive(Debug)]
+pub struct NegativeExpr {
+ arg: Arc<dyn PhysicalExpr>,
+}
+
+impl NegativeExpr {
+ /// Create new not expression
+ pub fn new(arg: Arc<dyn PhysicalExpr>) -> Self {
+ Self { arg }
+ }
+}
+
+impl fmt::Display for NegativeExpr {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "(- {})", self.arg)
+ }
+}
+
+impl PhysicalExpr for NegativeExpr {
+ fn data_type(&self, input_schema: &Schema) -> Result<DataType> {
+ self.arg.data_type(input_schema)
+ }
+
+ fn nullable(&self, input_schema: &Schema) -> Result<bool> {
+ self.arg.nullable(input_schema)
+ }
+
+ fn evaluate(&self, batch: &RecordBatch) -> Result<ColumnarValue> {
+ let arg = self.arg.evaluate(batch)?;
+ match arg {
+ ColumnarValue::Array(array) => {
+ let result: Result<ArrayRef> = match array.data_type() {
+ DataType::Int8 => compute_op!(array, negate, Int8Array),
+ DataType::Int16 => compute_op!(array, negate, Int16Array),
+ DataType::Int32 => compute_op!(array, negate, Int32Array),
+ DataType::Int64 => compute_op!(array, negate, Int64Array),
+ DataType::Float32 => compute_op!(array, negate,
Float32Array),
+ DataType::Float64 => compute_op!(array, negate,
Float64Array),
+ _ => panic!(
+ "(- '{:?}') can't be evaluated because the
expression's type is {:?}, not signed numeric",
Review comment:
pushed a commit to change this to internal error. also replaced the
unwrap in literal parsing with internal error as well.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]