@@ -39,9 +39,9 @@ use crate::utils::{
3939 split_conjunction,
4040} ;
4141use crate :: {
42- build_join_schema, expr_vec_fmt, BinaryExpr , CreateMemoryTable , CreateView , Expr ,
43- ExprSchemable , LogicalPlanBuilder , Operator , TableProviderFilterPushDown ,
44- TableSource , WindowFunctionDefinition ,
42+ build_join_schema, expr_vec_fmt, BinaryExpr , CreateMemoryTable , CreateView , Execute ,
43+ Expr , ExprSchemable , LogicalPlanBuilder , Operator , Prepare ,
44+ TableProviderFilterPushDown , TableSource , WindowFunctionDefinition ,
4545} ;
4646
4747use arrow:: datatypes:: { DataType , Field , Schema , SchemaRef } ;
@@ -262,11 +262,6 @@ pub enum LogicalPlan {
262262 /// Remove duplicate rows from the input. This is used to
263263 /// implement SQL `SELECT DISTINCT ...`.
264264 Distinct ( Distinct ) ,
265- /// Prepare a statement and find any bind parameters
266- /// (e.g. `?`). This is used to implement SQL-prepared statements.
267- Prepare ( Prepare ) ,
268- /// Execute a prepared statement. This is used to implement SQL 'EXECUTE'.
269- Execute ( Execute ) ,
270265 /// Data Manipulation Language (DML): Insert / Update / Delete
271266 Dml ( DmlStatement ) ,
272267 /// Data Definition Language (DDL): CREATE / DROP TABLES / VIEWS / SCHEMAS
@@ -314,8 +309,6 @@ impl LogicalPlan {
314309 LogicalPlan :: Statement ( statement) => statement. schema ( ) ,
315310 LogicalPlan :: Subquery ( Subquery { subquery, .. } ) => subquery. schema ( ) ,
316311 LogicalPlan :: SubqueryAlias ( SubqueryAlias { schema, .. } ) => schema,
317- LogicalPlan :: Prepare ( Prepare { input, .. } ) => input. schema ( ) ,
318- LogicalPlan :: Execute ( Execute { schema, .. } ) => schema,
319312 LogicalPlan :: Explain ( explain) => & explain. schema ,
320313 LogicalPlan :: Analyze ( analyze) => & analyze. schema ,
321314 LogicalPlan :: Extension ( extension) => extension. node . schema ( ) ,
@@ -448,18 +441,16 @@ impl LogicalPlan {
448441 LogicalPlan :: Copy ( copy) => vec ! [ & copy. input] ,
449442 LogicalPlan :: Ddl ( ddl) => ddl. inputs ( ) ,
450443 LogicalPlan :: Unnest ( Unnest { input, .. } ) => vec ! [ input] ,
451- LogicalPlan :: Prepare ( Prepare { input, .. } ) => vec ! [ input] ,
452444 LogicalPlan :: RecursiveQuery ( RecursiveQuery {
453445 static_term,
454446 recursive_term,
455447 ..
456448 } ) => vec ! [ static_term, recursive_term] ,
449+ LogicalPlan :: Statement ( stmt) => stmt. inputs ( ) ,
457450 // plans without inputs
458451 LogicalPlan :: TableScan { .. }
459- | LogicalPlan :: Statement { .. }
460452 | LogicalPlan :: EmptyRelation { .. }
461453 | LogicalPlan :: Values { .. }
462- | LogicalPlan :: Execute { .. }
463454 | LogicalPlan :: DescribeTable ( _) => vec ! [ ] ,
464455 }
465456 }
@@ -562,8 +553,6 @@ impl LogicalPlan {
562553 }
563554 LogicalPlan :: Subquery ( _) => Ok ( None ) ,
564555 LogicalPlan :: EmptyRelation ( _)
565- | LogicalPlan :: Prepare ( _)
566- | LogicalPlan :: Execute ( _)
567556 | LogicalPlan :: Statement ( _)
568557 | LogicalPlan :: Values ( _)
569558 | LogicalPlan :: Explain ( _)
@@ -715,8 +704,6 @@ impl LogicalPlan {
715704 LogicalPlan :: RecursiveQuery ( _) => Ok ( self ) ,
716705 LogicalPlan :: Analyze ( _) => Ok ( self ) ,
717706 LogicalPlan :: Explain ( _) => Ok ( self ) ,
718- LogicalPlan :: Prepare ( _) => Ok ( self ) ,
719- LogicalPlan :: Execute ( _) => Ok ( self ) ,
720707 LogicalPlan :: TableScan ( _) => Ok ( self ) ,
721708 LogicalPlan :: EmptyRelation ( _) => Ok ( self ) ,
722709 LogicalPlan :: Statement ( _) => Ok ( self ) ,
@@ -1070,24 +1057,25 @@ impl LogicalPlan {
10701057 logical_optimization_succeeded : e. logical_optimization_succeeded ,
10711058 } ) )
10721059 }
1073- LogicalPlan :: Prepare ( Prepare {
1074- name, data_types, ..
1075- } ) => {
1060+ LogicalPlan :: Statement ( Statement :: Prepare ( Prepare {
1061+ name,
1062+ data_types,
1063+ ..
1064+ } ) ) => {
10761065 self . assert_no_expressions ( expr) ?;
10771066 let input = self . only_input ( inputs) ?;
1078- Ok ( LogicalPlan :: Prepare ( Prepare {
1067+ Ok ( LogicalPlan :: Statement ( Statement :: Prepare ( Prepare {
10791068 name : name. clone ( ) ,
10801069 data_types : data_types. clone ( ) ,
10811070 input : Arc :: new ( input) ,
1082- } ) )
1071+ } ) ) )
10831072 }
1084- LogicalPlan :: Execute ( Execute { name, schema , .. } ) => {
1073+ LogicalPlan :: Statement ( Statement :: Execute ( Execute { name, .. } ) ) => {
10851074 self . assert_no_inputs ( inputs) ?;
1086- Ok ( LogicalPlan :: Execute ( Execute {
1075+ Ok ( LogicalPlan :: Statement ( Statement :: Execute ( Execute {
10871076 name : name. clone ( ) ,
1088- schema : Arc :: clone ( schema) ,
10891077 parameters : expr,
1090- } ) )
1078+ } ) ) )
10911079 }
10921080 LogicalPlan :: TableScan ( ts) => {
10931081 self . assert_no_inputs ( inputs) ?;
@@ -1184,8 +1172,8 @@ impl LogicalPlan {
11841172 /// Replaces placeholder param values (like `$1`, `$2`) in [`LogicalPlan`]
11851173 /// with the specified `param_values`.
11861174 ///
1187- /// [`LogicalPlan:: Prepare`] are
1188- /// converted to their inner logical plan for execution.
1175+ /// [`Prepare`] statements are converted to
1176+ /// their inner logical plan for execution.
11891177 ///
11901178 /// # Example
11911179 /// ```
@@ -1242,13 +1230,17 @@ impl LogicalPlan {
12421230 let plan_with_values = self . replace_params_with_values ( & param_values) ?;
12431231
12441232 // unwrap Prepare
1245- Ok ( if let LogicalPlan :: Prepare ( prepare_lp) = plan_with_values {
1246- param_values. verify ( & prepare_lp. data_types ) ?;
1247- // try and take ownership of the input if is not shared, clone otherwise
1248- Arc :: unwrap_or_clone ( prepare_lp. input )
1249- } else {
1250- plan_with_values
1251- } )
1233+ Ok (
1234+ if let LogicalPlan :: Statement ( Statement :: Prepare ( prepare_lp) ) =
1235+ plan_with_values
1236+ {
1237+ param_values. verify ( & prepare_lp. data_types ) ?;
1238+ // try and take ownership of the input if is not shared, clone otherwise
1239+ Arc :: unwrap_or_clone ( prepare_lp. input )
1240+ } else {
1241+ plan_with_values
1242+ } ,
1243+ )
12521244 }
12531245
12541246 /// Returns the maximum number of rows that this plan can output, if known.
@@ -1346,8 +1338,6 @@ impl LogicalPlan {
13461338 | LogicalPlan :: Dml ( _)
13471339 | LogicalPlan :: Copy ( _)
13481340 | LogicalPlan :: DescribeTable ( _)
1349- | LogicalPlan :: Prepare ( _)
1350- | LogicalPlan :: Execute ( _)
13511341 | LogicalPlan :: Statement ( _)
13521342 | LogicalPlan :: Extension ( _) => None ,
13531343 }
@@ -1962,14 +1952,6 @@ impl LogicalPlan {
19621952 LogicalPlan :: Analyze { .. } => write ! ( f, "Analyze" ) ,
19631953 LogicalPlan :: Union ( _) => write ! ( f, "Union" ) ,
19641954 LogicalPlan :: Extension ( e) => e. node . fmt_for_explain ( f) ,
1965- LogicalPlan :: Prepare ( Prepare {
1966- name, data_types, ..
1967- } ) => {
1968- write ! ( f, "Prepare: {name:?} {data_types:?} " )
1969- }
1970- LogicalPlan :: Execute ( Execute { name, parameters, .. } ) => {
1971- write ! ( f, "Execute: {} params=[{}]" , name, expr_vec_fmt!( parameters) )
1972- }
19731955 LogicalPlan :: DescribeTable ( DescribeTable { .. } ) => {
19741956 write ! ( f, "DescribeTable" )
19751957 }
@@ -2624,39 +2606,6 @@ impl PartialOrd for Union {
26242606 }
26252607}
26262608
2627- /// Prepare a statement but do not execute it. Prepare statements can have 0 or more
2628- /// `Expr::Placeholder` expressions that are filled in during execution
2629- #[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Hash ) ]
2630- pub struct Prepare {
2631- /// The name of the statement
2632- pub name : String ,
2633- /// Data types of the parameters ([`Expr::Placeholder`])
2634- pub data_types : Vec < DataType > ,
2635- /// The logical plan of the statements
2636- pub input : Arc < LogicalPlan > ,
2637- }
2638-
2639- /// Execute a prepared statement.
2640- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
2641- pub struct Execute {
2642- /// The name of the prepared statement to execute
2643- pub name : String ,
2644- /// The execute parameters
2645- pub parameters : Vec < Expr > ,
2646- /// Dummy schema
2647- pub schema : DFSchemaRef ,
2648- }
2649-
2650- // Comparison excludes the `schema` field.
2651- impl PartialOrd for Execute {
2652- fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
2653- match self . name . partial_cmp ( & other. name ) {
2654- Some ( Ordering :: Equal ) => self . parameters . partial_cmp ( & other. parameters ) ,
2655- cmp => cmp,
2656- }
2657- }
2658- }
2659-
26602609/// Describe the schema of table
26612610///
26622611/// # Example output:
0 commit comments