spring-projects / spring-projects/spring-data-jpa
Pattern matching for aliases in org.springframework.data.jpa.repository.queryQueryUtils
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.3k
- Forks
- 1.6k
- PR merge metrics
- No merged PRs in 30d
Description
I have a calculated field in a native query that from my understanding the "getFunctionAliases" method should recognise as an alia but the FUNCTION_PATTERN does not seem to match it:
COUNT( DISTINCT (c_prog.id ) ) as completions,
When i add a pageable to sort by completions it trys to do "table_name.completions" rather than just "completions". Check the FUNCTION_PATTERN against my entire query gets a line where I used "array_aggs" correctly though:
array_agg( tag.name ) as tags,
I can share the full query if that would help.
Originally posted by @GregPulse in #2648
Originally posted this as a comment on another bug but the original bug is 3 years or so old so I wanted to make a new ticket.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in org.springframework.data.jpa.repository.query.QueryUtils by reading getFunctionAliases and FUNCTION_PATTERN. Reproduce the native-query pageable sort case with COUNT(DISTINCT (c_prog.id)) as completions, compare it with the working array_agg alias, and add coverage showing that sorting uses completions without a table prefix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, sql
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100