mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
@@ -24,6 +24,7 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLStatement {
|
||||
|
||||
protected boolean ifNotExiists = false;
|
||||
protected Type type;
|
||||
protected SQLExprTableSource tableSource;
|
||||
|
||||
@@ -71,6 +72,14 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
|
||||
public List<SQLTableElement> getTableElementList() {
|
||||
return tableElementList;
|
||||
}
|
||||
|
||||
public boolean isIfNotExiists() {
|
||||
return ifNotExiists;
|
||||
}
|
||||
|
||||
public void setIfNotExiists(boolean ifNotExiists) {
|
||||
this.ifNotExiists = ifNotExiists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void output(StringBuffer buf) {
|
||||
|
||||
-10
@@ -34,8 +34,6 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class MySqlCreateTableStatement extends SQLCreateTableStatement implements MySqlStatement {
|
||||
|
||||
private boolean ifNotExiists = false;
|
||||
|
||||
private Map<String, SQLObject> tableOptions = new LinkedHashMap<String, SQLObject>();
|
||||
|
||||
protected SQLSelect query;
|
||||
@@ -99,14 +97,6 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public boolean isIfNotExiists() {
|
||||
return ifNotExiists;
|
||||
}
|
||||
|
||||
public void setIfNotExiists(boolean ifNotExiists) {
|
||||
this.ifNotExiists = ifNotExiists;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor instanceof MySqlASTVisitor) {
|
||||
|
||||
@@ -2375,6 +2375,11 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
} else if (identifierEquals("REMOVE")) {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
} else if (identifierEquals("ALGORITHM")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EQ);
|
||||
stmt.getItems().add(new MySqlAlterTableOption("ALGORITHM", lexer.stringVal()));
|
||||
lexer.nextToken();
|
||||
} else if (identifierEquals(ENGINE)) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EQ);
|
||||
|
||||
+13
-11
@@ -28,21 +28,13 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class OdpsCreateTableStatement extends SQLCreateTableStatement {
|
||||
|
||||
private boolean ifNotExiists = false;
|
||||
|
||||
private SQLExprTableSource like;
|
||||
|
||||
protected SQLExpr comment;
|
||||
|
||||
protected List<SQLColumnDefinition> partitionColumns = new ArrayList<SQLColumnDefinition>(2);
|
||||
|
||||
public boolean isIfNotExiists() {
|
||||
return ifNotExiists;
|
||||
}
|
||||
|
||||
public void setIfNotExiists(boolean ifNotExiists) {
|
||||
this.ifNotExiists = ifNotExiists;
|
||||
}
|
||||
protected SQLExpr lifecycle;
|
||||
|
||||
public SQLExprTableSource getLike() {
|
||||
return like;
|
||||
@@ -67,7 +59,15 @@ public class OdpsCreateTableStatement extends SQLCreateTableStatement {
|
||||
public List<SQLColumnDefinition> getPartitionColumns() {
|
||||
return partitionColumns;
|
||||
}
|
||||
|
||||
|
||||
public SQLExpr getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
public void setLifecycle(SQLExpr lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
accept0((OdpsASTVisitor) visitor);
|
||||
@@ -78,7 +78,9 @@ public class OdpsCreateTableStatement extends SQLCreateTableStatement {
|
||||
this.acceptChild(visitor, tableSource);
|
||||
this.acceptChild(visitor, tableElementList);
|
||||
this.acceptChild(visitor, partitionColumns);
|
||||
this.acceptChild(visitor, lifecycle);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.alibaba.druid.sql.dialect.odps.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class OdpsShowPartitionsStmt extends SQLStatementImpl implements SQLStatement {
|
||||
|
||||
private SQLExprTableSource tableSource;
|
||||
|
||||
public SQLExprTableSource getTableSource() {
|
||||
return tableSource;
|
||||
}
|
||||
|
||||
public void setTableSource(SQLExprTableSource tableSource) {
|
||||
this.tableSource = tableSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
accept0((OdpsASTVisitor) visitor);
|
||||
}
|
||||
|
||||
protected void accept0(OdpsASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, tableSource);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.alibaba.druid.sql.dialect.odps.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class OdpsShowStatisticStmt extends SQLStatementImpl implements SQLStatement {
|
||||
|
||||
private SQLExprTableSource tableSource;
|
||||
|
||||
public SQLExprTableSource getTableSource() {
|
||||
return tableSource;
|
||||
}
|
||||
|
||||
public void setTableSource(SQLExprTableSource tableSource) {
|
||||
this.tableSource = tableSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
accept0((OdpsASTVisitor) visitor);
|
||||
}
|
||||
|
||||
protected void accept0(OdpsASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, tableSource);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,11 @@ public class OdpsCreateTableParser extends SQLCreateTableParser {
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
if (identifierEquals("LIFECYCLE")) {
|
||||
lexer.nextToken();
|
||||
stmt.setLifecycle(this.exprParser.expr());
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public class OdpsLexer extends Lexer {
|
||||
|
||||
map.putAll(Keywords.DEFAULT_KEYWORDS.getKeywords());
|
||||
|
||||
map.put("SHOW", Token.SHOW);
|
||||
map.put("PARTITION", Token.PARTITION);
|
||||
map.put("PARTITIONED", Token.PARTITIONED);
|
||||
map.put("OVERWRITE", Token.OVERWRITE);
|
||||
|
||||
@@ -21,10 +21,14 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelect;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowPartitionsStmt;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowStatisticStmt;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLCreateTableParser;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
import com.alibaba.druid.sql.parser.SQLSelectParser;
|
||||
@@ -134,4 +138,31 @@ public class OdpsStatementParser extends SQLStatementParser {
|
||||
return insert;
|
||||
}
|
||||
|
||||
public SQLStatement parseShow() {
|
||||
accept(Token.SHOW);
|
||||
|
||||
if (identifierEquals("PARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
|
||||
OdpsShowPartitionsStmt stmt = new OdpsShowPartitionsStmt();
|
||||
|
||||
SQLExpr expr = this.exprParser.expr();
|
||||
stmt.setTableSource(new SQLExprTableSource(expr));
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
if (identifierEquals("STATISTIC")) {
|
||||
lexer.nextToken();
|
||||
|
||||
OdpsShowStatisticStmt stmt = new OdpsShowStatisticStmt();
|
||||
|
||||
SQLExpr expr = this.exprParser.expr();
|
||||
stmt.setTableSource(new SQLExprTableSource(expr));
|
||||
|
||||
return stmt;
|
||||
}
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ package com.alibaba.druid.sql.dialect.odps.visitor;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowPartitionsStmt;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowStatisticStmt;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsUDTFSQLSelectItem;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
@@ -38,4 +40,12 @@ public interface OdpsASTVisitor extends SQLASTVisitor {
|
||||
void endVisit(OdpsUDTFSQLSelectItem x);
|
||||
|
||||
boolean visit(OdpsUDTFSQLSelectItem x);
|
||||
|
||||
void endVisit(OdpsShowPartitionsStmt x);
|
||||
|
||||
boolean visit(OdpsShowPartitionsStmt x);
|
||||
|
||||
void endVisit(OdpsShowStatisticStmt x);
|
||||
|
||||
boolean visit(OdpsShowStatisticStmt x);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowPartitionsStmt;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowStatisticStmt;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsUDTFSQLSelectItem;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
|
||||
@@ -89,6 +91,12 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
}
|
||||
print(")");
|
||||
}
|
||||
|
||||
if (x.getLifecycle() != null) {
|
||||
println();
|
||||
print("LIFECYCLE ");
|
||||
x.getLifecycle().accept(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -299,4 +307,28 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OdpsShowPartitionsStmt x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsShowPartitionsStmt x) {
|
||||
print("SHOW PARTITIONS ");
|
||||
x.getTableSource().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OdpsShowStatisticStmt x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsShowStatisticStmt x) {
|
||||
print("SHOW STATISTIC ");
|
||||
x.getTableSource().accept(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowPartitionsStmt;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowStatisticStmt;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsUDTFSQLSelectItem;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
|
||||
@@ -65,5 +67,25 @@ public class OdpsSchemaStatVisitor extends SchemaStatVisitor implements OdpsASTV
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OdpsShowPartitionsStmt x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsShowPartitionsStmt x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OdpsShowStatisticStmt x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsShowStatisticStmt x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user