This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-22097-0c4ace8b77461cac3538d38b1122a7dbf08c4d4f in repository https://gitbox.apache.org/repos/asf/datafusion.git
commit 8441a8f5e9274f2f681f5e86906cbd35deb5639e Author: gstvg <[email protected]> AuthorDate: Wed May 13 11:24:37 2026 -0300 Minor: Disallow async function in lambdas (#22097) ## Which issue does this PR close? Part of #22091. ## Rationale for this change Current async udfs in lambdas fail with generic errors ## What changes are included in this PR? Report an explicit error when trying to create a lambda with async functions ## Are these changes tested? One sqllogictest added to assert the friendly error ## Are there any user-facing changes? What failed before still fail but with a better error --------- Co-authored-by: debonageo <[email protected]> --- datafusion/physical-expr/src/expressions/lambda.rs | 30 +++++++++++++++++++--- datafusion/sqllogictest/test_files/async_udf.slt | 6 +++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/datafusion/physical-expr/src/expressions/lambda.rs b/datafusion/physical-expr/src/expressions/lambda.rs index 5e6dca1a62..9275821ae9 100644 --- a/datafusion/physical-expr/src/expressions/lambda.rs +++ b/datafusion/physical-expr/src/expressions/lambda.rs @@ -21,6 +21,7 @@ use std::hash::Hash; use std::sync::Arc; use crate::{ + ScalarFunctionExpr, expressions::{Column, LambdaVariable}, physical_expr::PhysicalExpr, }; @@ -61,11 +62,16 @@ impl Hash for LambdaExpr { impl LambdaExpr { /// Create a new lambda expression with the given parameters and body pub fn try_new(params: Vec<String>, body: Arc<dyn PhysicalExpr>) -> Result<Self> { - if all_unique(¶ms) { - Ok(Self::new(params, body)) - } else { - plan_err!("lambda params must be unique, got ({})", params.join(", ")) + if !all_unique(¶ms) { + return plan_err!( + "lambda params must be unique, got ({})", + params.join(", ") + ); } + + check_async_udf(&body)?; + + Ok(Self::new(params, body)) } fn new(params: Vec<String>, body: Arc<dyn PhysicalExpr>) -> Self { @@ -179,6 +185,8 @@ impl PhysicalExpr for LambdaExpr { ); }; + check_async_udf(body)?; + Ok(Arc::new(Self::new(self.params.clone(), Arc::clone(body)))) } @@ -210,6 +218,20 @@ fn all_unique(params: &[String]) -> bool { } } +fn check_async_udf(body: &Arc<dyn PhysicalExpr>) -> Result<()> { + if body.exists(|expr| { + Ok(expr + .downcast_ref::<ScalarFunctionExpr>() + .is_some_and(|udf| udf.fun().as_async().is_some())) + })? { + return plan_err!( + "Async functions in lambdas aren't supported, see https://github.com/apache/datafusion/issues/22091" + ); + } + + Ok(()) +} + #[cfg(test)] mod tests { use crate::expressions::{NoOp, lambda::lambda}; diff --git a/datafusion/sqllogictest/test_files/async_udf.slt b/datafusion/sqllogictest/test_files/async_udf.slt index 0708b59e51..683c2a13e6 100644 --- a/datafusion/sqllogictest/test_files/async_udf.slt +++ b/datafusion/sqllogictest/test_files/async_udf.slt @@ -99,3 +99,9 @@ physical_plan 01)ProjectionExec: expr=[__async_fn_0@1 as async_abs(data.x)] 02)--AsyncFuncExec: async_expr=[async_expr(name=__async_fn_0, expr=async_abs(x@0))] 03)----DataSourceExec: partitions=1, partition_sizes=[1] + +# Async udf can't be used in lambdas +query error +select array_transform([1], v -> async_abs(v)); +---- +DataFusion error: Error during planning: Async functions in lambdas aren't supported, see https://github.com/apache/datafusion/issues/22091 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
