ddacxhs opened a new issue #9427:
URL: https://github.com/apache/shardingsphere/issues/9427


   ## 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?
   
   5.0.0-alpha
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   
   ShardingSphere-JDBC
   
   ### Expected behavior
   
   no error
   
   ### Actual behavior
   
   Exception in thread "main" java.lang.IllegalArgumentException: Actual value: 
1, Expected value: 46
   
   ### Reason analyze (If you can)
   
   
org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSetMetaData#getColumnCount
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   
   ### Example codes for reproduce this issue (such as a github link).
   
   ```java
   @SpringBootApplication
   public class DemoApplication {
   
       public static void main(String[] args) throws Exception {
           ConfigurableApplicationContext applicationContext = 
SpringApplication.run(DemoApplication.class, args);
           final DataSource dataSource = 
applicationContext.getBean(DataSource.class);
           final DataSource shardingSphereDatasource = 
createShardingSphereDatasource(dataSource);
   
           final int normalResultColumnCount = getResultColumnCount(dataSource);
           final int shardingSphereResultColumnCount = 
getResultColumnCount(shardingSphereDatasource);
   
           System.out.printf("normalResultColumnCount: %d, 
shardingSphereResultColumnCount: %d\n", normalResultColumnCount, 
shardingSphereResultColumnCount);
           Assert.isTrue(normalResultColumnCount == 
shardingSphereResultColumnCount, String.format("Actual value: %d, Expected 
value: %d", shardingSphereResultColumnCount, normalResultColumnCount));
       }
   
       public static DataSource createShardingSphereDatasource(DataSource 
dataSource) throws SQLException {
           Map<String, DataSource> dataSourceMap = new HashMap<>();
           dataSourceMap.put("master", dataSource);
           Properties properties = new Properties();
           ReplicaQueryDataSourceRuleConfiguration 
replicaQueryDataSourceRuleConfiguration = new 
ReplicaQueryDataSourceRuleConfiguration("test", "master", new 
ArrayList<>(dataSourceMap.keySet()), "ROUND_ROBIN");
           Map<String, ShardingSphereAlgorithmConfiguration> 
shardingSphereAlgorithmConfigurationMap = new HashMap<>();
           shardingSphereAlgorithmConfigurationMap.put("ROUND_ROBIN", new 
ShardingSphereAlgorithmConfiguration("ROUND_ROBIN", properties));
           ReplicaQueryRuleConfiguration replicaQueryRuleConfiguration = new 
ReplicaQueryRuleConfiguration(Collections.singletonList(replicaQueryDataSourceRuleConfiguration),
 shardingSphereAlgorithmConfigurationMap);
           return 
ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, 
Collections.singletonList(replicaQueryRuleConfiguration), properties);
       }
   
       public static int getResultColumnCount(DataSource dataSource) throws 
SQLException {
           Connection connection = DataSourceUtils.getConnection(dataSource);
           try {
               // example sql
               String sql = "SELECT u.*, d.Db FROM `mysql`.`user` u INNER JOIN 
`mysql`.`db` d ON d.`User` = u.`User`";
               try (final PreparedStatement preparedStatement = 
connection.prepareStatement(sql)) {
                   try (ResultSet resultSet = preparedStatement.executeQuery()) 
{
                       return resultSet.getMetaData().getColumnCount();
                   }
               }
           } finally {
               DataSourceUtils.releaseConnection(connection, dataSource);
           }
       }
   }
   ```


----------------------------------------------------------------
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]


Reply via email to