-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New QueryUtils.hasOrderByClause doesn't find subselect/window order by clause #2496
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
Comments
Added postgres JSON examples |
This issue is also seen in spring-data-jpa 2.5.11. See commit that was added to 2.5.x branch - edf06a9. |
You may wish to investigate our hook for native queries using JSqlParser. See #2409 for more details. |
The regex at spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java Line 113 in edf06a9
Couldn't the regex be simplified to |
@svolle Interestingly enough, I plugged in your suggestion, and so far it passes all our existing unit and integrations tests. I want to see if I can capture this scenario in a test and see how it fares there as well. |
Captured the opening comment as a test case. @svolle 's suggestion works on it as well! @Test
void orderByShouldWorkWithSubSelectStatement() {
Sort sort = Sort.by(Order.desc("age"));
assertThat(QueryUtils.applySorting("SELECT\n" //
+ " foo_bar.*\n" //
+ "FROM\n" //
+ " foo foo\n" //
+ "INNER JOIN\n" //
+ " foo_bar_dnrmv foo_bar ON\n" //
+ " foo_bar.foo_id = foo.foo_id\n" //
+ "INNER JOIN\n" //
+ " (\n" //
+ " SELECT\n" //
+ " foo_bar_action.*,\n" //
+ " RANK() OVER (PARTITION BY \"foo_bar_action\".attributes->>'baz' ORDER BY \"foo_bar_action\".attributes->>'qux' DESC) AS ranking\n" //
+ " FROM\n" //
+ " foo_bar_action\n" //
+ " WHERE\n" //
+ " foo_bar_action.deleted_ts IS NULL)\n" //
+ " foo_bar_action ON\n" //
+ " foo_bar.foo_bar_id = foo_bar_action.foo_bar_id\n" //
+ " AND ranking = 1\n" //
+ "INNER JOIN\n" //
+ " bar bar ON\n" //
+ " foo_bar.bar_id = bar.bar_id\n" //
+ "INNER JOIN\n" //
+ " bar_metadata bar_metadata ON\n" //
+ " bar.bar_metadata_key = bar_metadata.bar_metadata_key\n" //
+ "WHERE\n" //
+ " foo.tenant_id =:tenantId\n" //
+ "AND (foo.attributes ->> :serialNum IN (:serialNumValue))", sort)).endsWith("order by foo.age desc");
} |
@gregturn The regex I suggested will not match if the
The following regex does not have this limitation: |
Backported to Megathanks to @svolle! |
Thanks all! |
New QueryUtils.hasOrderByClause doesn't find subselect/window order by clause preventing
order by
from being added to query.spring-data-jpa 2.6.4
java 15
spring-data-jpa/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java
Line 113 in a70fff4
The text was updated successfully, but these errors were encountered: