You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/02/18 09:51:30 UTC
[GitHub] [shardingsphere] ddacxhs opened a new issue #9427: java.sql.ResultSetMetaData#getColumnCount returns inconsistent
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:
users@infra.apache.org
[GitHub] [shardingsphere] tristaZero commented on issue #9427: java.sql.ResultSetMetaData#getColumnCount returns inconsistent
Posted by GitBox <gi...@apache.org>.
tristaZero commented on issue #9427:
URL: https://github.com/apache/shardingsphere/issues/9427#issuecomment-785541513
Hi @ddacxhs ,
Clear enough. Thanks for your info.
Like @terrymanu said, could you try the master branch?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] ddacxhs commented on issue #9427: java.sql.ResultSetMetaData#getColumnCount returns inconsistent
Posted by GitBox <gi...@apache.org>.
ddacxhs commented on issue #9427:
URL: https://github.com/apache/shardingsphere/issues/9427#issuecomment-782832901
> Hi @ddacxhs
>
> You just test on the `ReplicaQuery` scenario, don't you?
>
> > SELECT u.*, d.Db FROM `mysql`.`user` u INNER JOIN `mysql`.`db` d ON d.`User` = u.`User`
>
> What's the expectation and actual result of the column's amount?
是的,使用了读写分离做的查询,您可运行下给出的代码,运行给出的查询结果列数与实际列数不匹配
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] ddacxhs commented on issue #9427: java.sql.ResultSetMetaData#getColumnCount returns inconsistent
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
[GitHub] [shardingsphere] ddacxhs commented on issue #9427: java.sql.ResultSetMetaData#getColumnCount returns inconsistent
Posted by GitBox <gi...@apache.org>.
ddacxhs commented on issue #9427:
URL: https://github.com/apache/shardingsphere/issues/9427#issuecomment-782832728
是的,使用了读写分离做的查询,您可运行下给出的代码,查询出的列数与实际列数不匹配
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] ddacxhs commented on issue #9427: java.sql.ResultSetMetaData#getColumnCount returns inconsistent
Posted by GitBox <gi...@apache.org>.
ddacxhs commented on issue #9427:
URL: https://github.com/apache/shardingsphere/issues/9427#issuecomment-785639206
> Maybe 2 months later, we are testing now
Ok, thank you
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] ddacxhs removed a comment on issue #9427: java.sql.ResultSetMetaData#getColumnCount returns inconsistent
Posted by GitBox <gi...@apache.org>.
ddacxhs removed a comment on issue #9427:
URL: https://github.com/apache/shardingsphere/issues/9427#issuecomment-782832728
是的,使用了读写分离做的查询,您可运行下给出的代码,查询出的列数与实际列数不匹配
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] ddacxhs edited a comment on issue #9427: java.sql.ResultSetMetaData#getColumnCount returns inconsistent
Posted by GitBox <gi...@apache.org>.
ddacxhs edited a comment on issue #9427:
URL: https://github.com/apache/shardingsphere/issues/9427#issuecomment-785550008
@tristaZero @terrymanu
The master branch has passed the test. When will the official version be released?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] terrymanu commented on issue #9427: java.sql.ResultSetMetaData#getColumnCount returns inconsistent
Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #9427:
URL: https://github.com/apache/shardingsphere/issues/9427#issuecomment-785607112
Maybe 2 months later, we are testing now
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] terrymanu commented on issue #9427: java.sql.ResultSetMetaData#getColumnCount returns inconsistent
Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #9427:
URL: https://github.com/apache/shardingsphere/issues/9427#issuecomment-785533449
This issue is fixed in the current master branch, could try it?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] tristaZero commented on issue #9427: java.sql.ResultSetMetaData#getColumnCount returns inconsistent
Posted by GitBox <gi...@apache.org>.
tristaZero commented on issue #9427:
URL: https://github.com/apache/shardingsphere/issues/9427#issuecomment-782538784
Hi @ddacxhs
You just test on the `ReplicaQuery` scenario, don't you?
> SELECT u.*, d.Db FROM `mysql`.`user` u INNER JOIN `mysql`.`db` d ON d.`User` = u.`User`
What's the expectation and actual result of the column's amount?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] tristaZero commented on issue #9427: java.sql.ResultSetMetaData#getColumnCount returns inconsistent
Posted by GitBox <gi...@apache.org>.
tristaZero commented on issue #9427:
URL: https://github.com/apache/shardingsphere/issues/9427#issuecomment-784697229
Hi @ddacxhs ,
Could you test other simple SQLs? We need to figure out whether it has something to do with SQLs.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] ddacxhs closed issue #9427: java.sql.ResultSetMetaData#getColumnCount returns inconsistent
Posted by GitBox <gi...@apache.org>.
ddacxhs closed issue #9427:
URL: https://github.com/apache/shardingsphere/issues/9427
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [shardingsphere] ddacxhs commented on issue #9427: java.sql.ResultSetMetaData#getColumnCount returns inconsistent
Posted by GitBox <gi...@apache.org>.
ddacxhs commented on issue #9427:
URL: https://github.com/apache/shardingsphere/issues/9427#issuecomment-785550008
@tristaZero @tristaZero
The master branch has passed the test. When will the official version be released?
----------------------------------------------------------------
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:
users@infra.apache.org