Skip to content

Recognize LEFT, RIGHT, INNER, OUTER, and FULL as reserved words #2874

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.1.0-SNAPSHOT</version>
<version>3.1.0-gh-2864-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data JPA Parent</name>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-envers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-envers</artifactId>
<version>3.1.0-SNAPSHOT</version>
<version>3.1.0-gh-2864-SNAPSHOT</version>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.1.0-SNAPSHOT</version>
<version>3.1.0-gh-2864-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-jpa-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.1.0-SNAPSHOT</version>
<version>3.1.0-gh-2864-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>3.1.0-SNAPSHOT</version>
<version>3.1.0-gh-2864-SNAPSHOT</version>

<name>Spring Data JPA</name>
<description>Spring Data module for JPA repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.1.0-SNAPSHOT</version>
<version>3.1.0-gh-2864-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ reservedWord
| FOR
| FORMAT
| FROM
// | FULL
| FULL
Copy link
Member

Choose a reason for hiding this comment

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

What about the JPQL grammar about FULL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've copied the test cases I used to expose this issue in HQL into the JPQL-based tests. Looks like "RIGHT" is okay, but we need to add support for "LEFT", "INNER", and "OUTER".

| FUNCTION
| GROUP
| GROUPS
Expand All @@ -712,7 +712,7 @@ reservedWord
| IN
| INDEX
| INDICES
// | INNER
| INNER
| INSERT
| INSTANT
| INTERSECT
Expand All @@ -722,7 +722,7 @@ reservedWord
| KEY
| LAST
| LEADING
// | LEFT
| LEFT
| LIKE
| LIMIT
| LIST
Expand Down Expand Up @@ -760,7 +760,7 @@ reservedWord
| OR
| ORDER
| OTHERS
// | OUTER
| OUTER
| OVER
| OVERFLOW
| OVERLAY
Expand All @@ -773,7 +773,7 @@ reservedWord
| QUARTER
| RANGE
| RESPECT
// | RIGHT
| RIGHT
| ROLLUP
| ROW
| ROWS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,12 @@ trim_character

identification_variable
: IDENTIFICATION_VARIABLE
| ORDER // Gap in the spec requires supporting 'Order' as an entity name
| COUNT // Gap in the spec requires supporting 'count' as a possible name
| KEY // Gap in the sepc requires supported 'key' as a possible name
| ORDER
| COUNT
| KEY
| LEFT
| INNER
| OUTER
| spel_expression // we use various SpEL expressions in our queries
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
import static org.assertj.core.api.Assertions.*;

import java.util.regex.Pattern;
import java.util.stream.Stream;

import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.JpaSort;
Expand Down Expand Up @@ -808,6 +812,40 @@ void countQueryShouldWorkEvenWithoutExplicitAlias() {
"select count(b) FROM BookError b WHERE portal = :portal");
}

@ParameterizedTest
@MethodSource("queriesWithReservedWordsAsIdentifiers") // GH-2864
void usingReservedWordAsRelationshipNameShouldWork(String relationshipName, String joinAlias) {

HqlQueryParser.parseQuery(String.format("""
select u
from UserAccountEntity u
join fetch u.lossInspectorLimitConfiguration lil
join fetch u.companyTeam ct
where exists (
select iu
from UserAccountEntity iu
join iu.roles u2r
join u2r.role r
join r.rights r2r
join r2r.%s %s
where
%s.code = :rightCode
and iu = u
)
and ct.id = :teamId
""", relationshipName, joinAlias, joinAlias));
}

static Stream<Arguments> queriesWithReservedWordsAsIdentifiers() {

return Stream.of( //
Arguments.of("right", "rt"), //
Arguments.of("left", "lt"), //
Arguments.of("outer", "ou"), //
Arguments.of("full", "full"), //
Arguments.of("inner", "inr"));
}

private void assertCountQuery(String originalQuery, String countQuery) {
assertThat(createCountQueryFor(originalQuery)).isEqualTo(countQuery);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
import static org.assertj.core.api.Assertions.*;

import java.util.regex.Pattern;
import java.util.stream.Stream;

import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.JpaSort;
Expand Down Expand Up @@ -679,6 +683,40 @@ void queryParserPicksCorrectAliasAmidstMultipleAlises() {
assertThat(alias("select u from User as u left join u.roles as r")).isEqualTo("u");
}

@ParameterizedTest
@MethodSource("queriesWithReservedWordsAsIdentifiers") // GH-2864
void usingReservedWordAsRelationshipNameShouldWork(String relationshipName, String joinAlias) {

JpqlQueryParser.parseQuery(String.format("""
select u
from UserAccountEntity u
join u.lossInspectorLimitConfiguration lil
join u.companyTeam ct
where exists (
select iu
from UserAccountEntity iu
join iu.roles u2r
join u2r.role r
join r.rights r2r
join r2r.inner inr
where
inr.code = :rightCode
and iu = u
)
and ct.id = :teamId
""", relationshipName, joinAlias, joinAlias));
}

static Stream<Arguments> queriesWithReservedWordsAsIdentifiers() {

return Stream.of( //
Arguments.of("right", "rt"), //
Arguments.of("left", "lt"), //
Arguments.of("outer", "ou"), //
Arguments.of("full", "full"), //
Arguments.of("inner", "inr"));
}

private void assertCountQuery(String originalQuery, String countQuery) {
assertThat(createCountQueryFor(originalQuery)).isEqualTo(countQuery);
}
Expand Down