-
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
Handle EmptyRelation during SQL unparsing #10803
Changes from all commits
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 |
---|---|---|
|
@@ -389,7 +389,10 @@ impl Unparser<'_> { | |
)?; | ||
|
||
let ast_join = ast::Join { | ||
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. This is totally fine, but I figured I would point out another way to express this logic that you might prefer in future PRs Instead of let ast_join = ast::Join {
relation: match right_relation.build()? {
Some(relation) => relation,
None => return internal_err!("Failed to build right relation"),
},
join_operator: self
.join_operator_to_sql(join.join_type, join_constraint),
}; You can do something like this with a let Some(relation) = match right_relation.build()? else {
return internal_err!("Failed to build right relation"),
};
let ast_join = ast::Join {
relation,
join_operator: self
.join_operator_to_sql(join.join_type, join_constraint),
}; |
||
relation: right_relation.build()?, | ||
relation: match right_relation.build()? { | ||
Some(relation) => relation, | ||
None => return internal_err!("Failed to build right relation"), | ||
}, | ||
join_operator: self | ||
.join_operator_to_sql(join.join_type, join_constraint), | ||
}; | ||
|
@@ -417,7 +420,10 @@ impl Unparser<'_> { | |
)?; | ||
|
||
let ast_join = ast::Join { | ||
relation: right_relation.build()?, | ||
relation: match right_relation.build()? { | ||
Some(relation) => relation, | ||
None => return internal_err!("Failed to build right relation"), | ||
}, | ||
join_operator: self.join_operator_to_sql( | ||
JoinType::Inner, | ||
ast::JoinConstraint::On(ast::Expr::Value(ast::Value::Boolean( | ||
|
@@ -483,6 +489,10 @@ impl Unparser<'_> { | |
relation, | ||
) | ||
} | ||
LogicalPlan::EmptyRelation(_) => { | ||
relation.empty(); | ||
Ok(()) | ||
} | ||
LogicalPlan::Extension(_) => not_impl_err!("Unsupported operator: {plan:?}"), | ||
_ => not_impl_err!("Unsupported operator: {plan:?}"), | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,11 @@ fn roundtrip_expr() { | |
#[test] | ||
fn roundtrip_statement() -> Result<()> { | ||
let tests: Vec<&str> = vec![ | ||
"select 1;", | ||
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. ❤️ |
||
"select 1 limit 0;", | ||
"select ta.j1_id from j1 ta join (select 1 as j1_id) tb on ta.j1_id = tb.j1_id;", | ||
"select ta.j1_id from j1 ta join (select 1 as j1_id) tb on ta.j1_id = tb.j1_id where ta.j1_id > 1;", | ||
"select ta.j1_id from (select 1 as j1_id) ta;", | ||
"select ta.j1_id from j1 ta;", | ||
"select ta.j1_id from j1 ta order by ta.j1_id;", | ||
"select * from j1 ta order by ta.j1_id, ta.j1_string desc;", | ||
|
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 you could also do this (which is more concise)
Though I see it follows the same pattern as the code above so if we are going to change any of the we should change them all