You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/08/15 03:51:07 UTC

[GitHub] [shardingsphere] tristaZero commented on a change in pull request #6837: fix rewrite for subquery

tristaZero commented on a change in pull request #6837:
URL: https://github.com/apache/shardingsphere/pull/6837#discussion_r470933372



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/statement/dml/SelectStatementContext.java
##########
@@ -194,68 +178,7 @@ public boolean isSameGroupByAndOrderByItems() {
     
     @Override
     public Collection<SimpleTableSegment> getAllTables() {
-        return getTableFromSelect(getSqlStatement());
-    }
-    
-    private Collection<SimpleTableSegment> getAllTablesFromWhere(final WhereSegment where, final Collection<TableSegment> tableSegments) {
-        Collection<SimpleTableSegment> result = new LinkedList<>();
-        for (AndPredicate each : where.getAndPredicates()) {
-            for (PredicateSegment predicate : each.getPredicates()) {
-                result.addAll(new PredicateExtractor(tableSegments, predicate).extractTables());
-            }
-        }
-        return result;
-    }
-    
-    private Collection<SimpleTableSegment> getAllTablesFromProjections(final ProjectionsSegment projections, final Collection<TableSegment> tableSegments) {
-        Collection<SimpleTableSegment> result = new LinkedList<>();
-        for (ProjectionSegment each : projections.getProjections()) {
-            Optional<SimpleTableSegment> table = getTableSegment(each, tableSegments);
-            table.ifPresent(result::add);
-        }
-        return result;
-    }
-    
-    private Optional<SimpleTableSegment> getTableSegment(final ProjectionSegment each, final Collection<TableSegment> tableSegments) {
-        Optional<OwnerSegment> owner = getTableOwner(each);
-        if (owner.isPresent() && isTable(owner.get(), tableSegments)) {
-            return Optional .of(new SimpleTableSegment(owner.get().getStartIndex(), owner.get().getStopIndex(), owner.get().getIdentifier()));
-        }
-        return Optional.empty();
-    }
-    
-    private Optional<OwnerSegment> getTableOwner(final ProjectionSegment each) {
-        if (each instanceof OwnerAvailable) {
-            return ((OwnerAvailable) each).getOwner();
-        }
-        if (each instanceof ColumnProjectionSegment) {
-            return ((ColumnProjectionSegment) each).getColumn().getOwner();
-        }
-        return Optional.empty();
-    }
-    
-    private Collection<SimpleTableSegment> getAllTablesFromOrderByItems(final Collection<OrderByItemSegment> orderByItems, final Collection<TableSegment> tableSegments) {
-        Collection<SimpleTableSegment> result = new LinkedList<>();
-        for (OrderByItemSegment each : orderByItems) {
-            if (each instanceof ColumnOrderByItemSegment) {
-                Optional<OwnerSegment> owner = ((ColumnOrderByItemSegment) each).getColumn().getOwner();
-                if (owner.isPresent() && isTable(owner.get(), tableSegments)) {
-                    Preconditions.checkState(((ColumnOrderByItemSegment) each).getColumn().getOwner().isPresent());
-                    OwnerSegment segment = ((ColumnOrderByItemSegment) each).getColumn().getOwner().get();
-                    result.add(new SimpleTableSegment(segment.getStartIndex(), segment.getStopIndex(), segment.getIdentifier()));
-                }
-            }
-        }
-        return result;
-    }
-    
-    private boolean isTable(final OwnerSegment owner, final Collection<TableSegment> tables) {
-        for (TableSegment each : tables) {
-            if (owner.getIdentifier().getValue().equals(each.getAlias().orElse(null))) {
-                return false;
-            }
-        }
-        return true;
+        return TableExtractUtils.getTableFromSelect(getSqlStatement());

Review comment:
       What's the difference between `TableExtractUtils.getRealTableFromSelect(getSqlStatement());` and `TableExtractUtils.getTableFromSelect(getSqlStatement());`?
   Besides, can we consider another function name full of description  for `getRealTableFromSelect` ?




----------------------------------------------------------------
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:
users@infra.apache.org