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/11/07 17:01:02 UTC

[GitHub] [arrow-datafusion] capkurmagati commented on a change in pull request #1249: Fix some `BuiltinScalarFunction` panics with zero arguments

capkurmagati commented on a change in pull request #1249:
URL: https://github.com/apache/arrow-datafusion/pull/1249#discussion_r744286714



##########
File path: datafusion/src/physical_plan/functions.rs
##########
@@ -1135,6 +1134,15 @@ pub fn create_physical_expr(
     input_schema: &Schema,
     ctx_state: &ExecutionContextState,
 ) -> Result<Arc<dyn PhysicalExpr>> {
+    let args = coerce(args, input_schema, &signature(fun))?;
+
+    let arg_types = args
+        .iter()
+        .map(|e| e.data_type(input_schema))
+        .collect::<Result<Vec<_>>>()?;
+
+    let data_type = return_type(fun, &arg_types)?;

Review comment:
       To execute `return_type` earlier to assert invalid empty arguments so that direct index usage in `let fun_expr: ScalarFunctionImplementation = match fun` won't panic.

##########
File path: datafusion/src/physical_plan/functions.rs
##########
@@ -3859,28 +3861,56 @@ mod tests {
     }
 
     #[test]
-    fn test_concat_error() -> Result<()> {
+    fn test_empty_arguments_error() -> Result<()> {
         let ctx_state = ExecutionContextState::new();
         let schema = Schema::new(vec![Field::new("a", DataType::Int32, false)]);
 
-        let expr = create_physical_expr(
-            &BuiltinScalarFunction::Concat,
-            &[],
-            &schema,
-            &ctx_state,
-        )?;
+        let funs = [
+            BuiltinScalarFunction::Concat,
+            BuiltinScalarFunction::ToTimestamp,
+            BuiltinScalarFunction::Abs,
+            BuiltinScalarFunction::Repeat,
+        ];

Review comment:
       Don't a good way to loop over the `BuiltinScalarFunction` enum so I picked up some functions for the test.

##########
File path: datafusion/src/physical_plan/functions.rs
##########
@@ -3859,28 +3861,56 @@ mod tests {
     }
 
     #[test]
-    fn test_concat_error() -> Result<()> {
+    fn test_empty_arguments_error() -> Result<()> {
         let ctx_state = ExecutionContextState::new();
         let schema = Schema::new(vec![Field::new("a", DataType::Int32, false)]);
 
-        let expr = create_physical_expr(
-            &BuiltinScalarFunction::Concat,
-            &[],
-            &schema,
-            &ctx_state,
-        )?;
+        let funs = [
+            BuiltinScalarFunction::Concat,
+            BuiltinScalarFunction::ToTimestamp,
+            BuiltinScalarFunction::Abs,
+            BuiltinScalarFunction::Repeat,
+        ];
+
+        for fun in funs.iter() {
+            let expr = create_physical_expr(fun, &[], &schema, &ctx_state);
+
+            match expr {

Review comment:
       Wonder if there's a better way to avoid a match block in another match block.




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