Skip to content

Commit b09205a

Browse files
authored
fix: propagate errors for unsupported table function arguments instead of silently dropping them (#21135)
## Which issue does this PR close? - Closes #21125. ## Rationale for this change `flat_map` swallows error since it results into an iterator that yields no elements. Instead of this this PR uses `map` and propagates error. ## What changes are included in this PR? error propagation and related tests ## Are these changes tested? Yes I've added both unit and slt test ## Are there any user-facing changes? User's will see propagated error
1 parent a910b03 commit b09205a

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

datafusion/sql/src/relation/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
151151
let args = func_args
152152
.args
153153
.into_iter()
154-
.flat_map(|arg| {
154+
.map(|arg| {
155155
if let FunctionArg::Unnamed(FunctionArgExpr::Expr(expr)) = arg
156156
{
157157
self.sql_expr_to_logical_expr(
@@ -163,7 +163,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
163163
plan_err!("Unsupported function argument type: {}", arg)
164164
}
165165
})
166-
.collect::<Vec<_>>();
166+
.collect::<Result<Vec<_>>>()?;
167167
let provider = self
168168
.context_provider
169169
.get_table_function_source(&tbl_func_name, args)?;

datafusion/sql/tests/sql_integration.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4725,6 +4725,26 @@ fn plan_create_index() {
47254725
}
47264726
}
47274727

4728+
#[test]
4729+
fn test_table_function_with_unsupported_arg_propagates_error() {
4730+
let sql = "SELECT * FROM my_func(('a', 'b', 'c'))";
4731+
let dialect = &GenericDialect {};
4732+
let state = MockSessionState::default();
4733+
let context = MockContextProvider { state };
4734+
let planner = SqlToRel::new(&context);
4735+
let result = DFParser::parse_sql_with_dialect(sql, dialect);
4736+
let mut ast = result.unwrap();
4737+
let err = planner
4738+
.statement_to_plan(ast.pop_front().unwrap())
4739+
.expect_err("query should have failed");
4740+
let msg = err.strip_backtrace();
4741+
assert!(
4742+
!msg.contains("Table Functions are not supported"),
4743+
"tuple argument error should be propagated before reaching get_table_function_source, got: {msg}"
4744+
);
4745+
assert_contains!(msg, "Struct not supported");
4746+
}
4747+
47284748
fn assert_field_not_found(mut err: DataFusionError, name: &str) {
47294749
let err = loop {
47304750
match err {

datafusion/sqllogictest/test_files/table_functions.slt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ SELECT * FROM range(TIMESTAMP '2023-01-03T00:00:00', TIMESTAMP '2023-01-01T00:00
397397

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

403403
# Timestamp range with NULL values
@@ -543,3 +543,16 @@ LIMIT 10;
543543
1
544544
1
545545
1
546+
547+
# Test that unsupported function argument types are properly reported
548+
# rather than being silently dropped (which previously caused a misleading
549+
# "requires 1 to 3 arguments" error instead)
550+
551+
statement error DataFusion error: Error during planning: Unsupported function argument type: start => 1
552+
SELECT * FROM generate_series(start => 1, stop => 5)
553+
554+
statement error DataFusion error: Error during planning: Unsupported function argument type: \*
555+
SELECT * FROM generate_series(*)
556+
557+
statement error DataFusion error: Error during planning: Unsupported function argument type: t\.\*
558+
SELECT * FROM generate_series(t.*)

0 commit comments

Comments
 (0)