mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved SchemaStatVisitor. bug fixed for issue #2509
This commit is contained in:
@@ -2085,9 +2085,7 @@ class SchemaResolveVisitorFactory {
|
||||
SQLExpr expr = selectItem.getExpr();
|
||||
if (expr instanceof SQLAllColumnExpr) {
|
||||
SQLAllColumnExpr allColumnExpr = (SQLAllColumnExpr) expr;
|
||||
if (from instanceof SQLExprTableSource) {
|
||||
allColumnExpr.setResolvedTableSource(from);
|
||||
}
|
||||
allColumnExpr.setResolvedTableSource(from);
|
||||
|
||||
visitor.visit(allColumnExpr);
|
||||
|
||||
|
||||
@@ -1407,43 +1407,61 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
public boolean visit(SQLAllColumnExpr x) {
|
||||
SQLTableSource tableSource = x.getResolvedTableSource();
|
||||
if (tableSource == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
statAllColumn(x, tableSource);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void statAllColumn(SQLAllColumnExpr x, SQLTableSource tableSource) {
|
||||
if (tableSource instanceof SQLExprTableSource) {
|
||||
SQLExprTableSource exprTableSource = (SQLExprTableSource) tableSource;
|
||||
SQLName expr = exprTableSource.getName();
|
||||
statAllColumn(x, (SQLExprTableSource) tableSource);
|
||||
return;
|
||||
}
|
||||
|
||||
SQLCreateTableStatement createStmt = null;
|
||||
if (tableSource instanceof SQLJoinTableSource) {
|
||||
SQLJoinTableSource join = (SQLJoinTableSource) tableSource;
|
||||
statAllColumn(x, join.getLeft());
|
||||
statAllColumn(x, join.getRight());
|
||||
}
|
||||
}
|
||||
|
||||
SchemaObject tableObject = exprTableSource.getSchemaObject();
|
||||
if (tableObject != null) {
|
||||
SQLStatement stmt = tableObject.getStatement();
|
||||
if (stmt instanceof SQLCreateTableStatement) {
|
||||
createStmt = (SQLCreateTableStatement) stmt;
|
||||
}
|
||||
}
|
||||
private void statAllColumn(SQLAllColumnExpr x, SQLExprTableSource tableSource) {
|
||||
SQLExprTableSource exprTableSource = tableSource;
|
||||
SQLName expr = exprTableSource.getName();
|
||||
|
||||
if (createStmt != null
|
||||
&& createStmt.getTableElementList().size() > 0) {
|
||||
SQLName tableName = createStmt.getName();
|
||||
for (SQLTableElement e : createStmt.getTableElementList()) {
|
||||
if (e instanceof SQLColumnDefinition) {
|
||||
SQLColumnDefinition columnDefinition = (SQLColumnDefinition) e;
|
||||
SQLName columnName = columnDefinition.getName();
|
||||
Column column = addColumn(tableName.toString(), columnName.toString());
|
||||
if (isParentSelectItem(x.getParent())) {
|
||||
column.setSelec(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (expr != null) {
|
||||
Column column = addColumn(expr.toString(), "*");
|
||||
if (isParentSelectItem(x.getParent())) {
|
||||
column.setSelec(true);
|
||||
}
|
||||
SQLCreateTableStatement createStmt = null;
|
||||
|
||||
SchemaObject tableObject = exprTableSource.getSchemaObject();
|
||||
if (tableObject != null) {
|
||||
SQLStatement stmt = tableObject.getStatement();
|
||||
if (stmt instanceof SQLCreateTableStatement) {
|
||||
createStmt = (SQLCreateTableStatement) stmt;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
if (createStmt != null
|
||||
&& createStmt.getTableElementList().size() > 0) {
|
||||
SQLName tableName = createStmt.getName();
|
||||
for (SQLTableElement e : createStmt.getTableElementList()) {
|
||||
if (e instanceof SQLColumnDefinition) {
|
||||
SQLColumnDefinition columnDefinition = (SQLColumnDefinition) e;
|
||||
SQLName columnName = columnDefinition.getName();
|
||||
Column column = addColumn(tableName.toString(), columnName.toString());
|
||||
if (isParentSelectItem(x.getParent())) {
|
||||
column.setSelec(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (expr != null) {
|
||||
Column column = addColumn(expr.toString(), "*");
|
||||
if (isParentSelectItem(x.getParent())) {
|
||||
column.setSelec(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<TableStat.Name, TableStat> getTables() {
|
||||
|
||||
Reference in New Issue
Block a user