-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: support prepare statement #4490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
f7408fc
ff0dc10
5a50288
e5ec877
678a30b
e04da97
860f85d
ba8ad0f
67cbfdd
001251c
5d78097
1344395
87787da
199b657
cdb328c
58a3117
30705d9
87a3523
91e104a
dd6c3e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,6 +108,8 @@ pub enum LogicalPlan { | |
| Distinct(Distinct), | ||
| /// Set a Variable | ||
| SetVariable(SetVariable), | ||
| /// Prepare a statement | ||
| Prepare(Prepare), | ||
|
alamb marked this conversation as resolved.
|
||
| } | ||
|
|
||
| impl LogicalPlan { | ||
|
|
@@ -134,6 +136,7 @@ impl LogicalPlan { | |
| LogicalPlan::CreateExternalTable(CreateExternalTable { schema, .. }) => { | ||
| schema | ||
| } | ||
| LogicalPlan::Prepare(Prepare { input, .. }) => input.schema(), | ||
| LogicalPlan::Explain(explain) => &explain.schema, | ||
| LogicalPlan::Analyze(analyze) => &analyze.schema, | ||
| LogicalPlan::Extension(extension) => extension.node.schema(), | ||
|
|
@@ -201,8 +204,9 @@ impl LogicalPlan { | |
| | LogicalPlan::Sort(Sort { input, .. }) | ||
| | LogicalPlan::CreateMemoryTable(CreateMemoryTable { input, .. }) | ||
| | LogicalPlan::CreateView(CreateView { input, .. }) | ||
| | LogicalPlan::Filter(Filter { input, .. }) => input.all_schemas(), | ||
| LogicalPlan::Distinct(Distinct { input, .. }) => input.all_schemas(), | ||
| | LogicalPlan::Filter(Filter { input, .. }) | ||
| | LogicalPlan::Distinct(Distinct { input, .. }) | ||
| | LogicalPlan::Prepare(Prepare { input, .. }) => input.all_schemas(), | ||
| LogicalPlan::DropTable(_) | ||
| | LogicalPlan::DropView(_) | ||
| | LogicalPlan::SetVariable(_) => vec![], | ||
|
|
@@ -271,7 +275,8 @@ impl LogicalPlan { | |
| | LogicalPlan::Analyze(_) | ||
| | LogicalPlan::Explain(_) | ||
| | LogicalPlan::Union(_) | ||
| | LogicalPlan::Distinct(_) => { | ||
| | LogicalPlan::Distinct(_) | ||
| | LogicalPlan::Prepare(_) => { | ||
| vec![] | ||
| } | ||
| } | ||
|
|
@@ -300,7 +305,8 @@ impl LogicalPlan { | |
| LogicalPlan::Explain(explain) => vec![&explain.plan], | ||
| LogicalPlan::Analyze(analyze) => vec![&analyze.input], | ||
| LogicalPlan::CreateMemoryTable(CreateMemoryTable { input, .. }) | ||
| | LogicalPlan::CreateView(CreateView { input, .. }) => { | ||
| | LogicalPlan::CreateView(CreateView { input, .. }) | ||
| | LogicalPlan::Prepare(Prepare { input, .. }) => { | ||
| vec![input] | ||
| } | ||
| // plans without inputs | ||
|
|
@@ -448,9 +454,8 @@ impl LogicalPlan { | |
| input.accept(visitor)? | ||
| } | ||
| LogicalPlan::CreateMemoryTable(CreateMemoryTable { input, .. }) | ||
| | LogicalPlan::CreateView(CreateView { input, .. }) => { | ||
| input.accept(visitor)? | ||
| } | ||
| | LogicalPlan::CreateView(CreateView { input, .. }) | ||
| | LogicalPlan::Prepare(Prepare { input, .. }) => input.accept(visitor)?, | ||
| LogicalPlan::Extension(extension) => { | ||
| for input in extension.node.inputs() { | ||
| if !input.accept(visitor)? { | ||
|
|
@@ -961,6 +966,11 @@ impl LogicalPlan { | |
| LogicalPlan::Analyze { .. } => write!(f, "Analyze"), | ||
| LogicalPlan::Union(_) => write!(f, "Union"), | ||
| LogicalPlan::Extension(e) => e.node.fmt_for_explain(f), | ||
| LogicalPlan::Prepare(Prepare { | ||
| name, data_types, .. | ||
| }) => { | ||
| write!(f, "Prepare: {:?} {:?} ", name, data_types) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1358,6 +1368,17 @@ pub struct CreateExternalTable { | |
| pub options: HashMap<String, String>, | ||
| } | ||
|
|
||
| /// Prepare a statement | ||
|
NGA-TRAN marked this conversation as resolved.
Outdated
|
||
| #[derive(Clone)] | ||
| pub struct Prepare { | ||
| /// The name of the statement | ||
| pub name: String, | ||
| /// Data types of the parameters | ||
|
NGA-TRAN marked this conversation as resolved.
Outdated
|
||
| pub data_types: Vec<DataType>, | ||
| /// The logical plan of the statements | ||
| pub input: Arc<LogicalPlan>, | ||
| } | ||
|
|
||
|
Comment on lines
+1393
to
+1397
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the data types Vec size is the same with the place holders in the input plan, but is there any check for this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The data types of the placeholders are from the data types of the Vec here so they match. We do check if the Vec contains enough params, too. However, there are flexibility:
However, I am working on #4550 that convert Prepare Logical Plan to a logical plan with all placeholders replaced with actual values. There, I will throw error if the data types provided do not work. We follow the same behavior of Postgres |
||
| /// Produces a relation with string representations of | ||
| /// various parts of the plan | ||
| #[derive(Clone)] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,8 @@ use crate::expr_visitor::{ExprVisitable, ExpressionVisitor, Recursion}; | |
| use crate::logical_plan::builder::build_join_schema; | ||
| use crate::logical_plan::{ | ||
| Aggregate, Analyze, CreateMemoryTable, CreateView, Distinct, Extension, Filter, Join, | ||
| Limit, Partitioning, Projection, Repartition, Sort, Subquery, SubqueryAlias, Union, | ||
| Values, Window, | ||
| Limit, Partitioning, Prepare, Projection, Repartition, Sort, Subquery, SubqueryAlias, | ||
| Union, Values, Window, | ||
| }; | ||
| use crate::{Cast, Expr, ExprSchemable, LogicalPlan, LogicalPlanBuilder}; | ||
| use arrow::datatypes::{DataType, TimeUnit}; | ||
|
|
@@ -126,7 +126,8 @@ impl ExpressionVisitor for ColumnNameVisitor<'_> { | |
| | Expr::ScalarSubquery(_) | ||
| | Expr::Wildcard | ||
| | Expr::QualifiedWildcard { .. } | ||
| | Expr::GetIndexedField { .. } => {} | ||
| | Expr::GetIndexedField { .. } | ||
| | Expr::Placeholder(_) => {} | ||
| } | ||
| Ok(Recursion::Continue(self)) | ||
| } | ||
|
|
@@ -575,6 +576,13 @@ pub fn from_plan( | |
| ); | ||
| Ok(plan.clone()) | ||
| } | ||
| LogicalPlan::Prepare(Prepare { | ||
| name, data_types, .. | ||
| }) => Ok(LogicalPlan::Prepare(Prepare { | ||
| name: name.clone(), | ||
| data_types: data_types.clone(), | ||
| input: Arc::new(inputs[0].clone()), | ||
| })), | ||
|
Comment on lines
+586
to
+589
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible and allowed here that the method passed in a totally different input plan ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the code we implement, the answer is no unless there are bugs |
||
| LogicalPlan::EmptyRelation(_) | ||
| | LogicalPlan::TableScan { .. } | ||
| | LogicalPlan::CreateExternalTable(_) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.