-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
As per the comments on this closed issue, I'm opening a new issue, because sorting still doesn't work for aliases in all cases.
The regex patterns in org.springframework.data.jpa.repository.query.QueryUtils are not broad enough.
The FUNCTION_PATTERN in QueryUtils looks like this:
builder = new StringBuilder(); // any function call including parameters within the brackets builder.append("\\w+\\s*\\([\\w\\.,\\s'=]+\\)"); // the potential alias builder.append("\\s+[as|AS]+\\s+(([\\w\\.]+))"); FUNCTION_PATTERN = compile(builder.toString());which only considers a single pair of parenthesis, but not two or more. So, for example, the earlierstBundleStart is not detected in this query:
SELECT DISTINCT(event.id) as id, event.name as name, event.top_event as topEvent, event.ranking as ranking, MIN(bundle.base_price_amount) as cheapestBundlePrice, MIN(DATE(bundle.start)) as earliestBundleStart, ..
There was also a question on SO about this here, where many people state that they are facing the same issue.
There are and have been several issues (at least #1404, #1724, #1919) with the regex patterns in QueryUtils. I'm wondering, isn't there any more reliable way to parse the queries than with a regex (possibly an AST that is used also to execute the query)?
Edit: here's another closely related issue: #2079