You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "Afsalmc (via GitHub)" <gi...@apache.org> on 2023/11/10 10:49:25 UTC

[I] resultSetMetaData.getColumnCount() returns wrong value when using with TOP statement [shardingsphere]

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: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] resultSetMetaData.getColumnCount() returns wrong value when using with TOP statement [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu closed issue #29004: resultSetMetaData.getColumnCount() returns wrong value when using with TOP statement
URL: https://github.com/apache/shardingsphere/issues/29004


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] resultSetMetaData.getColumnCount() returns wrong value when using with TOP statement [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on issue #29004:
URL: https://github.com/apache/shardingsphere/issues/29004#issuecomment-1807298429

   Hi @Afsalmc, here is ShardingSphere slack channel - https://apacheshardingsphere.slack.com/join/shared_invite/zt-sbdde7ie-SjDqo9~I4rYcR18bq0SYTg#/shared-invite/email.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] resultSetMetaData.getColumnCount() returns wrong value when using with TOP statement [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on issue #29004:
URL: https://github.com/apache/shardingsphere/issues/29004#issuecomment-1806595081

   Hi @Afsalmc, thank you for your feedback. ShardingSphere's current support for SQLServer is not perfect, are you interested in submitting PR to optimize this problem?


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] resultSetMetaData.getColumnCount() returns wrong value when using with TOP statement [shardingsphere]

Posted by "Afsalmc (via GitHub)" <gi...@apache.org>.
Afsalmc commented on issue #29004:
URL: https://github.com/apache/shardingsphere/issues/29004#issuecomment-1806830082

   @strongduanmu Sure I will try to debug on my own. I want to discuss further with shardingsphere community. But I had no luck joining the slack channel. Could you please help with that?


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] resultSetMetaData.getColumnCount() returns wrong value when using with TOP statement [shardingsphere]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #29004:
URL: https://github.com/apache/shardingsphere/issues/29004#issuecomment-1854626785

   There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org