From 48ac11cb1067bd15043b573ca6bfc9352fccfebd Mon Sep 17 00:00:00 2001 From: Dean Kamali Date: Fri, 16 Oct 2026 04:37:55 +0000 Subject: [PATCH] fix: keep correlated args intact in table function sources --- datafusion/core/src/execution/session_state.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/datafusion/core/src/execution/session_state.rs b/datafusion/core/src/execution/session_state.rs index ee707162908a4..b6e7b78c1564d 100644 --- a/datafusion/core/src/execution/session_state.rs +++ b/datafusion/core/src/execution/session_state.rs @@ -2021,10 +2021,18 @@ impl ContextProvider for SessionContextProvider<'_> { let args = args .into_iter() .map(|(arg, name)| { - simplifier - .coerce(arg, &schema) - .and_then(|e| simplifier.simplify(e)) - .map(|expr| (expr, name)) + // Expressions referencing columns (e.g. correlated arguments + // of lateral table functions) cannot be type-coerced or + // simplified against an empty schema; pass them through + // unchanged. Column-free expressions keep constant folding. + if arg.column_refs().is_empty() { + simplifier + .coerce(arg, &schema) + .and_then(|e| simplifier.simplify(e)) + .map(|expr| (expr, name)) + } else { + Ok((arg, name)) + } }) .collect::>>()?; let (exprs, names): (Vec<_>, Vec<_>) = args.into_iter().unzip();