@@ -266,6 +266,8 @@ pub enum LogicalPlan {
266266 /// Prepare a statement and find any bind parameters
267267 /// (e.g. `?`). This is used to implement SQL-prepared statements.
268268 Prepare ( Prepare ) ,
269+ /// Execute a prepared statement. This is used to implement SQL 'EXECUTE'.
270+ Execute ( Execute ) ,
269271 /// Data Manipulation Language (DML): Insert / Update / Delete
270272 Dml ( DmlStatement ) ,
271273 /// Data Definition Language (DDL): CREATE / DROP TABLES / VIEWS / SCHEMAS
@@ -314,6 +316,7 @@ impl LogicalPlan {
314316 LogicalPlan :: Subquery ( Subquery { subquery, .. } ) => subquery. schema ( ) ,
315317 LogicalPlan :: SubqueryAlias ( SubqueryAlias { schema, .. } ) => schema,
316318 LogicalPlan :: Prepare ( Prepare { input, .. } ) => input. schema ( ) ,
319+ LogicalPlan :: Execute ( Execute { schema, .. } ) => schema,
317320 LogicalPlan :: Explain ( explain) => & explain. schema ,
318321 LogicalPlan :: Analyze ( analyze) => & analyze. schema ,
319322 LogicalPlan :: Extension ( extension) => extension. node . schema ( ) ,
@@ -457,6 +460,7 @@ impl LogicalPlan {
457460 | LogicalPlan :: Statement { .. }
458461 | LogicalPlan :: EmptyRelation { .. }
459462 | LogicalPlan :: Values { .. }
463+ | LogicalPlan :: Execute { .. }
460464 | LogicalPlan :: DescribeTable ( _) => vec ! [ ] ,
461465 }
462466 }
@@ -560,6 +564,7 @@ impl LogicalPlan {
560564 LogicalPlan :: Subquery ( _) => Ok ( None ) ,
561565 LogicalPlan :: EmptyRelation ( _)
562566 | LogicalPlan :: Prepare ( _)
567+ | LogicalPlan :: Execute ( _)
563568 | LogicalPlan :: Statement ( _)
564569 | LogicalPlan :: Values ( _)
565570 | LogicalPlan :: Explain ( _)
@@ -712,6 +717,7 @@ impl LogicalPlan {
712717 LogicalPlan :: Analyze ( _) => Ok ( self ) ,
713718 LogicalPlan :: Explain ( _) => Ok ( self ) ,
714719 LogicalPlan :: Prepare ( _) => Ok ( self ) ,
720+ LogicalPlan :: Execute ( _) => Ok ( self ) ,
715721 LogicalPlan :: TableScan ( _) => Ok ( self ) ,
716722 LogicalPlan :: EmptyRelation ( _) => Ok ( self ) ,
717723 LogicalPlan :: Statement ( _) => Ok ( self ) ,
@@ -1072,6 +1078,14 @@ impl LogicalPlan {
10721078 input : Arc :: new ( input) ,
10731079 } ) )
10741080 }
1081+ LogicalPlan :: Execute ( Execute { name, schema, .. } ) => {
1082+ self . assert_no_inputs ( inputs) ?;
1083+ Ok ( LogicalPlan :: Execute ( Execute {
1084+ name : name. clone ( ) ,
1085+ schema : Arc :: clone ( schema) ,
1086+ parameters : expr,
1087+ } ) )
1088+ }
10751089 LogicalPlan :: TableScan ( ts) => {
10761090 self . assert_no_inputs ( inputs) ?;
10771091 Ok ( LogicalPlan :: TableScan ( TableScan {
@@ -1330,6 +1344,7 @@ impl LogicalPlan {
13301344 | LogicalPlan :: Copy ( _)
13311345 | LogicalPlan :: DescribeTable ( _)
13321346 | LogicalPlan :: Prepare ( _)
1347+ | LogicalPlan :: Execute ( _)
13331348 | LogicalPlan :: Statement ( _)
13341349 | LogicalPlan :: Extension ( _) => None ,
13351350 }
@@ -1933,6 +1948,9 @@ impl LogicalPlan {
19331948 } ) => {
19341949 write ! ( f, "Prepare: {name:?} {data_types:?} " )
19351950 }
1951+ LogicalPlan :: Execute ( Execute { name, parameters, .. } ) => {
1952+ write ! ( f, "Execute: {} params=[{}]" , name, expr_vec_fmt!( parameters) )
1953+ }
19361954 LogicalPlan :: DescribeTable ( DescribeTable { .. } ) => {
19371955 write ! ( f, "DescribeTable" )
19381956 }
@@ -2599,6 +2617,27 @@ pub struct Prepare {
25992617 pub input : Arc < LogicalPlan > ,
26002618}
26012619
2620+ /// Execute a prepared statement.
2621+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
2622+ pub struct Execute {
2623+ /// The name of the prepared statement to execute
2624+ pub name : String ,
2625+ /// The execute parameters
2626+ pub parameters : Vec < Expr > ,
2627+ /// Dummy schema
2628+ pub schema : DFSchemaRef ,
2629+ }
2630+
2631+ // Comparison excludes the `schema` field.
2632+ impl PartialOrd for Execute {
2633+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
2634+ match self . name . partial_cmp ( & other. name ) {
2635+ Some ( Ordering :: Equal ) => self . parameters . partial_cmp ( & other. parameters ) ,
2636+ cmp => cmp,
2637+ }
2638+ }
2639+ }
2640+
26022641/// Describe the schema of table
26032642///
26042643/// # Example output:
0 commit comments