|
15 | 15 | */ |
16 | 16 | package org.springframework.data.jpa.repository.query; |
17 | 17 |
|
18 | | -import static org.springframework.data.jpa.repository.query.QueryTokens.TOKEN_AS; |
19 | | -import static org.springframework.data.jpa.repository.query.QueryTokens.TOKEN_CLOSE_PAREN; |
20 | | -import static org.springframework.data.jpa.repository.query.QueryTokens.TOKEN_COUNT_FUNC; |
21 | | -import static org.springframework.data.jpa.repository.query.QueryTokens.TOKEN_DOUBLE_UNDERSCORE; |
22 | | -import static org.springframework.data.jpa.repository.query.QueryTokens.TOKEN_OPEN_PAREN; |
23 | | -import static org.springframework.data.jpa.repository.query.QueryTokens.TOKEN_SELECT_COUNT; |
| 18 | +import static org.springframework.data.jpa.repository.query.QueryTokens.*; |
24 | 19 |
|
25 | 20 | import org.springframework.data.jpa.repository.query.HqlParser.SelectClauseContext; |
26 | 21 | import org.springframework.data.jpa.repository.query.QueryRenderer.QueryRendererBuilder; |
@@ -208,6 +203,22 @@ public QueryTokenStream visitSelectClause(HqlParser.SelectClauseContext ctx) { |
208 | 203 | return builder; |
209 | 204 | } |
210 | 205 |
|
| 206 | + @Override |
| 207 | + public QueryTokenStream visitSelection(HqlParser.SelectionContext ctx) { |
| 208 | + |
| 209 | + if (isSubquery(ctx)) { |
| 210 | + return super.visitSelection(ctx); |
| 211 | + } |
| 212 | + |
| 213 | + QueryRendererBuilder builder = QueryRenderer.builder(); |
| 214 | + |
| 215 | + builder.append(visit(ctx.selectExpression())); |
| 216 | + |
| 217 | + // do not append variables to skip AS field aliasing |
| 218 | + |
| 219 | + return builder; |
| 220 | + } |
| 221 | + |
211 | 222 | @Override |
212 | 223 | public QueryRendererBuilder visitQueryOrder(HqlParser.QueryOrderContext ctx) { |
213 | 224 |
|
@@ -247,7 +258,7 @@ private QueryRendererBuilder getDistinctCountSelection(QueryTokenStream selectio |
247 | 258 | nested.append(QueryTokens.token(primaryFromAlias)); |
248 | 259 | } else { |
249 | 260 | // keep all the select items to distinct against |
250 | | - nested.append(countSelection); |
| 261 | + nested.append(selectionListbuilder); |
251 | 262 | } |
252 | 263 | return nested; |
253 | 264 | } |
|
0 commit comments