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

>
>

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