You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/07/13 13:25:00 UTC

[GitHub] [arrow-datafusion] lvheyang commented on a change in pull request #716: #699 fix return type conflict when calling builtin math fuctions

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



##########
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:
       Yes, the code cannot work because of type coercion rules. I checked the rules, it really supports int as input args type. Thus here we cannot return an error when the input type is not Float32 or Float64.
   
   So I kept the default return type, but add a float32 match arm as a special case.
   
   And I also changed the behavior of ColumnarValue::Scalar  to be the same as ColumnarValue::Array(array). The test case passed this time.  >_<




-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org