strongduanmu commented on issue #10563:
URL:
https://github.com/apache/shardingsphere/issues/10563#issuecomment-851383186
After we change the sql to `select count(1) from t_order group by order_id
order by order_id desc;`, another error will occur:
```
ERROR: Can't find index: AggregationProjection(type=COUNT,
innerExpression=(1), alias=Optional.empty, derivedAggregationProjections=[],
index=-1), please add alias for aggregate selections
```
This exception is because the `columnLabel` that in the
`columnLabelIndexMap` returned by PG is `count`, and the `columnLabel`
processed by SS is `count(1)`, the inconsistency of the `columnLabel` results
in an exception in the verification. Considering the different processing way
of MySQL, we need to distinguish between different database dialects to obtain
the `columnLabel` in SS.
```java
private void setIndexForAggregationProjection(final Map<String, Integer>
columnLabelIndexMap) {
for (AggregationProjection each :
projectionsContext.getAggregationProjections()) {
Preconditions.checkState(columnLabelIndexMap.containsKey(each.getColumnLabel()),
"Can't find index: %s, please add alias for aggregate selections", each);
each.setIndex(columnLabelIndexMap.get(each.getColumnLabel()));
for (AggregationProjection derived :
each.getDerivedAggregationProjections()) {
Preconditions.checkState(columnLabelIndexMap.containsKey(derived.getColumnLabel()),
"Can't find index: %s", derived);
derived.setIndex(columnLabelIndexMap.get(derived.getColumnLabel()));
}
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]