ddacxhs commented on issue #9427:
URL: https://github.com/apache/shardingsphere/issues/9427#issuecomment-784908684


   @tristaZero 
   ## test data table
   
   ```sql
   CREATE TABLE employees
   (
       emp_no     INT            NOT NULL,
       birth_date DATE           NOT NULL,
       first_name VARCHAR(14)    NOT NULL,
       last_name  VARCHAR(16)    NOT NULL,
       gender     ENUM ('M','F') NOT NULL,
       hire_date  DATE           NOT NULL,
       PRIMARY KEY (emp_no)
   ) ENGINE = innodb
     CHARACTER SET utf8;
   
   CREATE TABLE titles
   (
       emp_no    INT         NOT NULL,
       title     VARCHAR(50) NOT NULL,
       from_date DATE        NOT NULL,
       to_date   DATE,
       FOREIGN KEY (emp_no) REFERENCES employees (emp_no) ON DELETE CASCADE,
       PRIMARY KEY (emp_no, title, from_date)
   ) ENGINE = innodb
     CHARACTER SET utf8;
   
   
   INSERT INTO `employees`
   VALUES (10001, '1953-09-02', 'Georgi', 'Facello', 'M', '1986-06-26'),
          (10002, '1964-06-02', 'Bezalel', 'Simmel', 'F', '1985-11-21');
   
   INSERT INTO `titles`
   VALUES (10001, 'Senior Engineer', '1986-06-26', '9999-01-01'),
          (10002, 'Staff', '1996-08-03', '9999-01-01');
   ```
   
   ## test code
   
   ```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 emp.*, t.title FROM employees emp INNER 
JOIN titles t ON emp.emp_no = t.emp_no";
               try (final PreparedStatement preparedStatement = 
connection.prepareStatement(sql)) {
                   try (ResultSet resultSet = preparedStatement.executeQuery()) 
{
                       return resultSet.getMetaData().getColumnCount();
                   }
               }
           } finally {
               DataSourceUtils.releaseConnection(connection, dataSource);
           }
       }
   }
   ```
   
   ## run results
   
   ### Expected
   
   `normalResultColumnCount: 7, shardingSphereResultColumnCount: 7`
   
   ### Actual
   
   `normalResultColumnCount: 7, shardingSphereResultColumnCount: 1`
   


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