-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
omit some clone when converting sql to logical plan #1945
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @doki23
location: location.clone(), | ||
file_type: *file_type, | ||
has_header: *has_header, | ||
name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍,clone
disappeared
datafusion/src/execution/context.rs
Outdated
@@ -311,7 +311,7 @@ impl ExecutionContext { | |||
// create a query planner | |||
let state = self.state.lock().clone(); | |||
let query_planner = SqlToRel::new(&state); | |||
query_planner.statement_to_plan(&statements[0]) | |||
query_planner.statement_to_plan(statements.remove(0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wonder what's the motivation behind .remove
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is to take ownership of the 1 item from statements
. statements.len() == 1
is verified on line 305 above
I think statements.pop().unwrap()
is equivalent and might be clearer what is going on, though I think remove(0)
is also fine
if we are using so many |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can approve to unblock merging but i do think the remove(0)
makes the logic quite cryptic. might need a follow up PR to clean up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it looks great -- thank you @doki23
After this PR there is definitely some more cleanup possible such as
fn sql_expr_to_logical_expr(&self, sql: &SQLExpr, schema: &DFSchema) -> Result<Expr> {
But I can file a follow on ticket for that.
datafusion/src/execution/context.rs
Outdated
@@ -311,7 +311,7 @@ impl ExecutionContext { | |||
// create a query planner | |||
let state = self.state.lock().clone(); | |||
let query_planner = SqlToRel::new(&state); | |||
query_planner.statement_to_plan(&statements[0]) | |||
query_planner.statement_to_plan(statements.remove(0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is to take ownership of the 1 item from statements
. statements.len() == 1
is verified on line 305 above
I think statements.pop().unwrap()
is equivalent and might be clearer what is going on, though I think remove(0)
is also fine
datafusion/src/sql/planner.rs
Outdated
let rewrite = DFParser::parse_sql(&query)?; | ||
self.statement_to_plan(&rewrite[0]) | ||
let mut rewrite = DFParser::parse_sql(&query)?; | ||
self.statement_to_plan(rewrite.remove(0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this was not added in this PR, but I wonder if we could add an assert_eq!(rewrite.len(), 1)
here to make sure we don't accidentally lose one of these statements later on
+1 |
I accidentally closed this pr, hope it didn't cause confusion😂 |
@@ -311,7 +311,7 @@ impl ExecutionContext { | |||
// create a query planner | |||
let state = self.state.lock().clone(); | |||
let query_planner = SqlToRel::new(&state); | |||
query_planner.statement_to_plan(&statements[0]) | |||
query_planner.statement_to_plan(statements.pop().unwrap()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about combining the length check and pop logic into a single block to make it more readable? basically something like below:
let stmt = statements.pop().ok_or(Err(DataFusionError::NotImplemented(
"The context currently only supports a single SQL statement".to_string()
)))?;
// create a query planner
let state = self.state.lock().clone();
let query_planner = SqlToRel::new(&state);
query_planner.statement_to_plan(stmt)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, the error description means length of statements should eq 1, but 'statements.pop().ok_or(...)' only indicates that it's >= 1. And I have not found api having same semantics.
Co-authored-by: xudong.w <wxd963996380@gmail.com>
@doki23 and @xudong963 I merged this PR with master to resolve (another) conflict in a0f7091 -- I hope you don't mind. I don't want it to be hanging out too long and picking up conflits along the way |
Thanks again @doki23 |
Which issue does this PR close?
Closes #1469.
What changes are included in this PR?
It's an api change.
Take ownership of sql-parser components to emit some clones.
It's hard to me - a new comer of rust and df, and the mutual calls between functions are very complex, so please bear with me :)