mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor sql parser.
This commit is contained in:
@@ -32,7 +32,6 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
|
||||
|
||||
protected SQLExpr expr;
|
||||
private List<SQLName> partitions;
|
||||
|
||||
private SchemaObject schemaObject;
|
||||
|
||||
public SQLExprTableSource(){
|
||||
|
||||
@@ -50,7 +50,10 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
protected SQLLimit limit;
|
||||
|
||||
// for oracle
|
||||
protected List<SQLExpr> forUpdateOf;
|
||||
protected List<SQLExpr> forUpdateOf;
|
||||
|
||||
protected List<SQLExpr> distributeBy;
|
||||
protected List<SQLSelectOrderByItem> sortBy;
|
||||
|
||||
public SQLSelectQueryBlock(){
|
||||
|
||||
@@ -308,6 +311,14 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
this.noCycle = noCycle;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getDistributeBy() {
|
||||
return distributeBy;
|
||||
}
|
||||
|
||||
public List<SQLSelectOrderByItem> getSortBy() {
|
||||
return sortBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
@@ -500,7 +511,7 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean selectItemHashAllColumn() {
|
||||
public boolean selectItemHasAllColumn() {
|
||||
for (SQLSelectItem item : this.selectList) {
|
||||
SQLExpr expr = item.getExpr();
|
||||
|
||||
@@ -512,7 +523,7 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
SQLSelect subSelect = ((SQLSubqueryTableSource) from).select;
|
||||
SQLSelectQueryBlock queryBlock = subSelect.getQueryBlock();
|
||||
if (queryBlock != null) {
|
||||
return queryBlock.selectItemHashAllColumn();
|
||||
return queryBlock.selectItemHasAllColumn();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -522,6 +533,23 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
return false;
|
||||
}
|
||||
|
||||
public SQLSelectItem findAllColumnSelectItem() {
|
||||
SQLSelectItem allColumnItem = null;
|
||||
for (SQLSelectItem item : this.selectList) {
|
||||
SQLExpr expr = item.getExpr();
|
||||
|
||||
boolean allColumn = expr instanceof SQLAllColumnExpr
|
||||
|| (expr instanceof SQLPropertyExpr && ((SQLPropertyExpr) expr).getName().equals("*"));
|
||||
|
||||
if (allColumnItem != null) {
|
||||
return null; // duplicateAllColumn
|
||||
}
|
||||
allColumnItem = item;
|
||||
}
|
||||
|
||||
return allColumnItem;
|
||||
}
|
||||
|
||||
public SQLColumnDefinition findColumn(String columnName) {
|
||||
if (from == null) {
|
||||
return null;
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLUpdateStatement extends SQLStatementImpl implements SQLReplaceable {
|
||||
protected SQLWithSubqueryClause with; // for pg
|
||||
|
||||
protected final List<SQLUpdateSetItem> items = new ArrayList<SQLUpdateSetItem>();
|
||||
protected SQLExpr where;
|
||||
@@ -161,4 +162,15 @@ public class SQLUpdateStatement extends SQLStatementImpl implements SQLReplaceab
|
||||
}
|
||||
this.orderBy = orderBy;
|
||||
}
|
||||
|
||||
public SQLWithSubqueryClause getWith() {
|
||||
return with;
|
||||
}
|
||||
|
||||
public void setWith(SQLWithSubqueryClause with) {
|
||||
if (with != null) {
|
||||
with.setParent(this);
|
||||
}
|
||||
this.with = with;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +132,15 @@ public class SQLWithSubqueryClause extends SQLObjectImpl {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
if (subQuery != null) {
|
||||
SQLSelectQueryBlock queryBlock = subQuery.getFirstQueryBlock();
|
||||
if (queryBlock != null) {
|
||||
if (queryBlock.findSelectItem(columnNameHash) != null) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user