mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
sql parser support mysql 5.7 & oceanbase 1.0
This commit is contained in:
@@ -18,17 +18,28 @@ package com.alibaba.druid.sql.ast.statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLAlterTableAddPartition extends SQLObjectImpl implements SQLAlterTableItem {
|
||||
|
||||
private boolean ifNotExists = false;
|
||||
private boolean ifNotExists = false;
|
||||
|
||||
private final List<SQLAssignItem> partition = new ArrayList<SQLAssignItem>(4);
|
||||
private final List<SQLObject> partitions = new ArrayList<SQLObject>(4);
|
||||
|
||||
public List<SQLAssignItem> getPartition() {
|
||||
return partition;
|
||||
private SQLExpr partitionCount;
|
||||
|
||||
public List<SQLObject> getPartitions() {
|
||||
return partitions;
|
||||
}
|
||||
|
||||
public void addPartition(SQLObject partition) {
|
||||
if (partition != null) {
|
||||
partition.setParent(this);
|
||||
}
|
||||
this.partitions.add(partition);
|
||||
}
|
||||
|
||||
public boolean isIfNotExists() {
|
||||
@@ -39,10 +50,21 @@ public class SQLAlterTableAddPartition extends SQLObjectImpl implements SQLAlter
|
||||
this.ifNotExists = ifNotExists;
|
||||
}
|
||||
|
||||
public SQLExpr getPartitionCount() {
|
||||
return partitionCount;
|
||||
}
|
||||
|
||||
public void setPartitionCount(SQLExpr partitionCount) {
|
||||
if (partitionCount != null) {
|
||||
partitionCount.setParent(this);
|
||||
}
|
||||
this.partitionCount = partitionCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, partition);
|
||||
acceptChild(visitor, partitions);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 1999-2101 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLAlterTableCoalescePartition extends SQLObjectImpl implements SQLAlterTableItem {
|
||||
|
||||
private SQLExpr count;
|
||||
|
||||
public SQLExpr getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(SQLExpr count) {
|
||||
if (count != null) {
|
||||
count.setParent(this);
|
||||
}
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, count);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.alibaba.druid.sql.ast.statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
@@ -27,10 +28,17 @@ public class SQLAlterTableDropPartition extends SQLObjectImpl implements SQLAlte
|
||||
|
||||
private boolean purge;
|
||||
|
||||
private final List<SQLAssignItem> partition = new ArrayList<SQLAssignItem>(4);
|
||||
private final List<SQLObject> partitions = new ArrayList<SQLObject>(4);
|
||||
|
||||
public List<SQLAssignItem> getPartition() {
|
||||
return partition;
|
||||
public List<SQLObject> getPartitions() {
|
||||
return partitions;
|
||||
}
|
||||
|
||||
public void addPartition(SQLObject partition) {
|
||||
if (partition != null) {
|
||||
partition.setParent(this);
|
||||
}
|
||||
this.partitions.add(partition);
|
||||
}
|
||||
|
||||
public boolean isIfNotExists() {
|
||||
@@ -52,7 +60,7 @@ public class SQLAlterTableDropPartition extends SQLObjectImpl implements SQLAlte
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, partition);
|
||||
acceptChild(visitor, partitions);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 1999-2101 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLAlterTableReOrganizePartition extends SQLObjectImpl implements SQLAlterTableItem {
|
||||
|
||||
private final List<SQLName> names = new ArrayList<SQLName>();
|
||||
|
||||
private final List<SQLObject> partitions = new ArrayList<SQLObject>(4);
|
||||
|
||||
public List<SQLObject> getPartitions() {
|
||||
return partitions;
|
||||
}
|
||||
|
||||
public void addPartition(SQLObject partition) {
|
||||
if (partition != null) {
|
||||
partition.setParent(this);
|
||||
}
|
||||
this.partitions.add(partition);
|
||||
}
|
||||
|
||||
public List<SQLName> getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, partitions);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,19 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLExprTableSource extends SQLTableSourceImpl {
|
||||
|
||||
protected SQLExpr expr;
|
||||
|
||||
private List<SQLName> partitions;
|
||||
|
||||
public SQLExprTableSource(){
|
||||
|
||||
}
|
||||
@@ -29,7 +35,7 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
|
||||
public SQLExprTableSource(SQLExpr expr){
|
||||
this(expr, null);
|
||||
}
|
||||
|
||||
|
||||
public SQLExprTableSource(SQLExpr expr, String alias){
|
||||
this.setExpr(expr);
|
||||
this.setAlias(alias);
|
||||
@@ -46,6 +52,32 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
public List<SQLName> getPartitions() {
|
||||
if (this.partitions == null) {
|
||||
this.partitions = new ArrayList<SQLName>(2);
|
||||
}
|
||||
|
||||
return partitions;
|
||||
}
|
||||
|
||||
public int getPartitionSize() {
|
||||
if (this.partitions == null) {
|
||||
return 0;
|
||||
}
|
||||
return this.partitions.size();
|
||||
}
|
||||
|
||||
public void addPartition(SQLName partition) {
|
||||
if (partition != null) {
|
||||
partition.setParent(this);
|
||||
}
|
||||
|
||||
if (this.partitions == null) {
|
||||
this.partitions = new ArrayList<SQLName>(2);
|
||||
}
|
||||
this.partitions.add(partition);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
|
||||
+24
-85
@@ -24,11 +24,11 @@ import com.alibaba.druid.sql.ast.SQLPartitionBy;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionByHash;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionByList;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionByRange;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionValue;
|
||||
import com.alibaba.druid.sql.ast.SQLSubPartitionBy;
|
||||
import com.alibaba.druid.sql.ast.SQLSubPartitionByHash;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNumberExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCheck;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
@@ -406,7 +406,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("PARTITION")) {
|
||||
if (lexer.token() == Token.PARTITION) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
|
||||
@@ -427,13 +427,15 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
}
|
||||
|
||||
accept(Token.LPAREN);
|
||||
for (;;) {
|
||||
clause.addColumn(this.exprParser.name());
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
if (lexer.token() != Token.RPAREN) {
|
||||
for (;;) {
|
||||
clause.addColumn(this.exprParser.name());
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
|
||||
@@ -497,79 +499,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
for (;;) {
|
||||
acceptIdentifier("PARTITION");
|
||||
|
||||
SQLPartition partitionDef = new SQLPartition();
|
||||
|
||||
partitionDef.setName(this.exprParser.name());
|
||||
|
||||
|
||||
SQLPartitionValue values = parsePartitionValues();
|
||||
if (values != null) {
|
||||
partitionDef.setValues(values);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
boolean storage = false;
|
||||
if (identifierEquals("DATA")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("DIRECTORY");
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
partitionDef.setDataDirectory(this.exprParser.expr());
|
||||
} else if (lexer.token() == Token.TABLESPACE) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLName tableSpace = this.exprParser.name();
|
||||
partitionDef.setTableSpace(tableSpace);
|
||||
} else if (lexer.token() == Token.INDEX) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("DIRECTORY");
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
partitionDef.setIndexDirectory(this.exprParser.expr());
|
||||
} else if (identifierEquals("MAX_ROWS")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLExpr maxRows = this.exprParser.primary();
|
||||
partitionDef.setMaxRows(maxRows);
|
||||
} else if (identifierEquals("MIN_ROWS")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLExpr minRows = this.exprParser.primary();
|
||||
partitionDef.setMaxRows(minRows);
|
||||
} else if (identifierEquals("ENGINE") || //
|
||||
(storage = (lexer.token() == Token.STORAGE || identifierEquals("STORAGE")))) {
|
||||
if (storage) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
acceptIdentifier("ENGINE");
|
||||
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
SQLName engine = this.exprParser.name();
|
||||
partitionDef.setEngine(engine);
|
||||
} else if (lexer.token() == Token.COMMENT) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLExpr comment = this.exprParser.primary();
|
||||
partitionDef.setComment(comment);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
SQLPartition partitionDef = this.getExprParser().parsePartition();
|
||||
|
||||
partitionClause.addPartition(partitionDef);
|
||||
|
||||
@@ -610,9 +540,11 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected SQLPartitionByRange partitionByRange() {
|
||||
acceptIdentifier("RANGE");
|
||||
|
||||
|
||||
SQLPartitionByRange clause = new SQLPartitionByRange();
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
@@ -639,12 +571,11 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (identifierEquals("PARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLIntegerExpr countExpr = new SQLIntegerExpr(lexer.integerValue());
|
||||
accept(Token.LITERAL_INT);
|
||||
SQLIntegerExpr countExpr = this.exprParser.integerExpr();
|
||||
clause.setPartitionsCount(countExpr);
|
||||
}
|
||||
|
||||
if (identifierEquals("PARTITION")) {
|
||||
if (lexer.token() == Token.PARTITION) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (identifierEquals("NUM")) {
|
||||
@@ -757,6 +688,14 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
|
||||
subPartitionByClause.getOptions().add(option);
|
||||
}
|
||||
|
||||
if (identifierEquals("SUBPARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
Number intValue = lexer.integerValue();
|
||||
SQLNumberExpr numExpr = new SQLNumberExpr(intValue);
|
||||
subPartitionByClause.setSubPartitionsCount(numExpr);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (subPartitionByClause != null) {
|
||||
subPartitionByClause.setLinear(linear);
|
||||
|
||||
@@ -20,6 +20,9 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderingSpecification;
|
||||
import com.alibaba.druid.sql.ast.SQLPartition;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionValue;
|
||||
import com.alibaba.druid.sql.ast.SQLSubPartition;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
@@ -553,7 +556,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("PARTITION")) {
|
||||
if (lexer.token() == Token.PARTITION) {
|
||||
throw new ParserException("syntax error " + lexer.token() + " " + lexer.stringVal());
|
||||
}
|
||||
|
||||
@@ -894,4 +897,102 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public SQLPartition parsePartition() {
|
||||
accept(Token.PARTITION);
|
||||
|
||||
SQLPartition partitionDef = new SQLPartition();
|
||||
|
||||
partitionDef.setName(this.name());
|
||||
|
||||
SQLPartitionValue values = this.parsePartitionValues();
|
||||
if (values != null) {
|
||||
partitionDef.setValues(values);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
boolean storage = false;
|
||||
if (identifierEquals("DATA")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("DIRECTORY");
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
partitionDef.setDataDirectory(this.expr());
|
||||
} else if (lexer.token() == Token.TABLESPACE) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLName tableSpace = this.name();
|
||||
partitionDef.setTableSpace(tableSpace);
|
||||
} else if (lexer.token() == Token.INDEX) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("DIRECTORY");
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
partitionDef.setIndexDirectory(this.expr());
|
||||
} else if (identifierEquals("MAX_ROWS")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLExpr maxRows = this.primary();
|
||||
partitionDef.setMaxRows(maxRows);
|
||||
} else if (identifierEquals("MIN_ROWS")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLExpr minRows = this.primary();
|
||||
partitionDef.setMaxRows(minRows);
|
||||
} else if (identifierEquals("ENGINE") || //
|
||||
(storage = (lexer.token() == Token.STORAGE || identifierEquals("STORAGE")))) {
|
||||
if (storage) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
acceptIdentifier("ENGINE");
|
||||
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
SQLName engine = this.name();
|
||||
partitionDef.setEngine(engine);
|
||||
} else if (lexer.token() == Token.COMMENT) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLExpr comment = this.primary();
|
||||
partitionDef.setComment(comment);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
|
||||
for (;;) {
|
||||
acceptIdentifier("SUBPARTITION");
|
||||
|
||||
SQLName subPartitionName = this.name();
|
||||
SQLSubPartition subPartition = new SQLSubPartition();
|
||||
subPartition.setName(subPartitionName);
|
||||
|
||||
partitionDef.addSubPartition(subPartition);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
return partitionDef;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,9 @@ public class MySqlLexer extends Lexer {
|
||||
map.put("ROW", Token.ROW);
|
||||
map.put("BEGIN", Token.BEGIN);
|
||||
map.put("END", Token.END);
|
||||
|
||||
// for oceanbase & mysql 5.7
|
||||
map.put("PARTITION", Token.PARTITION);
|
||||
|
||||
DEFAULT_MYSQL_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
@@ -342,6 +342,13 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
parseIndexHint(hint);
|
||||
tableSource.getHints().add(hint);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.PARTITION) {
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
this.exprParser.names(((SQLExprTableSource) tableSource).getPartitions(), tableSource);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
return super.parseTableSourceRest(tableSource);
|
||||
}
|
||||
|
||||
+648
-621
File diff suppressed because it is too large
Load Diff
@@ -2575,6 +2575,12 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print(' ');
|
||||
x.getHints().get(i).accept(this);
|
||||
}
|
||||
|
||||
if (x.getPartitionSize() > 0) {
|
||||
print0(ucase ? " PARTITION (" : " partition (");
|
||||
printlnAndAccept(x.getPartitions(), ", ");
|
||||
print(')');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
-1
@@ -20,7 +20,6 @@ import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLHint;
|
||||
import com.alibaba.druid.sql.ast.SQLPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertInto;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelect;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.OracleSQLObject;
|
||||
|
||||
+39
-35
@@ -263,39 +263,9 @@ public class OracleCreateTableParser extends SQLCreateTableParser {
|
||||
accept(Token.LPAREN);
|
||||
|
||||
for (;;) {
|
||||
acceptIdentifier("PARTITION");
|
||||
SQLPartition range = new SQLPartition();
|
||||
range.setName(this.exprParser.name());
|
||||
SQLPartition partition = parsePartition();
|
||||
|
||||
SQLPartitionValue values = parsePartitionValues();
|
||||
if (values != null) {
|
||||
range.setValues(values);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
|
||||
for (;;) {
|
||||
SQLSubPartition subPartition = parseSubPartition();
|
||||
|
||||
range.addSubPartition(subPartition);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
accept(Token.RPAREN);
|
||||
} else if (identifierEquals("SUBPARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
SQLExpr subPartitionsCount = this.exprParser.primary();
|
||||
range.setSubPartitionsCount(subPartitionsCount);
|
||||
}
|
||||
|
||||
clause.addPartition(range);
|
||||
clause.addPartition(partition);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
@@ -308,6 +278,41 @@ public class OracleCreateTableParser extends SQLCreateTableParser {
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
protected SQLPartition parsePartition() {
|
||||
acceptIdentifier("PARTITION");
|
||||
SQLPartition partition = new SQLPartition();
|
||||
partition.setName(this.exprParser.name());
|
||||
|
||||
SQLPartitionValue values = this.exprParser.parsePartitionValues();
|
||||
if (values != null) {
|
||||
partition.setValues(values);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
|
||||
for (;;) {
|
||||
SQLSubPartition subPartition = parseSubPartition();
|
||||
|
||||
partition.addSubPartition(subPartition);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
accept(Token.RPAREN);
|
||||
} else if (identifierEquals("SUBPARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
SQLExpr subPartitionsCount = this.exprParser.primary();
|
||||
partition.setSubPartitionsCount(subPartitionsCount);
|
||||
}
|
||||
return partition;
|
||||
}
|
||||
|
||||
protected SQLSubPartition parseSubPartition() {
|
||||
acceptIdentifier("SUBPARTITION");
|
||||
|
||||
@@ -315,7 +320,7 @@ public class OracleCreateTableParser extends SQLCreateTableParser {
|
||||
SQLName name = this.exprParser.name();
|
||||
subPartition.setName(name);
|
||||
|
||||
SQLPartitionValue values = parsePartitionValues();
|
||||
SQLPartitionValue values = this.exprParser.parsePartitionValues();
|
||||
if (values != null) {
|
||||
subPartition.setValues(values);
|
||||
}
|
||||
@@ -327,8 +332,7 @@ public class OracleCreateTableParser extends SQLCreateTableParser {
|
||||
if (identifierEquals("PARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLIntegerExpr countExpr = new SQLIntegerExpr(lexer.integerValue());
|
||||
accept(Token.LITERAL_INT);
|
||||
SQLIntegerExpr countExpr = this.exprParser.integerExpr();
|
||||
clause.setPartitionsCount(countExpr);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
package com.alibaba.druid.sql.parser;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionValue;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
@@ -129,44 +127,4 @@ public class SQLCreateTableParser extends SQLDDLParser {
|
||||
return new SQLCreateTableStatement(getDbType());
|
||||
}
|
||||
|
||||
protected SQLPartitionValue parsePartitionValues() {
|
||||
if (lexer.token() != Token.VALUES) {
|
||||
return null;
|
||||
}
|
||||
lexer.nextToken();
|
||||
|
||||
SQLPartitionValue values = null;
|
||||
|
||||
if (lexer.token() == Token.IN) {
|
||||
lexer.nextToken();
|
||||
values = new SQLPartitionValue(SQLPartitionValue.Operator.In);
|
||||
|
||||
accept(Token.LPAREN);
|
||||
this.exprParser.exprList(values.getItems(), values);
|
||||
accept(Token.RPAREN);
|
||||
} else if (identifierEquals("LESS")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("THAN");
|
||||
|
||||
values = new SQLPartitionValue(SQLPartitionValue.Operator.LessThan);
|
||||
|
||||
if (identifierEquals("MAXVALUE")) {
|
||||
SQLIdentifierExpr maxValue = new SQLIdentifierExpr(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
maxValue.setParent(values);
|
||||
values.addItem(maxValue);
|
||||
} else {
|
||||
accept(Token.LPAREN);
|
||||
this.exprParser.exprList(values.getItems(), values);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
} else if (lexer.token() == Token.LPAREN) {
|
||||
values = new SQLPartitionValue(SQLPartitionValue.Operator.List);
|
||||
lexer.nextToken();
|
||||
this.exprParser.exprList(values.getItems(), values);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderingSpecification;
|
||||
import com.alibaba.druid.sql.ast.SQLOver;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionValue;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateOption;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr;
|
||||
@@ -185,6 +186,12 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
public SQLIntegerExpr integerExpr() {
|
||||
SQLIntegerExpr intExpr = new SQLIntegerExpr(lexer.integerValue());
|
||||
accept(Token.LITERAL_INT);
|
||||
return intExpr;
|
||||
}
|
||||
|
||||
public SQLExpr primary() {
|
||||
List<String> beforeComments = null;
|
||||
@@ -1902,4 +1909,45 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
public SQLPartitionValue parsePartitionValues() {
|
||||
if (lexer.token() != Token.VALUES) {
|
||||
return null;
|
||||
}
|
||||
lexer.nextToken();
|
||||
|
||||
SQLPartitionValue values = null;
|
||||
|
||||
if (lexer.token() == Token.IN) {
|
||||
lexer.nextToken();
|
||||
values = new SQLPartitionValue(SQLPartitionValue.Operator.In);
|
||||
|
||||
accept(Token.LPAREN);
|
||||
this.exprList(values.getItems(), values);
|
||||
accept(Token.RPAREN);
|
||||
} else if (identifierEquals("LESS")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("THAN");
|
||||
|
||||
values = new SQLPartitionValue(SQLPartitionValue.Operator.LessThan);
|
||||
|
||||
if (identifierEquals("MAXVALUE")) {
|
||||
SQLIdentifierExpr maxValue = new SQLIdentifierExpr(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
maxValue.setParent(values);
|
||||
values.addItem(maxValue);
|
||||
} else {
|
||||
accept(Token.LPAREN);
|
||||
this.exprList(values.getItems(), values);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
} else if (lexer.token() == Token.LPAREN) {
|
||||
values = new SQLPartitionValue(SQLPartitionValue.Operator.List);
|
||||
lexer.nextToken();
|
||||
this.exprList(values.getItems(), values);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,9 +102,9 @@ public class SQLStatementParser extends SQLParser {
|
||||
|
||||
protected SQLExprParser exprParser;
|
||||
|
||||
protected boolean parseCompleteValues = true;
|
||||
protected boolean parseCompleteValues = true;
|
||||
|
||||
protected int parseValuesSize = 3;
|
||||
protected int parseValuesSize = 3;
|
||||
|
||||
public SQLStatementParser(String sql){
|
||||
this(sql, null);
|
||||
@@ -165,7 +165,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
int line0 = lexer.getLine();
|
||||
lexer.nextToken();
|
||||
int line1 = lexer.getLine();
|
||||
|
||||
|
||||
if (lexer.isKeepComments() && statementList.size() > 0) {
|
||||
SQLStatement stmt = statementList.get(statementList.size() - 1);
|
||||
if (line1 - line0 <= 1) {
|
||||
@@ -223,13 +223,13 @@ public class SQLStatementParser extends SQLParser {
|
||||
if (lexer.isKeepComments() && lexer.hasComment()) {
|
||||
beforeComments = lexer.readAndResetComments();
|
||||
}
|
||||
|
||||
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.TABLE || identifierEquals("TEMPORARY")) {
|
||||
|
||||
SQLDropTableStatement stmt = parseDropTable(false);
|
||||
|
||||
|
||||
if (beforeComments != null) {
|
||||
stmt.addBeforeComment(beforeComments);
|
||||
}
|
||||
@@ -241,7 +241,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
if (beforeComments != null) {
|
||||
stmt.addBeforeComment(beforeComments);
|
||||
}
|
||||
|
||||
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
} else if (lexer.token() == Token.INDEX) {
|
||||
@@ -249,61 +249,61 @@ public class SQLStatementParser extends SQLParser {
|
||||
if (beforeComments != null) {
|
||||
stmt.addBeforeComment(beforeComments);
|
||||
}
|
||||
|
||||
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
} else if (lexer.token() == Token.VIEW) {
|
||||
SQLStatement stmt = parseDropView(false);
|
||||
|
||||
|
||||
if (beforeComments != null) {
|
||||
stmt.addBeforeComment(beforeComments);
|
||||
}
|
||||
|
||||
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
} else if (lexer.token() == Token.TRIGGER) {
|
||||
SQLStatement stmt = parseDropTrigger(false);
|
||||
|
||||
|
||||
if (beforeComments != null) {
|
||||
stmt.addBeforeComment(beforeComments);
|
||||
}
|
||||
|
||||
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
} else if (lexer.token() == Token.DATABASE) {
|
||||
SQLStatement stmt = parseDropDatabase(false);
|
||||
|
||||
|
||||
if (beforeComments != null) {
|
||||
stmt.addBeforeComment(beforeComments);
|
||||
}
|
||||
|
||||
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
} else if (lexer.token() == Token.FUNCTION) {
|
||||
SQLStatement stmt = parseDropFunction(false);
|
||||
|
||||
|
||||
if (beforeComments != null) {
|
||||
stmt.addBeforeComment(beforeComments);
|
||||
}
|
||||
|
||||
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
} else if (lexer.token() == Token.TABLESPACE) {
|
||||
SQLStatement stmt = parseDropTablespace(false);
|
||||
|
||||
|
||||
if (beforeComments != null) {
|
||||
stmt.addBeforeComment(beforeComments);
|
||||
}
|
||||
|
||||
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
} else if (lexer.token() == Token.PROCEDURE) {
|
||||
SQLStatement stmt = parseDropProcedure(false);
|
||||
|
||||
|
||||
if (beforeComments != null) {
|
||||
stmt.addBeforeComment(beforeComments);
|
||||
}
|
||||
|
||||
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
} else {
|
||||
@@ -862,7 +862,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
|
||||
accept(Token.LPAREN);
|
||||
|
||||
parseAssignItems(addPartition.getPartition(), addPartition);
|
||||
parseAssignItems(addPartition.getPartitions(), addPartition);
|
||||
|
||||
accept(Token.RPAREN);
|
||||
|
||||
@@ -928,7 +928,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
stmt.addItem(parseAlterTableRename());
|
||||
} else if (lexer.token() == Token.SET) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
if (lexer.token() == Token.COMMENT) {
|
||||
lexer.nextToken();
|
||||
SQLAlterTableSetComment setComment = new SQLAlterTableSetComment();
|
||||
@@ -952,43 +952,43 @@ public class SQLStatementParser extends SQLParser {
|
||||
parseAssignItems(renamePartition.getPartition(), renamePartition);
|
||||
|
||||
accept(Token.RPAREN);
|
||||
|
||||
|
||||
if (lexer.token() == Token.ENABLE) {
|
||||
lexer.nextToken();
|
||||
if(identifierEquals("LIFECYCLE")) {
|
||||
if (identifierEquals("LIFECYCLE")) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
|
||||
SQLAlterTableEnableLifecycle enableLifeCycle = new SQLAlterTableEnableLifecycle();
|
||||
for (SQLAssignItem condition : renamePartition.getPartition()) {
|
||||
enableLifeCycle.getPartition().add(condition);
|
||||
condition.setParent(enableLifeCycle);
|
||||
}
|
||||
stmt.addItem(enableLifeCycle);
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (lexer.token() == Token.DISABLE) {
|
||||
lexer.nextToken();
|
||||
if(identifierEquals("LIFECYCLE")) {
|
||||
if (identifierEquals("LIFECYCLE")) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
|
||||
SQLAlterTableDisableLifecycle disableLifeCycle = new SQLAlterTableDisableLifecycle();
|
||||
for (SQLAssignItem condition : renamePartition.getPartition()) {
|
||||
disableLifeCycle.getPartition().add(condition);
|
||||
condition.setParent(disableLifeCycle);
|
||||
}
|
||||
stmt.addItem(disableLifeCycle);
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
acceptIdentifier("RENAME");
|
||||
accept(Token.TO);
|
||||
accept(Token.PARTITION);
|
||||
|
||||
|
||||
accept(Token.LPAREN);
|
||||
|
||||
parseAssignItems(renamePartition.getTo(), renamePartition);
|
||||
@@ -996,18 +996,18 @@ public class SQLStatementParser extends SQLParser {
|
||||
accept(Token.RPAREN);
|
||||
|
||||
stmt.addItem(renamePartition);
|
||||
} else if(identifierEquals("TOUCH")) {
|
||||
} else if (identifierEquals("TOUCH")) {
|
||||
lexer.nextToken();
|
||||
SQLAlterTableTouch item = new SQLAlterTableTouch();
|
||||
|
||||
|
||||
if (lexer.token() == Token.PARTITION) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
accept(Token.LPAREN);
|
||||
parseAssignItems(item.getPartition(), item);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
|
||||
stmt.addItem(item);
|
||||
} else {
|
||||
break;
|
||||
@@ -1107,14 +1107,24 @@ public class SQLStatementParser extends SQLParser {
|
||||
|
||||
stmt.addItem(item);
|
||||
} else if (lexer.token() == Token.PARTITION) {
|
||||
lexer.nextToken();
|
||||
SQLAlterTableDropPartition dropPartition = new SQLAlterTableDropPartition();
|
||||
SQLAlterTableDropPartition dropPartition = parseAlterTableDropPartition(ifNotExists);
|
||||
|
||||
dropPartition.setIfNotExists(ifNotExists);
|
||||
stmt.addItem(dropPartition);
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
}
|
||||
}
|
||||
|
||||
protected SQLAlterTableDropPartition parseAlterTableDropPartition(boolean ifNotExists) {
|
||||
lexer.nextToken();
|
||||
SQLAlterTableDropPartition dropPartition = new SQLAlterTableDropPartition();
|
||||
|
||||
dropPartition.setIfNotExists(ifNotExists);
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
accept(Token.LPAREN);
|
||||
|
||||
parseAssignItems(dropPartition.getPartition(), dropPartition);
|
||||
parseAssignItems(dropPartition.getPartitions(), dropPartition);
|
||||
|
||||
accept(Token.RPAREN);
|
||||
|
||||
@@ -1122,11 +1132,13 @@ public class SQLStatementParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
dropPartition.setPurge(true);
|
||||
}
|
||||
|
||||
stmt.addItem(dropPartition);
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
SQLName partition = this.exprParser.name();
|
||||
dropPartition.addPartition(partition);
|
||||
}
|
||||
|
||||
|
||||
return dropPartition;
|
||||
}
|
||||
|
||||
public SQLStatement parseRename() {
|
||||
@@ -1306,15 +1318,15 @@ public class SQLStatementParser extends SQLParser {
|
||||
|
||||
protected SQLDropTableSpaceStatement parseDropTablespace(boolean acceptDrop) {
|
||||
SQLDropTableSpaceStatement stmt = new SQLDropTableSpaceStatement(getDbType());
|
||||
|
||||
|
||||
if (lexer.isKeepComments() && lexer.hasComment()) {
|
||||
stmt.addBeforeComment(lexer.readAndResetComments());
|
||||
}
|
||||
|
||||
|
||||
if (acceptDrop) {
|
||||
accept(Token.DROP);
|
||||
}
|
||||
|
||||
|
||||
accept(Token.TABLESPACE);
|
||||
|
||||
if (lexer.token() == Token.IF) {
|
||||
@@ -1549,7 +1561,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public void parseAssignItems(List<SQLAssignItem> items, SQLObject parent) {
|
||||
public void parseAssignItems(List<? super SQLAssignItem> items, SQLObject parent) {
|
||||
for (;;) {
|
||||
SQLAssignItem item = exprParser.parseAssignItem();
|
||||
item.setParent(parent);
|
||||
@@ -2009,22 +2021,23 @@ public class SQLStatementParser extends SQLParser {
|
||||
accept(Token.RPAREN);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* parse cursor open statement
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public SQLOpenStatement parseOpen() {
|
||||
SQLOpenStatement stmt=new SQLOpenStatement();
|
||||
SQLOpenStatement stmt = new SQLOpenStatement();
|
||||
accept(Token.OPEN);
|
||||
stmt.setCursorName(exprParser.name().getSimpleName());
|
||||
accept(Token.SEMI);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
public SQLFetchStatement parseFetch() {
|
||||
accept(Token.FETCH);
|
||||
|
||||
|
||||
SQLFetchStatement stmt = new SQLFetchStatement();
|
||||
stmt.setCursorName(this.exprParser.name());
|
||||
accept(Token.INTO);
|
||||
@@ -2037,12 +2050,12 @@ public class SQLStatementParser extends SQLParser {
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
public SQLStatement parseClose() {
|
||||
SQLCloseStatement stmt=new SQLCloseStatement();
|
||||
SQLCloseStatement stmt = new SQLCloseStatement();
|
||||
accept(Token.CLOSE);
|
||||
stmt.setCursorName(exprParser.name().getSimpleName());
|
||||
accept(Token.SEMI);
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.alibaba.druid.sql.ast.SQLCommentHint;
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLDeclareItem;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.ast.SQLOver;
|
||||
@@ -86,6 +87,7 @@ import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAlterColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableCoalescePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableConvertCharSet;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableKeys;
|
||||
@@ -101,6 +103,7 @@ import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableKeys;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableLifecycle;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableReOrganizePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRename;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRenameColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRenamePartition;
|
||||
@@ -272,7 +275,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
public void print(String text) {
|
||||
print0(text);
|
||||
}
|
||||
|
||||
|
||||
protected void print0(String text) {
|
||||
try {
|
||||
this.appender.append(text);
|
||||
@@ -343,7 +346,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print(text);
|
||||
println();
|
||||
}
|
||||
|
||||
|
||||
protected void println0(String text) {
|
||||
print0(text);
|
||||
println();
|
||||
@@ -392,29 +395,29 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
for (int i = groupList.size() - 1; i >= 0; --i) {
|
||||
SQLExpr item = groupList.get(i);
|
||||
|
||||
|
||||
if (relational) {
|
||||
if (isPrettyFormat() && item.hasBeforeComment()) {
|
||||
printlnComments(item.getBeforeCommentsDirect());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isPrettyFormat() && item.hasBeforeComment()) {
|
||||
printlnComments(item.getBeforeCommentsDirect());
|
||||
}
|
||||
|
||||
|
||||
visitBinaryLeft(item, x.getOperator());
|
||||
|
||||
if (isPrettyFormat() && item.hasAfterComment()) {
|
||||
print(' ');
|
||||
printComment(item.getAfterCommentsDirect(), "\n");
|
||||
}
|
||||
|
||||
|
||||
if (i != groupList.size() - 1 && isPrettyFormat() && item.getParent().hasAfterComment()) {
|
||||
print(' ');
|
||||
printComment(item.getParent().getAfterCommentsDirect(), "\n");
|
||||
}
|
||||
|
||||
|
||||
if (relational) {
|
||||
println();
|
||||
} else {
|
||||
@@ -437,7 +440,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
if (isPrettyFormat() && x.getRight().hasBeforeComment()) {
|
||||
printlnComments(x.getRight().getBeforeCommentsDirect());
|
||||
}
|
||||
|
||||
|
||||
if (x.getRight() instanceof SQLBinaryOpExpr) {
|
||||
SQLBinaryOpExpr right = (SQLBinaryOpExpr) x.getRight();
|
||||
boolean rightRational = right.getOperator() == SQLBinaryOperator.BooleanAnd
|
||||
@@ -461,7 +464,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
} else {
|
||||
x.getRight().accept(this);
|
||||
}
|
||||
|
||||
|
||||
if (x.getRight().hasAfterComment() && isPrettyFormat()) {
|
||||
print(' ');
|
||||
printlnComments(x.getRight().getAfterCommentsDirect());
|
||||
@@ -587,7 +590,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
|
||||
final List<SQLExpr> list = x.getTargetList();
|
||||
|
||||
|
||||
boolean printLn = false;
|
||||
if (list.size() > 5) {
|
||||
printLn = true;
|
||||
@@ -598,7 +601,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (printLn) {
|
||||
incrementIndent();
|
||||
println();
|
||||
@@ -634,7 +637,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print(')');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected void printFunctionName(String name) {
|
||||
print0(name);
|
||||
}
|
||||
@@ -764,7 +767,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
for (int i = 0; i < itemSize; ++i) {
|
||||
if (i != 0) {
|
||||
if (groupItemSingleLine) {
|
||||
println(", ");
|
||||
println(", ");
|
||||
} else {
|
||||
print(", ");
|
||||
}
|
||||
@@ -779,15 +782,15 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print0(ucase ? "HAVING " : "having ");
|
||||
x.getHaving().accept(this);
|
||||
}
|
||||
|
||||
|
||||
if (x.isWithRollUp()) {
|
||||
print0(ucase ? " WITH ROLLUP" : " with rollup");
|
||||
}
|
||||
|
||||
|
||||
if (x.isWithCube()) {
|
||||
print0(ucase ? " WITH CUBE" : " with cube");
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -817,7 +820,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
if (isPrettyFormat() && x.hasBeforeComment()) {
|
||||
printComment(x.getBeforeCommentsDirect(), "\n");
|
||||
}
|
||||
|
||||
|
||||
print0(ucase ? "SELECT " : "select ");
|
||||
|
||||
if (SQLSetQuantifier.ALL == x.getDistionOption()) {
|
||||
@@ -876,7 +879,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
if (x.isSibings()) {
|
||||
print0(ucase ? "ORDER SIBLINGS BY " : "order siblings by ");
|
||||
} else {
|
||||
print0(ucase ? "ORDER BY " : "order by ");
|
||||
print0(ucase ? "ORDER BY " : "order by ");
|
||||
}
|
||||
|
||||
printAndAccept(x.getItems(), ", ");
|
||||
@@ -901,12 +904,12 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
public boolean visit(SQLExprTableSource x) {
|
||||
x.getExpr().accept(this);
|
||||
|
||||
|
||||
if (x.getAlias() != null) {
|
||||
print(' ');
|
||||
print0(x.getAlias());
|
||||
}
|
||||
|
||||
|
||||
if (isPrettyFormat() && x.hasAfterComment()) {
|
||||
print(' ');
|
||||
printComment(x.getAfterCommentsDirect(), "\n");
|
||||
@@ -1016,7 +1019,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
|
||||
protected void printCascade() {
|
||||
print0(ucase ? " CASCADE": " cascade");
|
||||
print0(ucase ? " CASCADE" : " cascade");
|
||||
}
|
||||
|
||||
public boolean visit(SQLDropViewStatement x) {
|
||||
@@ -1084,10 +1087,10 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print0(ucase ? " COMMENT " : " comment ");
|
||||
x.getComment().accept(this);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLColumnDefinition.Identity x) {
|
||||
print0(ucase ? "IDENTITY (" : "identity (");
|
||||
@@ -1629,20 +1632,20 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
public boolean visit(SQLCreateDatabaseStatement x) {
|
||||
print0(ucase ? "CREATE DATABASE " : "create database ");
|
||||
if (x.isIfNotExists()) {
|
||||
print0(ucase ? "IF NOT EXISTS " : "if not exists ");
|
||||
print0(ucase ? "IF NOT EXISTS " : "if not exists ");
|
||||
}
|
||||
x.getName().accept(this);
|
||||
|
||||
|
||||
if (x.getCharacterSet() != null) {
|
||||
print0(ucase ? " CHARACTER SET " : " character set ");
|
||||
print0(x.getCharacterSet());
|
||||
}
|
||||
|
||||
|
||||
if (x.getCollate() != null) {
|
||||
print0(ucase ? " COLLATE " : " collate ");
|
||||
print0(x.getCollate());
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1852,7 +1855,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print0(ucase ? "DROP PRIMARY KEY" : "drop primary key");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableDropKey x) {
|
||||
print0(ucase ? "DROP KEY " : "drop key ");
|
||||
@@ -1930,10 +1933,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print0(" (");
|
||||
printAndAccept(x.getItems(), ", ");
|
||||
print(')');
|
||||
|
||||
|
||||
// for mysql
|
||||
if (x.getUsing() != null) {
|
||||
print0(ucase ? " USING " : " using ");;
|
||||
print0(ucase ? " USING " : " using ");
|
||||
;
|
||||
print0(x.getUsing());
|
||||
}
|
||||
|
||||
@@ -2353,7 +2357,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
x.getTo().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLShowTablesStatement x) {
|
||||
print0(ucase ? "SHOW TABLES" : "show tables");
|
||||
@@ -2361,14 +2365,14 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print0(ucase ? " FROM " : " from ");
|
||||
x.getDatabase().accept(this);
|
||||
}
|
||||
|
||||
|
||||
if (x.getLike() != null) {
|
||||
print0(ucase ? " LIKE " : " like ");
|
||||
x.getLike().accept(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected void printComment(List<String> comments, String seperator) {
|
||||
if (comments != null) {
|
||||
for (int i = 0; i < comments.size(); ++i) {
|
||||
@@ -2380,7 +2384,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void printlnComments(List<String> comments) {
|
||||
if (comments != null) {
|
||||
for (int i = 0; i < comments.size(); ++i) {
|
||||
@@ -2390,7 +2394,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterViewRenameStatement x) {
|
||||
print0(ucase ? "ALTER VIEW " : "alter view ");
|
||||
@@ -2399,35 +2403,62 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
x.getTo().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableAddPartition x) {
|
||||
print0(ucase ? "ADD " : "add ");
|
||||
if (x.isIfNotExists()) {
|
||||
print0(ucase ? "IF NOT EXISTS " : "if not exists ");
|
||||
}
|
||||
print0(ucase ? "PARTITION (" : "partition (");
|
||||
printAndAccept(x.getPartition(), ", ");
|
||||
|
||||
if (x.getPartitionCount() != null) {
|
||||
print0(ucase ? "PARTITION PARTITIONS " : "partition partitions ");
|
||||
x.getPartitionCount().accept(this);
|
||||
}
|
||||
|
||||
if (x.getPartitions().size() > 0) {
|
||||
print0(ucase ? "PARTITION (" : "partition (");
|
||||
printAndAccept(x.getPartitions(), ", ");
|
||||
print(')');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableReOrganizePartition x) {
|
||||
print0(ucase ? "REORGANIZE " : "reorganize ");
|
||||
|
||||
printAndAccept(x.getNames(), ", ");
|
||||
|
||||
print0(ucase ? " INTO (" : " into (");
|
||||
printAndAccept(x.getPartitions(), ", ");
|
||||
print(')');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableDropPartition x) {
|
||||
print0(ucase ? "DROP " : "drop ");
|
||||
if (x.isIfNotExists()) {
|
||||
print0(ucase ? "IF NOT EXISTS " : "if not exists ");
|
||||
}
|
||||
print0(ucase ? "PARTITION (" : "partition (");
|
||||
printAndAccept(x.getPartition(), ", ");
|
||||
print(')');
|
||||
|
||||
print0(ucase ? "PARTITION " : "partition ");
|
||||
|
||||
if (x.getPartitions().size() == 1 && x.getPartitions().get(0) instanceof SQLName) {
|
||||
x.getPartitions().get(0).accept(this);
|
||||
} else {
|
||||
print('(');
|
||||
printAndAccept(x.getPartitions(), ", ");
|
||||
print(')');
|
||||
}
|
||||
|
||||
if (x.isPurge()) {
|
||||
print0(ucase ? " PURGE" : " purge");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableRenamePartition x) {
|
||||
print0(ucase ? "PARTITION (" : "partition (");
|
||||
@@ -2437,21 +2468,21 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print(')');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableSetComment x) {
|
||||
print0(ucase ? "SET COMMENT " : "set comment ");
|
||||
x.getComment().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableSetLifecycle x) {
|
||||
print0(ucase ? "SET LIFECYCLE " : "set lifecycle ");
|
||||
x.getLifecycle().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableEnableLifecycle x) {
|
||||
if (x.getPartition().size() != 0) {
|
||||
@@ -2459,11 +2490,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
printAndAccept(x.getPartition(), ", ");
|
||||
print0(") ");
|
||||
}
|
||||
|
||||
|
||||
print0(ucase ? "ENABLE LIFECYCLE" : "enable lifecycle");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableDisableLifecycle x) {
|
||||
if (x.getPartition().size() != 0) {
|
||||
@@ -2471,11 +2502,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
printAndAccept(x.getPartition(), ", ");
|
||||
print0(") ");
|
||||
}
|
||||
|
||||
|
||||
print0(ucase ? "DISABLE LIFECYCLE" : "disable lifecycle");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableTouch x) {
|
||||
print0(ucase ? "TOUCH" : "touch");
|
||||
@@ -2495,7 +2526,6 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print(']');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLOpenStatement x) {
|
||||
@@ -2503,7 +2533,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print0(x.getCursorName());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLFetchStatement x) {
|
||||
print0(ucase ? "FETCH " : "fetch ");
|
||||
@@ -2512,14 +2542,14 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
printAndAccept(x.getInto(), ", ");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLCloseStatement x) {
|
||||
print0(ucase ? "CLOSE " : "close ");
|
||||
print0(x.getCursorName());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLGroupingSetExpr x) {
|
||||
print0(ucase ? "GROUPING SETS" : "grouping sets");
|
||||
@@ -2528,7 +2558,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print(')');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLIfStatement x) {
|
||||
print0(ucase ? "IF " : "if ");
|
||||
@@ -2544,7 +2574,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
}
|
||||
decrementIndent();
|
||||
|
||||
|
||||
for (SQLIfStatement.ElseIf elseIf : x.getElseIfList()) {
|
||||
println();
|
||||
elseIf.accept(this);
|
||||
@@ -2556,7 +2586,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLIfStatement.Else x) {
|
||||
print0(ucase ? "ELSE" : "else");
|
||||
@@ -2575,7 +2605,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
decrementIndent();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLIfStatement.ElseIf x) {
|
||||
print0(ucase ? "ELSE IF" : "else if");
|
||||
@@ -2583,7 +2613,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print0(ucase ? " THEN" : " then");
|
||||
incrementIndent();
|
||||
println();
|
||||
|
||||
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
println();
|
||||
@@ -2592,11 +2622,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
item.setParent(x);
|
||||
item.accept(this);
|
||||
}
|
||||
|
||||
|
||||
decrementIndent();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLLoopStatement x) {
|
||||
print0(ucase ? "LOOP" : "loop");
|
||||
@@ -2617,7 +2647,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print0(ucase ? "END LOOP" : "end loop");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLParameter x) {
|
||||
if (x.getDataType().getName().equalsIgnoreCase("CURSOR")) {
|
||||
@@ -2652,12 +2682,12 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDeclareItem x) {
|
||||
x.getName().accept(this);
|
||||
|
||||
if(x.getType() == SQLDeclareItem.Type.TABLE) {
|
||||
|
||||
if (x.getType() == SQLDeclareItem.Type.TABLE) {
|
||||
print0(ucase ? " TABLE" : " table");
|
||||
int size = x.getTableElementList().size();
|
||||
|
||||
@@ -2692,23 +2722,22 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
x.getValue().accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLPartitionValue x) {
|
||||
if (x.getOperator() == SQLPartitionValue.Operator.LessThan //
|
||||
&& (!JdbcConstants.ORACLE.equals(getDbType()))
|
||||
&& x.getItems().size() == 1 //
|
||||
&& x.getItems().get(0) instanceof SQLIdentifierExpr) {
|
||||
&& (!JdbcConstants.ORACLE.equals(getDbType())) && x.getItems().size() == 1 //
|
||||
&& x.getItems().get(0) instanceof SQLIdentifierExpr) {
|
||||
SQLIdentifierExpr ident = (SQLIdentifierExpr) x.getItems().get(0);
|
||||
if ("MAXVALUE".equalsIgnoreCase(ident.getName())) {
|
||||
print0(ucase ? "VALUES LESS THAN MAXVALUE" : "values less than maxvalue");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (x.getOperator() == SQLPartitionValue.Operator.LessThan) {
|
||||
print0(ucase ? "VALUES LESS THAN (" : "values less than (");
|
||||
} else if (x.getOperator() == SQLPartitionValue.Operator.In) {
|
||||
@@ -2720,7 +2749,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print(')');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
@@ -2728,11 +2757,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
public boolean isUppCase() {
|
||||
return ucase;
|
||||
}
|
||||
|
||||
|
||||
public void setUppCase(boolean val) {
|
||||
this.ucase = val;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLPartition x) {
|
||||
print0(ucase ? "PARTITION " : "partition ");
|
||||
@@ -2749,7 +2778,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
x.getDataDirectory().accept(this);
|
||||
decrementIndent();
|
||||
}
|
||||
|
||||
|
||||
if (x.getIndexDirectory() != null) {
|
||||
incrementIndent();
|
||||
println();
|
||||
@@ -2757,32 +2786,32 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
x.getIndexDirectory().accept(this);
|
||||
decrementIndent();
|
||||
}
|
||||
|
||||
|
||||
if (x.getTableSpace() != null) {
|
||||
print0(ucase ? " TABLESPACE " : " tablespace ");
|
||||
x.getTableSpace().accept(this);
|
||||
}
|
||||
|
||||
|
||||
if (x.getEngine() != null) {
|
||||
print0(ucase ? " STORAGE ENGINE " : " storage engine ");
|
||||
x.getEngine().accept(this);
|
||||
}
|
||||
|
||||
|
||||
if (x.getMaxRows() != null) {
|
||||
print0(ucase ? " MAX_ROWS " : " max_rows ");
|
||||
x.getMaxRows().accept(this);
|
||||
}
|
||||
|
||||
|
||||
if (x.getMinRows() != null) {
|
||||
print0(ucase ? " MIN_ROWS " : " min_rows ");
|
||||
x.getMinRows().accept(this);
|
||||
}
|
||||
|
||||
|
||||
if (x.getComment() != null) {
|
||||
print0(ucase ? " COMMENT " : " comment ");
|
||||
x.getComment().accept(this);
|
||||
}
|
||||
|
||||
|
||||
if (x.getSubPartitionsCount() != null) {
|
||||
incrementIndent();
|
||||
println();
|
||||
@@ -2790,7 +2819,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
x.getSubPartitionsCount().accept(this);
|
||||
decrementIndent();
|
||||
}
|
||||
|
||||
|
||||
if (x.getSubPartitions().size() > 0) {
|
||||
println();
|
||||
print('(');
|
||||
@@ -2809,7 +2838,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLPartitionByRange x) {
|
||||
print0(ucase ? "PARTITION BY RANGE" : "partition by range");
|
||||
@@ -2833,7 +2862,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
|
||||
printPartitionsCountAndSubPartitions(x);
|
||||
|
||||
|
||||
println();
|
||||
print('(');
|
||||
incrementIndent();
|
||||
@@ -2847,10 +2876,10 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
decrementIndent();
|
||||
println();
|
||||
print(')');
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLPartitionByList x) {
|
||||
print0(ucase ? "PARTITION BY LIST " : "partition by list ");
|
||||
@@ -2885,7 +2914,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLPartitionByHash x) {
|
||||
if (x.isLinear()) {
|
||||
@@ -2906,7 +2935,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected void printPartitionsCountAndSubPartitions(SQLPartitionBy x) {
|
||||
if (x.getPartitionsCount() != null) {
|
||||
|
||||
@@ -2918,12 +2947,12 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
x.getPartitionsCount().accept(this);
|
||||
}
|
||||
|
||||
|
||||
if (x.getSubPartitionBy() != null) {
|
||||
println();
|
||||
x.getSubPartitionBy().accept(this);
|
||||
}
|
||||
|
||||
|
||||
if (x.getStoreIn().size() > 0) {
|
||||
println();
|
||||
print0(ucase ? "STORE IN (" : "store in (");
|
||||
@@ -2931,7 +2960,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print(')');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLSubPartitionByHash x) {
|
||||
if (x.isLinear()) {
|
||||
@@ -2955,7 +2984,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLSubPartitionByList x) {
|
||||
if (x.isLinear()) {
|
||||
@@ -2963,16 +2992,16 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
} else {
|
||||
print0(ucase ? "SUBPARTITION BY HASH " : "subpartition by hash ");
|
||||
}
|
||||
|
||||
|
||||
print('(');
|
||||
x.getColumn().accept(this);
|
||||
print(')');
|
||||
|
||||
|
||||
if (x.getSubPartitionsCount() != null) {
|
||||
print0(ucase ? " SUBPARTITIONS " : " subpartitions ");
|
||||
x.getSubPartitionsCount().accept(this);
|
||||
}
|
||||
|
||||
|
||||
if (x.getSubPartitionTemplate().size() > 0) {
|
||||
incrementIndent();
|
||||
println();
|
||||
@@ -2985,42 +3014,49 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print(')');
|
||||
decrementIndent();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLSubPartition x) {
|
||||
print0(ucase ? "SUBPARTITION " : "subpartition ");
|
||||
x.getName().accept(this);
|
||||
|
||||
|
||||
if (x.getValues() != null) {
|
||||
print(' ');
|
||||
x.getValues().accept(this);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterDatabaseStatement x) {
|
||||
print0(ucase ? "ALTER DATABASE " : "alter database ");
|
||||
x.getName().accept(this);
|
||||
if (x.isUpgradeDataDirectoryName()) {
|
||||
print0(ucase ? " UPGRADE DATA DIRECTORY NAME" : " upgrade data directory name");
|
||||
print0(ucase ? " UPGRADE DATA DIRECTORY NAME" : " upgrade data directory name");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableConvertCharSet x) {
|
||||
print0(ucase ? "CONVERT TO CHARACTER SET " : "convert to character set ");
|
||||
x.getCharset().accept(this);
|
||||
|
||||
|
||||
if (x.getCollate() != null) {
|
||||
print0(ucase ? "COLLATE " : "collate ");
|
||||
x.getCollate().accept(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableCoalescePartition x) {
|
||||
print0(ucase ? "COALESCE PARTITION " : "coalesce partition ");
|
||||
x.getCount().accept(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAlterColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableCoalescePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableConvertCharSet;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableKeys;
|
||||
@@ -84,6 +85,7 @@ import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableKeys;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableLifecycle;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableReOrganizePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRename;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRenameColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRenamePartition;
|
||||
@@ -740,4 +742,12 @@ public interface SQLASTVisitor {
|
||||
boolean visit(SQLAlterTableConvertCharSet x);
|
||||
|
||||
void endVisit(SQLAlterTableConvertCharSet x);
|
||||
|
||||
boolean visit(SQLAlterTableReOrganizePartition x);
|
||||
|
||||
void endVisit(SQLAlterTableReOrganizePartition x);
|
||||
|
||||
boolean visit(SQLAlterTableCoalescePartition x);
|
||||
|
||||
void endVisit(SQLAlterTableCoalescePartition x);
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAlterColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableCoalescePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableConvertCharSet;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableKeys;
|
||||
@@ -85,6 +86,7 @@ import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableKeys;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableLifecycle;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableReOrganizePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRename;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRenameColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRenamePartition;
|
||||
@@ -1493,4 +1495,24 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableReOrganizePartition x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLAlterTableReOrganizePartition x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableCoalescePartition x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLAlterTableCoalescePartition x) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,12 +51,15 @@ import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterDatabaseStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableCoalescePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableConvertCharSet;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropForeignKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableReOrganizePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRename;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLBlockStatement;
|
||||
@@ -1514,4 +1517,19 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
public boolean visit(SQLAlterTableConvertCharSet x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableDropPartition x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableReOrganizePartition x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableCoalescePartition x) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user