This is an automated email from the ASF dual-hosted git repository.
github-bot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 9f27e933ae Coerce expressions to udtf (#19915)
9f27e933ae is described below
commit 9f27e933ae97a6bd90b27728abc0e0f238352835
Author: Xiangpeng Hao <[email protected]>
AuthorDate: Thu Jan 22 11:01:55 2026 -0500
Coerce expressions to udtf (#19915)
## Which issue does this PR close?
Closes #19914
The changes are fairly simple. The bug only occurs to udtf, so I added a
test case for this.
---
datafusion/core/src/execution/session_state.rs | 7 +++++-
.../user_defined/user_defined_table_functions.rs | 25 ++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/datafusion/core/src/execution/session_state.rs
b/datafusion/core/src/execution/session_state.rs
index 7cdbc77ae9..0de2ace4f2 100644
--- a/datafusion/core/src/execution/session_state.rs
+++ b/datafusion/core/src/execution/session_state.rs
@@ -1843,9 +1843,14 @@ impl ContextProvider for SessionContextProvider<'_> {
self.state.execution_props().query_execution_start_time,
);
let simplifier = ExprSimplifier::new(simplify_context);
+ let schema = DFSchema::empty();
let args = args
.into_iter()
- .map(|arg| simplifier.simplify(arg))
+ .map(|arg| {
+ simplifier
+ .coerce(arg, &schema)
+ .and_then(|e| simplifier.simplify(e))
+ })
.collect::<datafusion_common::Result<Vec<_>>>()?;
let provider = tbl_func.create_table_provider(&args)?;
diff --git a/datafusion/core/tests/user_defined/user_defined_table_functions.rs
b/datafusion/core/tests/user_defined/user_defined_table_functions.rs
index 8be8609c62..95694d00a6 100644
--- a/datafusion/core/tests/user_defined/user_defined_table_functions.rs
+++ b/datafusion/core/tests/user_defined/user_defined_table_functions.rs
@@ -221,6 +221,31 @@ impl TableFunctionImpl for SimpleCsvTableFunc {
}
}
+/// Test that expressions passed to UDTFs are properly type-coerced
+/// This is a regression test for
https://github.com/apache/datafusion/issues/19914
+#[tokio::test]
+async fn test_udtf_type_coercion() -> Result<()> {
+ use datafusion::datasource::MemTable;
+
+ #[derive(Debug)]
+ struct NoOpTableFunc;
+
+ impl TableFunctionImpl for NoOpTableFunc {
+ fn call(&self, _: &[Expr]) -> Result<Arc<dyn TableProvider>> {
+ let schema = Arc::new(arrow::datatypes::Schema::empty());
+ Ok(Arc::new(MemTable::try_new(schema, vec![vec![]])?))
+ }
+ }
+
+ let ctx = SessionContext::new();
+ ctx.register_udtf("f", Arc::new(NoOpTableFunc));
+
+ // This should not panic - the array elements should be coerced to Float64
+ let _ = ctx.sql("SELECT * FROM f(ARRAY[0.1, 1, 2])").await?;
+
+ Ok(())
+}
+
fn read_csv_batches(csv_path: impl AsRef<Path>) -> Result<(SchemaRef,
Vec<RecordBatch>)> {
let mut file = File::open(csv_path)?;
let (schema, _) = Format::default()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]