fixed sql parser for odps alter table drop partition statement.

This commit is contained in:
wenshao
2017-01-11 16:41:23 +08:00
parent b5867e7c5e
commit e6341c4a89
3 changed files with 13 additions and 14 deletions
@@ -24,7 +24,7 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLAlterTableDropPartition extends SQLObjectImpl implements SQLAlterTableItem {
private boolean ifNotExists = false;
private boolean ifExists = false;
private boolean purge;
@@ -41,12 +41,12 @@ public class SQLAlterTableDropPartition extends SQLObjectImpl implements SQLAlte
this.partitions.add(partition);
}
public boolean isIfNotExists() {
return ifNotExists;
public boolean isIfExists() {
return ifExists;
}
public void setIfNotExists(boolean ifNotExists) {
this.ifNotExists = ifNotExists;
public void setIfExists(boolean ifExists) {
this.ifExists = ifExists;
}
public boolean isPurge() {
@@ -30,7 +30,6 @@ import com.alibaba.druid.sql.ast.statement.*;
import com.alibaba.druid.sql.ast.statement.SQLCreateTriggerStatement.TriggerEvent;
import com.alibaba.druid.sql.ast.statement.SQLCreateTriggerStatement.TriggerType;
import com.alibaba.druid.util.JdbcConstants;
import org.apache.ibatis.jdbc.SQL;
public class SQLStatementParser extends SQLParser {
@@ -1054,13 +1053,13 @@ public class SQLStatementParser extends SQLParser {
public void parseAlterDrop(SQLAlterTableStatement stmt) {
lexer.nextToken();
boolean ifNotExists = false;
boolean ifExists = false;
if (lexer.token() == Token.IF) {
lexer.nextToken();
accept(Token.NOT);
accept(Token.EXISTS);
ifNotExists = true;
ifExists = true;
}
if (lexer.token() == Token.CONSTRAINT) {
@@ -1090,7 +1089,7 @@ public class SQLStatementParser extends SQLParser {
stmt.addItem(item);
} else if (lexer.token() == Token.PARTITION) {
SQLAlterTableDropPartition dropPartition = parseAlterTableDropPartition(ifNotExists);
SQLAlterTableDropPartition dropPartition = parseAlterTableDropPartition(ifExists);
stmt.addItem(dropPartition);
} else if (lexer.token() == Token.INDEX) {
@@ -1104,11 +1103,11 @@ public class SQLStatementParser extends SQLParser {
}
}
protected SQLAlterTableDropPartition parseAlterTableDropPartition(boolean ifNotExists) {
protected SQLAlterTableDropPartition parseAlterTableDropPartition(boolean ifExists) {
lexer.nextToken();
SQLAlterTableDropPartition dropPartition = new SQLAlterTableDropPartition();
dropPartition.setIfNotExists(ifNotExists);
dropPartition.setIfExists(ifExists);
if (lexer.token() == Token.LPAREN) {
accept(Token.LPAREN);
@@ -2838,8 +2838,8 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
@Override
public boolean visit(SQLAlterTableDropPartition x) {
print0(ucase ? "DROP " : "drop ");
if (x.isIfNotExists()) {
print0(ucase ? "IF NOT EXISTS " : "if not exists ");
if (x.isIfExists()) {
print0(ucase ? "IF EXISTS " : "if exists ");
}
print0(ucase ? "PARTITION " : "partition ");