Afsalmc opened a new issue, #29004: URL: https://github.com/apache/shardingsphere/issues/29004
## 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.4.1 ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy? ShardingSphere-JDBC ### Expected behavior resultSetMetaData.getColumnCount() gives actual column count (x). ### Actual behavior resultSetMetaData.getColumnCount() gives actual column count -1 (x-1). ### Reason analyze (If you can) In ShardingSphereResultSetMetaData ``` public int getColumnCount() throws SQLException { if (this.sqlStatementContext instanceof SelectStatementContext) { return this.selectContainsEnhancedTable && this.hasSelectExpandProjections() ? ((SelectStatementContext)this.sqlStatementContext).getProjectionsContext().getExpandProjections().size() : this.resultSetMetaData.getColumnCount(); } else { return this.resultSetMetaData.getColumnCount(); } } ``` `((SelectStatementContext)this.sqlStatementContext).getProjectionsContext().getExpandProjections().size()` yields wrong value. while `this.resultSetMetaData.getColumnCount()` yields correct value. ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc. Select TOP 1 Accountid,Accountname from Account or basically any SQL Server query with TOP statement to limit the number of rows. ### Example codes for reproduce this issue (such as a github link). sharding.yml ``` dataSources: ds0: dataSourceClassName: com.zaxxer.hikari.HikariDataSource driverClassName: com.microsoft.sqlserver jdbcUrl: jdbc:sqlserver://127.0.0.1:1401;databaseName=db1;loginTimeout=300;encrypt=false; username: s5a password: Passw0rd props: sql-show: true rules: - !SHARDING tables: Account: actualDataNodes: ds0.Account tableStrategy: standard: shardingColumn: AccountID shardingAlgorithmName: order_sharding_algorithm keyGenerateStrategy: column: AccountID keyGeneratorName: snowflake Profile: actualDataNodes: ds0.Account tableStrategy: standard: shardingColumn: AccountID shardingAlgorithmName: order_sharding_algorithm keyGenerateStrategy: column: AccountID keyGeneratorName: snowflake Usr: actualDataNodes: ds0.Usr tableStrategy: standard: shardingColumn: AccountID shardingAlgorithmName: order_sharding_algorithm keyGenerateStrategy: column: AccountID keyGeneratorName: snowflake C2: actualDataNodes: ds0.C2 tableStrategy: standard: shardingColumn: AccountID shardingAlgorithmName: order_sharding_algorithm keyGenerateStrategy: column: AccountID keyGeneratorName: snowflake shardingAlgorithms: order_sharding_algorithm: type: INLINE props: algorithm-expression: ds${AccountID % 2} order_sharding_algorithm_db: type: INLINE props: algorithm-expression: db${AccountID % 2} keyGenerators: snowflake: type: SNOWFLAKE - !MASK tables: Account: columns: TaxId: maskAlgorithm: md5_mask AccountConfig: columns: AttributeName: maskAlgorithm: md5_mask maskAlgorithms: md5_mask: type: MD5 mask_from_x_to_y_mask: type: MASK_FROM_X_TO_Y props: from-x: 1 to-y: 6 replace-char: '*' keep_first_n_last_m_mask: type: KEEP_FIRST_N_LAST_M props: first-n: 3 last-m: 4 replace-char: '*' ``` javacode.java ``` conn = dataSource.getConnection(); stmt = conn.createStatement(); stmt.setFetchSize(1); var isResult = stmt.execute(message); // true if the first result is a ResultSet object; false if it is an update count or there are no results if(!isResult){ out.write(0); continue; } resultSet = stmt.getResultSet(); } resultSetMetaData = resultSet.getMetaData(); columnCount = resultSetMetaData.getColumnCount(); System.out.println("columncount: "+columnCount); ``` -- 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]
