I used H2 and sharding-jdbc for unit tests. When the "COUNT SQL" has spaces between brackets, Errors will occur.
SQL example:
SELECT COUNT( 1 ) FROM table;
Error:
Can't find index: AggregationProjection(type=COUNT, innerExpression=( ), alias=Optional.empty, databaseType=org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType@914adfb, derivedAggregationProjections=[], index=-1), please add alias for aggregate selections
java.lang.IllegalStateException: Can't find index: AggregationProjection(type=COUNT, innerExpression=( ), alias=Optional.empty, databaseType=org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType@914adfb, derivedAggregationProjections=[], index=-1), please add alias for aggregate selections
at com.google.common.base.Preconditions.checkState(Preconditions.java:589)
at org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext.setIndexForAggregationProjection(SelectStatementContext.java:230)
at org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext.setIndexes(SelectStatementContext.java:222)
at org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger.merge(ShardingDQLResultMerger.java:63)
at org.apache.shardingsphere.infra.merge.MergeEngine.executeMerge(MergeEngine.java:78)
at org.apache.shardingsphere.infra.merge.MergeEngine.merge(MergeEngine.java:67)
at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.mergeQuery(ShardingSpherePreparedStatement.java:487)
at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.executeQuery(ShardingSpherePreparedStatement.java:218)
This issue is similar to https://github.com/apache/shardingsphere/issues/2036.
I used H2 and sharding-jdbc for unit tests. When the "COUNT SQL" has spaces between brackets, Errors will occur.
SQL example: SELECT COUNT( 1 ) FROM table;
Error: Can't find index: AggregationProjection(type=COUNT, innerExpression=( ), alias=Optional.empty, databaseType=org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType@914adfb, derivedAggregationProjections=[], index=-1), please add alias for aggregate selections java.lang.IllegalStateException: Can't find index: AggregationProjection(type=COUNT, innerExpression=( ), alias=Optional.empty, databaseType=org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType@914adfb, derivedAggregationProjections=[], index=-1), please add alias for aggregate selections at com.google.common.base.Preconditions.checkState(Preconditions.java:589) at org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext.setIndexForAggregationProjection(SelectStatementContext.java:230) at org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext.setIndexes(SelectStatementContext.java:222) at org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger.merge(ShardingDQLResultMerger.java:63) at org.apache.shardingsphere.infra.merge.MergeEngine.executeMerge(MergeEngine.java:78) at org.apache.shardingsphere.infra.merge.MergeEngine.merge(MergeEngine.java:67) at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.mergeQuery(ShardingSpherePreparedStatement.java:487) at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.executeQuery(ShardingSpherePreparedStatement.java:218)
ShardingSphere JDBC Core version: 5.1.2 h2 version: 1.4.200