Skip to content
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

gh-516: support coexistence of SimpleExpr and QueryStatement #572

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

alphavector
Copy link

Took the liberty of implementing this feature to better understand the project

Closes: #516

Copy link
Member

@ikrivosheev ikrivosheev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alphavector thank you! LGTM!

src/func.rs Outdated
/// Query::select()
/// .from(Char::Table)
/// .expr(Func::max(Expr::col(Char::SizeW)))
/// .to_owned()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be take()

src/func.rs Outdated
/// .from(Char::Table)
/// .expr(Func::max(Expr::col(Char::SizeW)))
/// .to_owned()
/// .into(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather be more conservative on this type conversion. Would a method into_sub_query_expr with an explicit intent better for this use case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the slow reply.
Yes, perhaps into_sub_query_expr would be better (perhaps even better something like into_scalar_subquery_expr and implementing a separate ScalarSubQueryStatement)

But doesn't it create confusion that for coalesce SelectStatement needs to be explicitly converted to SubQueryStatement, and all other functions need to pass SelectStatement when called

Seems like this would require redoing the whole api or am I complicating things and it's simpler?

Copy link
Member

@tyt2y3 tyt2y3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution

src/expr.rs Outdated
@@ -2163,6 +2163,12 @@ impl Expression for SimpleExpr {
}
}

impl From<SelectStatement> for SimpleExpr {
Copy link
Member

@tyt2y3 tyt2y3 Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is we remove this From and instead have a concrete impl into_sub_query_expr in SelectStatement.
What I am concerning is that there may be multiple ways of converting SelectStatement into SimpleExpr, or may be can have additional options.
That'd be more future proof.

@@ -416,15 +420,15 @@ impl Func {
///
/// assert_eq!(
/// query.to_string(MysqlQueryBuilder),
/// r#"SELECT COALESCE(`size_w`, `size_h`, 12) FROM `character`"#
/// r#"SELECT COALESCE((SELECT MAX(`size_w`) FROM `character`), `size_h`, 12) FROM `character`"#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And btw, can you add a new test case instead? For better test coverage.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by a new test case? I added test cases, insert_coalesce for example. The current test case involves checking for a subquery in coalesce

@ikrivosheev
Copy link
Member

@alphavector hello! Any updates?

@alphavector
Copy link
Author

Sorry for the long reply...

@@ -37,6 +37,10 @@ pub enum SimpleExpr {
Constant(Value),
}

pub trait IntoSimpleExpr {
fn into_sub_query_expr(self) -> SimpleExpr;
Copy link
Member

@ikrivosheev ikrivosheev Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alphavector hello! Naming is confusing me a little bit)

@tyt2y3 what do you think?

pub trait IntoSimpleExpr {
   fn into_simple_expr(self) -> SimpleExpr;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, there is only one impl for this trait. May be we can simply make it an inherit method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triage
Development

Successfully merging this pull request may close these issues.

Function::Coalesce not support the coexistence of SimpleExpr and QueryStatement
3 participants