You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/05/16 14:41:51 UTC

(datafusion) branch main updated: fix: Handle EXECUTE without statement name (#22204)

This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[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 3a49a2fec6 fix: Handle EXECUTE without statement name (#22204)
3a49a2fec6 is described below

commit 3a49a2fec6abe41dd689f4e7c49721ce4119f51b
Author: Daniƫl Heres <da...@gmail.com>
AuthorDate: Sat May 16 16:22:56 2026 +0200

    fix: Handle EXECUTE without statement name (#22204)
    
    ## Which issue does this PR close?
    
    - Closes #22197.
    
    ## Rationale for this change
    
    `EXEC()` and `EXECUTE()` can parse as `Statement::Execute` without a
    statement name. The planner previously unwrapped that optional name and
    panicked on user-supplied SQL.
    
    ## What changes are included in this PR?
    
    - Return a planning error when `EXECUTE` has no statement name.
    - Add sqllogictest coverage for the malformed `EXEC` / `EXECUTE` forms
    from the issue.
    
    ## Are these changes tested?
    
    - `cargo test -p datafusion-sqllogictest --test sqllogictests --
    prepare`
    - `cargo fmt --all`
    - `cargo clippy --all-targets --all-features -- -D warnings`
    
    ## Are there any user-facing changes?
    
    Malformed `EXEC` / `EXECUTE` statements without a name now return a
    planning error instead of panicking.
---
 datafusion/sql/src/statement.rs                |  6 +++++-
 datafusion/sqllogictest/test_files/prepare.slt | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/datafusion/sql/src/statement.rs b/datafusion/sql/src/statement.rs
index e7088c8a3d..8c94610f77 100644
--- a/datafusion/sql/src/statement.rs
+++ b/datafusion/sql/src/statement.rs
@@ -886,6 +886,10 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
                         "Execute statement with DEFAULT is not supported"
                     );
                 }
+                let name = name.ok_or_else(|| {
+                    plan_datafusion_err!("EXECUTE statement requires a name")
+                })?;
+
                 let empty_schema = DFSchema::empty();
                 let parameters = parameters
                     .into_iter()
@@ -893,7 +897,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
                     .collect::<Result<Vec<Expr>>>()?;
 
                 Ok(LogicalPlan::Statement(PlanStatement::Execute(Execute {
-                    name: object_name_to_string(&name.unwrap()),
+                    name: object_name_to_string(&name),
                     parameters,
                 })))
             }
diff --git a/datafusion/sqllogictest/test_files/prepare.slt b/datafusion/sqllogictest/test_files/prepare.slt
index 8e8b1cd8e6..16e41834a3 100644
--- a/datafusion/sqllogictest/test_files/prepare.slt
+++ b/datafusion/sqllogictest/test_files/prepare.slt
@@ -53,6 +53,25 @@ PREPARE my_plan(INT, INT) AS SELECT 1 + $1;
 statement error SQL error: ParserError
 PREPARE my_plan(INT) AS SELECT id, age  FROM person WHERE age is $1;
 
+# EXEC/EXECUTE with parentheses but no statement name must error instead of panic
+statement error EXECUTE statement requires a name
+EXEC();
+
+statement error EXECUTE statement requires a name
+EXEC('');
+
+statement error EXECUTE statement requires a name
+EXEC('any-string');
+
+statement error EXECUTE statement requires a name
+EXEC(unknown_column);
+
+statement error EXECUTE statement requires a name
+EXECUTE();
+
+statement error EXECUTE statement requires a name
+EXEC ('a');
+
 # #######################
 # Test prepare and execute statements
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org