Skip to content

Conversation

@svenrienstra
Copy link
Contributor

@svenrienstra svenrienstra commented Jul 29, 2024

This PR add supports for CASE statements. Added 4 new types: CaseExpression and When plus their respective visitors.

Also I changed the order of visitors in TypedSingleConditionRenderSupport. Because Condition extends Expression the ExpressionVisitor was used for Conditions.

Question: Should I add support for any Expression in the THEN and OTHER clause (versus Literal now)?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 29, 2024
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 30, 2024
Copy link
Contributor

@schauder schauder left a comment

Choose a reason for hiding this comment

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

I'm asking for a few minor changes.

*/
public class CaseExpression extends AbstractSegment implements Expression {
private final List<When> whenList = new ArrayList<>();
private final Literal other;
Copy link
Contributor

Choose a reason for hiding this comment

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

other is a undescriptive as it gets. I guess we can't use else or default since those are Java keywords.

But elseBranch would be a better name, or maybe whenElse.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also other should be an Expression, not constraint to a Literal

*/
public CaseExpression when(When condition) {
this.whenList.add(condition);
return new CaseExpression(whenList, other);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it uses CaseExpression as an immutable, but it actually modifies the whenList. We should avoid that modification.

*/
public class When extends AbstractSegment {
private final Expression condition;
private final Literal value;
Copy link
Contributor

Choose a reason for hiding this comment

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

To answer your question: Yes, please make value an expression.

* @since 3.4
*/
public class When extends AbstractSegment {
private final Expression condition;
Copy link
Contributor

Choose a reason for hiding this comment

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

condition should be an actual Condition

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: there are other forms of CASE expressions, where you have an expression to start with and in each branch an expression to compare it to. See https://modern-sql.com/feature/case
But that is not what we are doing here.

@svenrienstra
Copy link
Contributor Author

Thanks for the review @schauder. I think I addressed all your comments.

@svenrienstra svenrienstra requested a review from schauder August 5, 2024 06:00
schauder pushed a commit that referenced this pull request Aug 5, 2024
schauder added a commit that referenced this pull request Aug 5, 2024
Minor formatting. Adding author tag in Javadoc. Fixing warnings. Original pull request #1844
@schauder
Copy link
Contributor

schauder commented Aug 5, 2024

Thanks. That is polished and merged.

@schauder schauder closed this Aug 5, 2024
@schauder schauder added this to the 3.4 M1 (2024.1.0) milestone Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

4 participants