Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
gregturn committed Sep 1, 2023
1 parent 1a5b08a commit 19fe71e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ ql_statement
;

select_statement
: select_clause from_clause (where_clause)? (groupby_clause)? (having_clause)? (orderby_clause)?
: select_clause from_clause (where_clause)? (groupby_clause)? (having_clause)? (orderby_clause)? (setOperator_with_select_statement)*
;

setOperator_with_select_statement
: INTERSECT select_statement
| UNION select_statement
| EXCEPT select_statement
;

update_statement
Expand Down Expand Up @@ -785,6 +791,7 @@ ELSE : E L S E;
EMPTY : E M P T Y;
ENTRY : E N T R Y;
ESCAPE : E S C A P E;
EXCEPT : E X C E P T;
EXISTS : E X I S T S;
EXP : E X P;
EXTRACT : E X T R A C T;
Expand All @@ -798,6 +805,7 @@ HAVING : H A V I N G;
IN : I N;
INDEX : I N D E X;
INNER : I N N E R;
INTERSECT : I N T E R S E C T;
IS : I S;
JOIN : J O I N;
KEY : K E Y;
Expand Down Expand Up @@ -840,6 +848,7 @@ TREAT : T R E A T;
TRIM : T R I M;
TRUE : T R U E;
TYPE : T Y P E;
UNION : U N I O N;
UPDATE : U P D A T E;
UPPER : U P P E R;
VALUE : V A L U E;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ public List<JpaQueryParsingToken> visitSelect_statement(JpqlParser.Select_statem
tokens.addAll(visit(ctx.orderby_clause()));
}

ctx.setOperator_with_select_statement().forEach(setOperatorWithSelectStatementContext -> {
tokens.addAll(visit(setOperatorWithSelectStatementContext));
});

return tokens;
}

@Override
public List<JpaQueryParsingToken> visitSetOperator_with_select_statement(
JpqlParser.SetOperator_with_select_statementContext ctx) {

List<JpaQueryParsingToken> tokens = new ArrayList<>();

if (ctx.INTERSECT() != null) {
tokens.add(new JpaQueryParsingToken(ctx.INTERSECT()));
} else if (ctx.UNION() != null) {
tokens.add(new JpaQueryParsingToken(ctx.UNION()));
} else if (ctx.EXCEPT() != null) {
tokens.add(new JpaQueryParsingToken(ctx.EXCEPT()));
}

tokens.addAll(visit(ctx.select_statement()));

return tokens;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ public List<JpaQueryParsingToken> visitSelect_statement(JpqlParser.Select_statem
}
}

ctx.setOperator_with_select_statement().forEach(setOperatorWithSelectStatementContext -> {
tokens.addAll(visit(setOperatorWithSelectStatementContext));
});

return tokens;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1610,4 +1610,17 @@ void doublePipeShouldBeValidAsAStringConcatOperator() {
""");
}

@Test // GH-3136
void combinedSelectStatementsShouldWork() {

assertQuery("""
select e from Employee e where e.last_name = 'Baggins'
intersect
select e from Employee e where e.first_name = 'Samwise'
union
select e from Employee e where e.home = 'The Shire'
except
select e from Employee e where e.home = 'Isengard'
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -992,4 +992,32 @@ void doublePipeShouldBeValidAsAStringConcatOperator() {
from Employee e
""");
}

@Test // GH-3136
void combinedSelectStatementsShouldWork() {

assertQuery("""
select e from Employee e where e.last_name = 'Baggins'
intersect
select e from Employee e where e.first_name = 'Samwise'
union
select e from Employee e where e.home = 'The Shire'
except
select e from Employee e where e.home = 'Isengard'
""");
}

@Disabled
@Test // GH-3136
void additionalStringOperationShouldWork() {

assertQuery("""
select
replace(e.name, 'Baggins', 'Proudfeet'),
left(e.role, 4),
right(e.home, 5),
cast(e.distance_from_home, int)
from Employee e
""");
}
}

0 comments on commit 19fe71e

Please sign in to comment.