userkdg edited a comment on issue #13972:
URL: 
https://github.com/apache/shardingsphere/issues/13972#issuecomment-989485381


   > ## Bug Report
   > subquery table set alias , proxy rewrite sql error . such as :
   > 
   > ```sql
   > MySQL [ec_order_db]> preview select count(1) as cnt from (select a.address 
from ec_oms_order a) as tmp;
   > 
+------------------+-----------------------------------------------------------------------------------------------+
   > | data_source_name | sql                                                   
                                        |
   > 
+------------------+-----------------------------------------------------------------------------------------------+
   > | ec_order_ds      | select count(1) as cnt from (select 
a.a.address_cipher AS address from ec_oms_order a) as tmp |
   > 
+------------------+-----------------------------------------------------------------------------------------------+
   > ```
   > 
   > ### Which version of ShardingSphere did you use?
   > the lastest master
   > 
   > ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   > shardingsphere-proxy
   > 
   > ### Expected behavior
   > ```sql
   >  select count(1) as cnt from (select a.address_cipher AS address from 
ec_oms_order a) as tmp
   > ```
   > 
   > ### Actual behavior
   > ```sql
   > select count(1) as cnt from (select a.a.address_cipher AS address from 
ec_oms_order a) as tmp
   > ```
   > 
   > ### Reason analyze (If you can)
   > 
![image](https://user-images.githubusercontent.com/21057449/144983499-052fbddf-dde8-44ef-ae40-a36da4a7bc55.png)
   > 
   > 
![image](https://user-images.githubusercontent.com/21057449/144983685-f47dfe97-6837-4d04-8371-93584170bfed.png)
   > 
   > ### 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).
   
   I try find bug
   
   position bug:
   
   the lastest master: 
   ``` java 
   private SubstitutableColumnNameToken generateSQLTokens(final String 
tableName, final ColumnProjectionSegment columnSegment, 
                                                              final 
ColumnProjection columnProjection, final SubqueryType subqueryType) {
           Collection<ColumnProjection> projections = 
generateProjections(tableName, columnProjection, subqueryType, false);
           int startIndex = columnSegment.getColumn().getOwner().isPresent() ? 
columnSegment.getColumn().getOwner().get().getStopIndex() + 2 : 
columnSegment.getColumn().getStartIndex();
           int stopIndex = columnSegment.getStopIndex();
           return new SubstitutableColumnNameToken(startIndex, stopIndex, 
projections);
       }
   ```
   
   local fix: 
   ``` java
   private SubstitutableColumnNameToken generateSQLTokens(final String 
tableName, final ColumnProjectionSegment columnSegment, 
                                                              final 
ColumnProjection columnProjection, final SubqueryType subqueryType) {
           Collection<ColumnProjection> projections = 
generateProjections(tableName, columnProjection, subqueryType, 
columnSegment.getColumn().getOwner().isPresent());
           int startIndex = columnSegment.getColumn().getOwner().isPresent() ? 
columnSegment.getColumn().getOwner().get().getStopIndex() : 
columnSegment.getColumn().getStartIndex();
           int stopIndex = columnSegment.getStopIndex();
           return new SubstitutableColumnNameToken(startIndex, stopIndex, 
projections);
       }
   ```
   
   explain:  for source ,
   the method 
org.apache.shardingsphere.encrypt.rewrite.token.generator.impl.EncryptProjectionTokenGenerator#generateSQLTokens
 
   1 line set shothand=false, but 2 line shorthand = 
columnSegment.getColumn().getOwner().isPresent() ,one method variable had tow 
behavior, Behavior inconsistency
   
   test:
   fixed , check normal query / subquery is ok 
   


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


Reply via email to