Make sure sorting is rendered correctly for JPQL query using set operator.
Original Pull Request: #3695
This commit is contained in:
committed by
Mark Paluch
parent
262e05eda8
commit
2b562420a6
@@ -68,6 +68,9 @@ class JpqlCountQueryTransformer extends JpqlQueryRenderer {
|
||||
if (ctx.having_clause() != null) {
|
||||
builder.appendExpression(visit(ctx.having_clause()));
|
||||
}
|
||||
if(ctx.set_fuction() != null) {
|
||||
builder.appendExpression(visit(ctx.set_fuction()));
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,11 @@ class JpqlSortedQueryTransformer extends JpqlQueryRenderer {
|
||||
builder.appendExpression(visit(ctx.having_clause()));
|
||||
}
|
||||
|
||||
doVisitOrderBy(builder, ctx);
|
||||
if(ctx.set_fuction() != null) {
|
||||
builder.appendExpression(visit(ctx.set_fuction()));
|
||||
} else {
|
||||
doVisitOrderBy(builder, ctx);
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
@@ -26,9 +26,9 @@ import org.springframework.data.jpa.repository.query.QueryRenderer.TokenRenderer
|
||||
/**
|
||||
* Tests built around examples of EQL found in the EclipseLink's docs at
|
||||
* https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/JPQL<br/>
|
||||
* With the exception of {@literal MOD} which is defined as {@literal MOD(arithmetic_expression , arithmetic_expression)},
|
||||
* but shown in tests as {@literal MOD(arithmetic_expression ? arithmetic_expression)}.
|
||||
* <br/>
|
||||
* With the exception of {@literal MOD} which is defined as
|
||||
* {@literal MOD(arithmetic_expression , arithmetic_expression)}, but shown in tests as
|
||||
* {@literal MOD(arithmetic_expression ? arithmetic_expression)}. <br/>
|
||||
* IMPORTANT: Purely verifies the parser without any transformations.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
@@ -415,7 +415,6 @@ class EqlComplianceTests {
|
||||
assertQuery("SELECT e FROM Employee e WHERE (e.active IS NOT NULL OR e.active = true)");
|
||||
}
|
||||
|
||||
|
||||
@Test // GH-3496
|
||||
void lateralShouldBeAValidParameter() {
|
||||
|
||||
@@ -442,13 +441,13 @@ class EqlComplianceTests {
|
||||
}
|
||||
|
||||
@ParameterizedTest // GH-3136
|
||||
@ValueSource(strings = {"STRING", "INTEGER", "FLOAT", "DOUBLE"})
|
||||
@ValueSource(strings = { "STRING", "INTEGER", "FLOAT", "DOUBLE" })
|
||||
void jpqlCast(String targetType) {
|
||||
assertQuery("SELECT CAST(e.salary AS %s) FROM Employee e".formatted(targetType));
|
||||
}
|
||||
|
||||
@ParameterizedTest // GH-3136
|
||||
@ValueSource(strings = {"LEFT", "RIGHT"})
|
||||
@ValueSource(strings = { "LEFT", "RIGHT" })
|
||||
void leftRightStringFunctions(String keyword) {
|
||||
assertQuery("SELECT %s(e.name, 3) FROM Employee e".formatted(keyword));
|
||||
}
|
||||
|
||||
@@ -784,6 +784,15 @@ class JpqlQueryTransformerTests {
|
||||
""");
|
||||
}
|
||||
|
||||
@Test // GH-3427
|
||||
void sortShouldBeAppendedToFullSelectOnlyInCaseOfSetOperator() {
|
||||
|
||||
String source = "SELECT tb FROM Test tb WHERE (tb.type='A') UNION SELECT tb FROM Test tb WHERE (tb.type='B')";
|
||||
String target = createQueryFor(source, Sort.by("Type").ascending());
|
||||
|
||||
assertThat(target).isEqualTo("SELECT tb FROM Test tb WHERE (tb.type = 'A') UNION SELECT tb FROM Test tb WHERE (tb.type = 'B') order by tb.Type asc");
|
||||
}
|
||||
|
||||
static Stream<Arguments> queriesWithReservedWordsAsIdentifiers() {
|
||||
|
||||
return Stream.of( //
|
||||
|
||||
Reference in New Issue
Block a user