jingshanglu commented on a change in pull request #7476:
URL: https://github.com/apache/shardingsphere/pull/7476#discussion_r489305083
##########
File path:
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ProjectionsTokenGenerator.java
##########
@@ -67,4 +92,40 @@ private String getDerivedProjectionText(final Projection
projection) {
}
return projection.getExpression() + " AS " +
projection.getAlias().get() + " ";
}
+
+ private String getDerivedProjectionTextFromColumnOrderByItemSegment(final
DerivedProjection projection, final TableExtractUtils utils, final RouteUnit
routeUnit) {
+ Preconditions.checkState(projection.getAlias().isPresent());
+ Preconditions.checkState(projection.getRealProjection() instanceof
ColumnOrderByItemSegment);
+ ColumnOrderByItemSegment columnOrderByItemSegment =
(ColumnOrderByItemSegment) projection.getRealProjection();
+ ColumnOrderByItemSegment newColumnOrderByItem =
generateNewColumnOrderByItem(columnOrderByItemSegment, routeUnit, utils);
+ return newColumnOrderByItem.getText() + " AS " +
projection.getAlias().get() + " ";
+ }
+
+ private Optional<String> getActualTables(final RouteUnit routeUnit, final
String logicalTableName) {
+ for (RouteMapper each : routeUnit.getTableMappers()) {
+ if (each.getLogicName().equalsIgnoreCase(logicalTableName)) {
+ return Optional.of(each.getActualName());
+ }
+ }
+ return Optional.empty();
+ }
+
+ private ColumnOrderByItemSegment generateNewColumnOrderByItem(final
ColumnOrderByItemSegment old, final RouteUnit routeUnit, final
TableExtractUtils utils) {
+ Optional<OwnerSegment> ownerSegment = old.getColumn().getOwner();
+ if (!ownerSegment.isPresent()) {
+ return old;
+ }
+ if (!utils.needRewrite(ownerSegment.get())) {
+ return old;
+ }
+ Optional<String> actualTableName = getActualTables(routeUnit,
ownerSegment.get().getIdentifier().getValue());
+ Preconditions.checkState(actualTableName.isPresent());
+ ColumnSegment newColumnSegment = new ColumnSegment(0, 0,
old.getColumn().getIdentifier());
+ IdentifierValue newOwnerIdentifier = new
IdentifierValue(ownerSegment.get().getIdentifier().getQuoteCharacter().getStartDelimiter()
Review comment:
Ok, i change it to String.format.
----------------------------------------------------------------
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]