alamb commented on a change in pull request #716:
URL: https://github.com/apache/arrow-datafusion/pull/716#discussion_r668145983



##########
File path: datafusion/src/physical_plan/functions.rs
##########
@@ -468,7 +468,15 @@ pub fn return_type(
         | BuiltinScalarFunction::Sin
         | BuiltinScalarFunction::Sqrt
         | BuiltinScalarFunction::Tan
-        | BuiltinScalarFunction::Trunc => Ok(DataType::Float64),
+        | BuiltinScalarFunction::Trunc => {
+            if arg_types.len() <= 0 {
+                return Err(DataFusionError::Internal(String::from(
+                    "Builtin Scalar Function does not support empty arguments",
+                )));
+            }
+            // return the same type as the input argument
+            return Ok(arg_types.get(0).unwrap().clone());

Review comment:
       I think this probably should special case f32 and f64 inputs -- as 
`abs(string)` doesn't really make sense
   
   So something like the following:
   
   ```
   match arg_types[0] {
     DataType:Float32 | DataType::Float64 => arg_types[0].clone(),
     _  => Err("invalid input type to function {}: {}, expected Float32 or 
Float64 ", func, input_types[0])))
   ```
   
   However, I can't remember if input coercion has happened by the time this 
function is called (e.g. we should support `sqrt(1)` (aka sqrt of an integral 
number)




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


Reply via email to