ddacxhs opened a new issue #11442: URL: https://github.com/apache/shardingsphere/issues/11442
## Bug Report **For English only**, other languages will not accept. Before report a bug, make sure you have: - Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues). - Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview). Please pay attention on issues you submitted, because we maybe need more details. If no response anymore and we cannot reproduce it on current information, we will **close it**. Please answer these questions before submitting your issue. Thanks! ### Which version of ShardingSphere did you use? ```xml <dependency> <groupId>org.apache.shardingsphere</groupId> <artifactId>shardingsphere-jdbc-core</artifactId> <version>5.0.0-beta</version> </dependency> ``` ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy? `ShardingSphere-JDBC` ### Expected behavior No errors, no exceptions ### Actual behavior ``` Exception in thread "main" org.springframework.dao.TransientDataAccessResourceException: StatementCallback; SQL [SELECT DISTINCT * FROM( SELECT a.* FROM actor a LEFT JOIN film_actor b ON a.actor_id = b.actor_id WHERE b.film_id IN (1, 23) ORDER BY b.last_update DESC) tmp]; Column index out of range.; nested exception is java.sql.SQLException: Column index out of range. at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:110) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1442) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:387) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:451) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:461) at org.springframework.jdbc.core.JdbcTemplate.queryForList(JdbcTemplate.java:489) at example.ReadWriteSplitApp.main(ReadWriteSplitApp.java:51) Caused by: java.sql.SQLException: Column index out of range. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) at com.mysql.cj.jdbc.result.ResultSetMetaData.getField(ResultSetMetaData.java:221) at com.mysql.cj.jdbc.result.ResultSetMetaData.getColumnLabel(ResultSetMetaData.java:179) at org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSetMetaData.getColumnLabel(ShardingSphereResultSetMetaData.java:97) at org.springframework.jdbc.support.JdbcUtils.lookupColumnName(JdbcUtils.java:458) at org.springframework.jdbc.core.ColumnMapRowMapper.mapRow(ColumnMapRowMapper.java:57) at org.springframework.jdbc.core.ColumnMapRowMapper.mapRow(ColumnMapRowMapper.java:49) at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:94) at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:61) at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:439) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:375) ... 4 more ``` ### Reason analyze (If you can) org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSetMetaData#getColumnCount Inconsistent with the real return of com.mysql.cj.jdbc.result.ResultSetMetaData#getColumnCount ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc. **mysql database** ```sql CREATE TABLE `actor` ( `actor_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `first_name` varchar(45) NOT NULL, `last_name` varchar(45) NOT NULL, `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`actor_id`), KEY `idx_actor_last_name` (`last_name`) ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4; CREATE TABLE `film_actor` ( `actor_id` smallint(5) unsigned NOT NULL, `film_id` smallint(5) unsigned NOT NULL, `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`actor_id`,`film_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; INSERT INTO actor (actor_id, first_name, last_name, last_update) VALUES (1, 'PENELOPE', 'GUINESS', '2006-02-15 04:34:33'), (2, 'NICK', 'WAHLBERG', '2006-02-15 04:34:33'), (3, 'ED', 'CHASE', '2006-02-15 04:34:33'), (4, 'JENNIFER', 'DAVIS', '2006-02-15 04:34:33'), (5, 'JOHNNY', 'LOLLOBRIGIDA', '2006-02-15 04:34:33'), (6, 'BETTE', 'NICHOLSON', '2006-02-15 04:34:33'), (7, 'GRACE', 'MOSTEL', '2006-02-15 04:34:33'), (8, 'MATTHEW', 'JOHANSSON', '2006-02-15 04:34:33'), (9, 'JOE', 'SWANK', '2006-02-15 04:34:33'), (10, 'CHRISTIAN', 'GABLE', '2006-02-15 04:34:33'); INSERT INTO film_actor (actor_id, film_id, last_update) VALUES (1, 1, '2006-02-15 05:05:03'), (1, 23, '2006-02-15 05:05:03'), (1, 25, '2006-02-15 05:05:03'); ``` **sql statement** ```sql SELECT DISTINCT * FROM (SELECT a.* FROM actor a LEFT JOIN film_actor b ON a.actor_id = b.actor_id WHERE b.film_id IN (1, 23) ORDER BY b.last_update DESC) tmp ``` ### Example codes for reproduce this issue (such as a github link). ```java import com.zaxxer.hikari.HikariDataSource; import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; import org.springframework.jdbc.core.JdbcTemplate; import javax.sql.DataSource; import java.sql.SQLException; import java.util.*; import java.util.stream.Collectors; public class ReadWriteSplitApp { public static DataSource createDataSource() { HikariDataSource hikariDataSource = new HikariDataSource(); hikariDataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); hikariDataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=Asia/Shanghai"); hikariDataSource.setUsername("root"); hikariDataSource.setPassword("root"); return hikariDataSource; } public static DataSource createReadWriteSplitDataSource() throws SQLException { Map<String, DataSource> dataSourceMap = new HashMap<>(); dataSourceMap.put("primary", createDataSource()); dataSourceMap.put("replicate", createDataSource()); ReadwriteSplittingDataSourceRuleConfiguration readwriteSplittingDataSourceRuleConfiguration = new ReadwriteSplittingDataSourceRuleConfiguration( "test", null, "primary", dataSourceMap.keySet().stream().filter(k -> !"primary".equals(k)).collect(Collectors.toList()), "ROUND_ROBIN" ); ReadwriteSplittingRuleConfiguration readwriteSplittingRuleConfiguration = new ReadwriteSplittingRuleConfiguration( Collections.singletonList(readwriteSplittingDataSourceRuleConfiguration), new HashMap<>(3) ); return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, Collections.singletonList(readwriteSplittingRuleConfiguration), new Properties()); } public static void main(String[] args) throws Exception { DataSource dataSource = createReadWriteSplitDataSource(); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); List<Map<String, Object>> list = jdbcTemplate.queryForList("SELECT DISTINCT * FROM( SELECT a.* FROM actor a LEFT JOIN film_actor b ON a.actor_id = b.actor_id WHERE b.film_id IN (1, 23) ORDER BY b.last_update DESC) tmp"); System.out.println("Run Success!"); } } ``` -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
