jingshanglu commented on a change in pull request #7476:
URL: https://github.com/apache/shardingsphere/pull/7476#discussion_r489306602



##########
File path: 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ProjectionsTokenGenerator.java
##########
@@ -44,17 +60,26 @@ public boolean isGenerateSQLToken(final SQLStatementContext 
sqlStatementContext)
     
     @Override
     public ProjectionsToken generateSQLToken(final SelectStatementContext 
selectStatementContext) {
-        Collection<String> derivedProjectionTexts = 
getDerivedProjectionTexts(selectStatementContext);
+        Map<RouteUnit, Collection<String>> derivedProjectionTexts = 
getDerivedProjectionTexts(selectStatementContext);
         return new 
ProjectionsToken(selectStatementContext.getProjectionsContext().getStopIndex() 
+ 1 + " ".length(), derivedProjectionTexts);
     }
     
-    private Collection<String> getDerivedProjectionTexts(final 
SelectStatementContext selectStatementContext) {
-        Collection<String> result = new LinkedList<>();
-        for (Projection each : 
selectStatementContext.getProjectionsContext().getProjections()) {
-            if (each instanceof AggregationProjection && 
!((AggregationProjection) each).getDerivedAggregationProjections().isEmpty()) {
-                result.addAll(((AggregationProjection) 
each).getDerivedAggregationProjections().stream().map(this::getDerivedProjectionText).collect(Collectors.toList()));
-            } else if (each instanceof DerivedProjection) {
-                result.add(getDerivedProjectionText(each));
+    private Map<RouteUnit, Collection<String>> getDerivedProjectionTexts(final 
SelectStatementContext selectStatementContext) {
+        Map<RouteUnit, Collection<String>> result = new HashMap<>();
+        for (RouteUnit routeUnit : 
routeContext.getRouteResult().getRouteUnits()) {
+            result.put(routeUnit, new LinkedList<>());
+            for (Projection each : 
selectStatementContext.getProjectionsContext().getProjections()) {
+                if (each instanceof AggregationProjection && 
!((AggregationProjection) each).getDerivedAggregationProjections().isEmpty()) {
+                    result.get(routeUnit).addAll(((AggregationProjection) 
each).getDerivedAggregationProjections().stream().map(this::getDerivedProjectionText).collect(Collectors.toList()));
+                } else if (each instanceof DerivedProjection) {
+                    if (!(((DerivedProjection) each).getRealProjection() 
instanceof ColumnOrderByItemSegment)) {
+                        
result.get(routeUnit).add(getDerivedProjectionText(each));
+                        continue;
+                    }
+                    TableExtractUtils utils = new TableExtractUtils();
+                    
utils.extractTablesFromSelect(selectStatementContext.getSqlStatement());
+                    
result.get(routeUnit).add(getDerivedProjectionTextFromColumnOrderByItemSegment((DerivedProjection)
 each, utils, routeUnit));
+                }

Review comment:
       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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to