Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions datafusion/sql/src/relation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
let args = func_args
.args
.into_iter()
.flat_map(|arg| {
.map(|arg| {
if let FunctionArg::Unnamed(FunctionArgExpr::Expr(expr)) = arg
{
self.sql_expr_to_logical_expr(
Expand All @@ -163,7 +163,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
plan_err!("Unsupported function argument type: {}", arg)
}
})
.collect::<Vec<_>>();
.collect::<Result<Vec<_>>>()?;
let provider = self
.context_provider
.get_table_function_source(&tbl_func_name, args)?;
Expand Down
20 changes: 20 additions & 0 deletions datafusion/sql/tests/sql_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4588,6 +4588,26 @@ fn plan_create_index() {
}
}

#[test]
fn test_table_function_with_unsupported_arg_propagates_error() {
let sql = "SELECT * FROM my_func(('a', 'b', 'c'))";
let dialect = &GenericDialect {};
let state = MockSessionState::default();
let context = MockContextProvider { state };
let planner = SqlToRel::new(&context);
let result = DFParser::parse_sql_with_dialect(sql, dialect);
let mut ast = result.unwrap();
let err = planner
.statement_to_plan(ast.pop_front().unwrap())
.expect_err("query should have failed");
let msg = err.strip_backtrace();
assert!(
!msg.contains("Table Functions are not supported"),
"tuple argument error should be propagated before reaching get_table_function_source, got: {msg}"
);
assert_contains!(msg, "Struct not supported");
}

fn assert_field_not_found(mut err: DataFusionError, name: &str) {
let err = loop {
match err {
Expand Down
15 changes: 14 additions & 1 deletion datafusion/sqllogictest/test_files/table_functions.slt
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ SELECT * FROM range(TIMESTAMP '2023-01-03T00:00:00', TIMESTAMP '2023-01-01T00:00

# Single timestamp (start == end)
query P
SELECT * FROM range(TIMESTAMP '2023-01-01T00:00:00', TIMESTAMP '2023-01-01T00:00:00', INTERVAL '1' DAY)
SELECT * FROM range(TIMESTAMP '2023-01-01T00:00:00', TIMESTAMP '2023-01-01T00:00:00', INTERVAL '1' DAY)
----

# Timestamp range with NULL values
Expand Down Expand Up @@ -543,3 +543,16 @@ LIMIT 10;
1
1
1

# Test that unsupported function argument types are properly reported
# rather than being silently dropped (which previously caused a misleading
# "requires 1 to 3 arguments" error instead)

statement error DataFusion error: Error during planning: Unsupported function argument type: start => 1
SELECT * FROM generate_series(start => 1, stop => 5)

statement error DataFusion error: Error during planning: Unsupported function argument type: \*
SELECT * FROM generate_series(*)

statement error DataFusion error: Error during planning: Unsupported function argument type: t\.\*
SELECT * FROM generate_series(t.*)
Loading