refactor sql parser. improved db2 sql support. bug fixed for issue #2033

This commit is contained in:
wenshao
2017-10-09 15:47:16 +08:00
parent 08cc982f2e
commit f4d3310734
26 changed files with 583 additions and 186 deletions
@@ -19,16 +19,12 @@ import java.util.ArrayList;
import java.util.List;
public abstract class SQLPartitionBy extends SQLObjectImpl {
protected SQLSubPartitionBy subPartitionBy;
protected SQLExpr partitionsCount;
protected boolean linear;
protected List<SQLPartition> partitions = new ArrayList<SQLPartition>();
protected List<SQLName> storeIn = new ArrayList<SQLName>();
protected List<SQLExpr> columns = new ArrayList<SQLExpr>();
public List<SQLPartition> getPartitions() {
return partitions;
@@ -75,6 +71,17 @@ public abstract class SQLPartitionBy extends SQLObjectImpl {
return storeIn;
}
public List<SQLExpr> getColumns() {
return columns;
}
public void addColumn(SQLExpr column) {
if (column != null) {
column.setParent(this);
}
this.columns.add(column);
}
public void cloneTo(SQLPartitionBy x) {
if (subPartitionBy != null) {
x.setSubPartitionBy(subPartitionBy.clone());
@@ -19,22 +19,9 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLPartitionByHash extends SQLPartitionBy {
protected SQLExpr expr;
// for aliyun ads
protected boolean key;
public SQLExpr getExpr() {
return expr;
}
public void setExpr(SQLExpr expr) {
if (expr != null) {
expr.setParent(this);
}
this.expr = expr;
}
public boolean isKey() {
return key;
}
@@ -46,7 +33,6 @@ public class SQLPartitionByHash extends SQLPartitionBy {
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, expr);
acceptChild(visitor, partitionsCount);
acceptChild(visitor, getPartitions());
acceptChild(visitor, subPartitionBy);
@@ -57,12 +43,14 @@ public class SQLPartitionByHash extends SQLPartitionBy {
public SQLPartitionByHash clone() {
SQLPartitionByHash x = new SQLPartitionByHash();
if (expr != null) {
x.setExpr(expr.clone());
}
x.key = key;
for (SQLExpr column : columns) {
SQLExpr c2 = column.clone();
c2.setParent(x);
x.columns.add(c2);
}
return x;
}
}
@@ -21,15 +21,9 @@ import java.util.List;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLPartitionByList extends SQLPartitionBy {
protected SQLExpr expr;
protected List<SQLName> columns = new ArrayList<SQLName>();
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, expr);
acceptChild(visitor, columns);
acceptChild(visitor, partitionsCount);
acceptChild(visitor, getPartitions());
@@ -38,37 +32,11 @@ public class SQLPartitionByList extends SQLPartitionBy {
visitor.endVisit(this);
}
public SQLExpr getExpr() {
return expr;
}
public void setExpr(SQLExpr expr) {
if (expr != null) {
expr.setParent(this);
}
this.expr = expr;
}
public List<SQLName> getColumns() {
return columns;
}
public void addColumn(SQLName column) {
if (column != null) {
column.setParent(this);
}
this.columns.add(column);
}
public SQLPartitionByList clone() {
SQLPartitionByList x = new SQLPartitionByList();
if (expr != null) {
x.setExpr(expr.clone());
}
for (SQLName column : columns) {
SQLName c2 = column.clone();
for (SQLExpr column : columns) {
SQLExpr c2 = column.clone();
c2.setParent(x);
x.columns.add(c2);
}
@@ -21,29 +21,12 @@ import java.util.List;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLPartitionByRange extends SQLPartitionBy {
protected List<SQLName> columns = new ArrayList<SQLName>();
protected SQLExpr interval;
// mysql
protected SQLExpr expr;
public SQLPartitionByRange() {
}
public List<SQLName> getColumns() {
return columns;
}
public void addColumn(SQLName column) {
if (column != null) {
column.setParent(this);
}
this.columns.add(column);
}
public SQLExpr getInterval() {
return interval;
}
@@ -56,22 +39,10 @@ public class SQLPartitionByRange extends SQLPartitionBy {
this.interval = interval;
}
public SQLExpr getExpr() {
return expr;
}
public void setExpr(SQLExpr expr) {
if (expr != null) {
expr.setParent(this);
}
this.expr = expr;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, columns);
acceptChild(visitor, expr);
acceptChild(visitor, interval);
acceptChild(visitor, storeIn);
acceptChild(visitor, partitions);
@@ -82,16 +53,12 @@ public class SQLPartitionByRange extends SQLPartitionBy {
public SQLPartitionByRange clone() {
SQLPartitionByRange x = new SQLPartitionByRange();
if (expr != null) {
x.setExpr(expr.clone());
}
if (interval != null) {
x.setInterval(interval.clone());
}
for (SQLName column : columns) {
SQLName c2 = column.clone();
for (SQLExpr column : columns) {
SQLExpr c2 = column.clone();
c2.setParent(x);
x.columns.add(c2);
}
@@ -39,15 +39,19 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
protected List<SQLTableElement> tableElementList = new ArrayList<SQLTableElement>();
// for postgresql
private SQLExprTableSource inherits;
protected SQLExprTableSource inherits;
protected SQLSelect select;
protected SQLExpr comment;
protected SQLExprTableSource like;
protected SQLExprTableSource like;
protected Boolean compress;
protected Boolean logging;
protected SQLName tablespace;
protected SQLPartitionBy partitioning;
public SQLCreateTableStatement(){
@@ -176,6 +180,45 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
this.like = like;
}
public Boolean getCompress() {
return compress;
}
public void setCompress(Boolean compress) {
this.compress = compress;
}
public Boolean getLogging() {
return logging;
}
public void setLogging(Boolean logging) {
this.logging = logging;
}
public SQLName getTablespace() {
return tablespace;
}
public void setTablespace(SQLName tablespace) {
if (tablespace != null) {
tablespace.setParent(this);
}
this.tablespace = tablespace;
}
public SQLPartitionBy getPartitioning() {
return partitioning;
}
public void setPartitioning(SQLPartitionBy partitioning) {
if (partitioning != null) {
partitioning.setParent(this);
}
this.partitioning = partitioning;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {