shardingsphere
shardingsphere copied to clipboard
COUNT sql. StringIndexOutOfBoundsException at AbstractSQLBuilder.java:64
Bug Report
version
use encryption in my project, and the maven dependency:
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core</artifactId>
<version>5.3.1</version>
</dependency>
Expected behavior
when I remove the encryption configuration, the sql works fine.
SELECT COUNT(*) FROM (SELECT DISTINCT (u.id), u.username, uc.card, u.sex, uc.grade_id, uc.grade_name, u.phone, u.email, uc.created AS createTime, u.country_calling_code AS countryCallingCode, u.nick_name, u.user_type AS accountType, a.tel AS attentionPhone, a.country_calling_code AS attentionCountryCallingCode, a.email AS attentionEmail, a.typeId AS attentionTypeId, uc.app_id AS appId, uo.utm AS origin, uo.level1, uo.level2, uo.level3, ut.tag_id FROM users u LEFT JOIN user_cards uc ON u.id = uc.uid LEFT JOIN attention a ON u.id = a.uid AND a.num = 1 LEFT JOIN user_origin uo ON u.id = uo.user_id LEFT JOIN user_tag ut ON u.id = ut.user_id AND ut.school_code = ? WHERE uc.areaCode = ? AND uc.created >= ? AND uc.created <= ?) TOTAL
Actual behavior
it throws an exception:
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -5
at java.lang.String.substring(String.java:1967)
at org.apache.shardingsphere.infra.rewrite.sql.impl.AbstractSQLBuilder.getConjunctionText(AbstractSQLBuilder.java:64)
at org.apache.shardingsphere.infra.rewrite.sql.impl.AbstractSQLBuilder.toSQL(AbstractSQLBuilder.java:47)
at org.apache.shardingsphere.infra.rewrite.engine.RouteSQLRewriteEngine.addSQLRewriteUnits(RouteSQLRewriteEngine.java:96)
at org.apache.shardingsphere.infra.rewrite.engine.RouteSQLRewriteEngine.rewrite(RouteSQLRewriteEngine.java:72)
at org.apache.shardingsphere.infra.rewrite.SQLRewriteEntry.rewrite(SQLRewriteEntry.java:73)
at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.rewrite(KernelProcessor.java:59)
at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.generateExecutionContext(KernelProcessor.java:47)
at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.createExecutionContext(ShardingSpherePreparedStatement.java:471)
at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.execute(ShardingSpherePreparedStatement.java:364)
Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
this is my tables configuration:
tables:
users:
columns:
phone:
logicColumn: phone
plainColumn: phone
cipherColumn: phone_cipher
encryptorName: aes_encryptor
attention:
columns:
tel:
logicColumn: tel
plainColumn: tel
cipherColumn: tel_cipher
encryptorName: aes_encryptor
email:
logicColumn: email
plainColumn: email
cipherColumn: email_cipher
encryptorName: aes_encryptor
recipient:
columns:
tel:
logicColumn: tel
plainColumn: tel
cipherColumn: tel_cipher
encryptorName: aes_encryptor