Skip to content

Allow native SQL functions to have ';' as arguments #2891

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 2 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-2884-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-2884-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-2884-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-2884-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-2884-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-2884-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public abstract class QueryUtils {

builder = new StringBuilder();
// any function call including parameters within the brackets
builder.append("\\w+\\s*\\([\\w\\.,\\s'=:\\\\?]+\\)");
builder.append("\\w+\\s*\\([\\w\\.,\\s'=:;\\\\?]+\\)");
// the potential alias
builder.append("\\s+[as|AS]+\\s+(([\\w\\.]+))");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@
*/
package org.springframework.data.jpa.repository.query;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.springframework.data.jpa.repository.query.QueryUtils.applySorting;
import static org.springframework.data.jpa.repository.query.QueryUtils.createCountQueryFor;
import static org.springframework.data.jpa.repository.query.QueryUtils.detectAlias;
import static org.springframework.data.jpa.repository.query.QueryUtils.getOuterJoinAliases;
import static org.springframework.data.jpa.repository.query.QueryUtils.hasConstructorExpression;
import static org.springframework.data.jpa.repository.query.QueryUtils.removeSubqueries;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.jpa.repository.query.QueryUtils.*;

import java.util.Collections;
import java.util.Set;
Expand Down Expand Up @@ -891,4 +885,30 @@ void orderByShouldWorkWithSubSelectStatements() {
+ ") as timestamp\n" //
+ "from foo f", sort)).endsWith("order by f.age desc");
}

@Test // GH-2884
void functionAliasShouldSupportArgumentsWithCommasOrArgumentsWithSemiColons() {

assertThat(QueryUtils.getFunctionAliases("""
select s.id as id, s.name as name, gp.points
from specialist s
left join (
select q.specialist_id, listagg(q.points, ',') as points
from qualification q
group by q.specialist_id
) gp on gp.specialist_id = s.id
where name like :name
""")).containsExactly("points");

assertThat(QueryUtils.getFunctionAliases("""
select s.id as id, s.name as name, gp.points
from specialist s
left join (
select q.specialist_id, listagg(q.points, ';') as points
from qualification q
group by q.specialist_id
) gp on gp.specialist_id = s.id
where name like :name
""")).containsExactly("points");
}
}