jingshanglu commented on a change in pull request #5206: Simplify the
SelectStatement
URL:
https://github.com/apache/incubator-shardingsphere/pull/5206#discussion_r410059159
##########
File path:
shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/statement/dml/SelectStatementContext.java
##########
@@ -262,8 +268,86 @@ private boolean isTable(final OwnerSegment owner, final
Collection<SimpleTableSe
return true;
}
+ private boolean isTable(final SimpleTableSegment owner, final
Collection<SimpleTableSegment> tableSegments) {
+ for (SimpleTableSegment each : tableSegments) {
+ String tableName = owner.getTableName().getIdentifier().getValue();
+ if (tableName.equals(each.getAlias().orElse(null)) &&
!tableName.equals(each.getTableName().getIdentifier().getValue())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
@Override
public Optional<WhereSegment> getWhere() {
return getSqlStatement().getWhere();
}
+
+ /**
+ * get tables.
+ *
+ * @param selectStatement SelectStatement.
+ *
+ * @return tables.
+ */
+ public Collection<SimpleTableSegment> getSimpleTableSegments(final
SelectStatement selectStatement) {
+ Collection<SimpleTableSegment> result = getTables(selectStatement);
+ Collection<SimpleTableSegment> tables = new LinkedList<>();
+ for (SimpleTableSegment each : result) {
+ if (isTable(each, result)) {
+ tables.add(each);
+ }
+ }
+ return tables;
+ }
+
+ private Collection<SimpleTableSegment> getTables(final ASTNode astNode) {
Review comment:
What do you mean? @tristaZero
----------------------------------------------------------------
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]
With regards,
Apache Git Services