jorgecarleitao commented on a change in pull request #7967:
URL: https://github.com/apache/arrow/pull/7967#discussion_r471688534



##########
File path: rust/datafusion/tests/sql.rs
##########
@@ -232,6 +326,55 @@ fn custom_sqrt(args: &[ArrayRef]) -> Result<ArrayRef> {
     Ok(Arc::new(builder.finish()))
 }
 
+fn custom_add(args: &[ArrayRef]) -> Result<ArrayRef> {
+    match (args[0].data_type(), args[1].data_type()) {
+        (DataType::Float64, DataType::Float64) => {
+            let input1 = &args[0]
+                .as_any()
+                .downcast_ref::<Float64Array>()
+                .expect("cast failed");
+            let input2 = &args[1]
+                .as_any()
+                .downcast_ref::<Float64Array>()
+                .expect("cast failed");
+
+            let mut builder = Float64Builder::new(input1.len());
+            for i in 0..input1.len() {
+                if input1.is_null(i) || input2.is_null(i) {
+                    builder.append_null()?;
+                } else {
+                    builder.append_value(input1.value(i) + input2.value(i))?;
+                }
+            }
+            Ok(Arc::new(builder.finish()))
+        }
+        (DataType::Float32, DataType::Float32) => {
+            // all other cases return a constant vector (just to be diferent)
+            let mut builder = Float64Builder::new(args[0].len());
+            for _ in 0..args[0].len() {
+                builder.append_value(3232.0)?;
+            }
+            Ok(Arc::new(builder.finish()))
+        }
+        (DataType::Float32, DataType::Float64) => {
+            // all other cases return a constant vector (just to be diferent)
+            let mut builder = Float64Builder::new(args[0].len());
+            for _ in 0..args[0].len() {
+                builder.append_value(3264.0)?;
+            }
+            Ok(Arc::new(builder.finish()))
+        }
+        (_, _) => {
+            // all other cases return a constant vector (just to be diferent)

Review comment:
       Good point. I made the function return an Err instead, and asserted that 
the result of the execution is an error. 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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to