mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge pull request #1085 from wenshao/master
mysql parser support subpartition syntax
This commit is contained in:
@@ -1933,7 +1933,7 @@ public class DruidDataSource extends DruidAbstractDataSource
|
||||
try {
|
||||
connection = createPhysicalConnection();
|
||||
} catch (SQLException e) {
|
||||
LOG.error("create connection error, url: " + jdbcUrl, e);
|
||||
LOG.error("create connection error, url: " + jdbcUrl + ", errorCode " + e.getErrorCode() + ", state " + e.getSQLState(), e);
|
||||
|
||||
errorCount++;
|
||||
|
||||
|
||||
+12
@@ -44,6 +44,8 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement
|
||||
private List<SQLCommentHint> optionHints = new ArrayList<SQLCommentHint>();
|
||||
|
||||
private SQLExprTableSource like;
|
||||
|
||||
private SQLName tableGroup;
|
||||
|
||||
public MySqlCreateTableStatement(){
|
||||
super (JdbcConstants.MYSQL);
|
||||
@@ -157,4 +159,14 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement
|
||||
public void setOptionHints(List<SQLCommentHint> optionHints) {
|
||||
this.optionHints = optionHints;
|
||||
}
|
||||
|
||||
|
||||
public SQLName getTableGroup() {
|
||||
return tableGroup;
|
||||
}
|
||||
|
||||
|
||||
public void setTableGroup(SQLName tableGroup) {
|
||||
this.tableGroup = tableGroup;
|
||||
}
|
||||
}
|
||||
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.dialect.mysql.ast.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitioningClause;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObjectImpl;
|
||||
|
||||
public abstract class MySqlPartitionByClause extends MySqlObjectImpl implements SQLPartitioningClause {
|
||||
|
||||
private List<MySqlPartitioningDef> partitions = new ArrayList<MySqlPartitioningDef>();
|
||||
|
||||
protected SQLExpr partitionsCount;
|
||||
|
||||
protected boolean linear;
|
||||
|
||||
protected MySqlSubPartitionByClause subPartitionBy;
|
||||
|
||||
public List<MySqlPartitioningDef> getPartitions() {
|
||||
return partitions;
|
||||
}
|
||||
|
||||
public void setPartitions(List<MySqlPartitioningDef> partitions) {
|
||||
this.partitions = partitions;
|
||||
}
|
||||
|
||||
public SQLExpr getPartitionsCount() {
|
||||
return partitionsCount;
|
||||
}
|
||||
|
||||
public void setPartitionsCount(SQLExpr partitionsCount) {
|
||||
this.partitionsCount = partitionsCount;
|
||||
}
|
||||
|
||||
public boolean isLinear() {
|
||||
return linear;
|
||||
}
|
||||
|
||||
public void setLinear(boolean linear) {
|
||||
this.linear = linear;
|
||||
}
|
||||
|
||||
public MySqlSubPartitionByClause getSubPartitionBy() {
|
||||
return subPartitionBy;
|
||||
}
|
||||
|
||||
public void setSubPartitionBy(MySqlSubPartitionByClause subPartitionBy) {
|
||||
this.subPartitionBy = subPartitionBy;
|
||||
}
|
||||
|
||||
}
|
||||
+9
-18
@@ -18,32 +18,24 @@ package com.alibaba.druid.sql.dialect.mysql.ast.statement;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MySqlPartitionByHash extends MySqlPartitioningClause {
|
||||
public class MySqlPartitionByHash extends MySqlPartitionByClause {
|
||||
|
||||
private SQLExpr expr;
|
||||
|
||||
private SQLExpr partitionCount;
|
||||
|
||||
private boolean linear;
|
||||
// for aliyun ads
|
||||
private boolean key;
|
||||
|
||||
@Override
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, expr);
|
||||
acceptChild(visitor, partitionCount);
|
||||
acceptChild(visitor, partitionsCount);
|
||||
acceptChild(visitor, getPartitions());
|
||||
acceptChild(visitor, subPartitionBy);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getPartitionCount() {
|
||||
return partitionCount;
|
||||
}
|
||||
|
||||
public void setPartitionCount(SQLExpr partitionCount) {
|
||||
this.partitionCount = partitionCount;
|
||||
}
|
||||
|
||||
public SQLExpr getExpr() {
|
||||
return expr;
|
||||
}
|
||||
@@ -52,12 +44,11 @@ public class MySqlPartitionByHash extends MySqlPartitioningClause {
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
public boolean isLinear() {
|
||||
return linear;
|
||||
public boolean isKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setLinear(boolean linear) {
|
||||
this.linear = linear;
|
||||
public void setKey(boolean key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-23
@@ -18,36 +18,24 @@ package com.alibaba.druid.sql.dialect.mysql.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.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MySqlPartitionByKey extends MySqlPartitioningClause {
|
||||
public class MySqlPartitionByKey extends MySqlPartitionByClause {
|
||||
|
||||
private List<SQLName> columns = new ArrayList<SQLName>();
|
||||
|
||||
private SQLExpr partitionCount;
|
||||
|
||||
private boolean linear;
|
||||
|
||||
@Override
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, columns);
|
||||
acceptChild(visitor, partitionCount);
|
||||
acceptChild(visitor, partitionsCount);
|
||||
acceptChild(visitor, getPartitions());
|
||||
acceptChild(visitor, subPartitionBy);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getPartitionCount() {
|
||||
return partitionCount;
|
||||
}
|
||||
|
||||
public void setPartitionCount(SQLExpr partitionCount) {
|
||||
this.partitionCount = partitionCount;
|
||||
}
|
||||
|
||||
public List<SQLName> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
@@ -56,12 +44,4 @@ public class MySqlPartitionByKey extends MySqlPartitioningClause {
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
public boolean isLinear() {
|
||||
return linear;
|
||||
}
|
||||
|
||||
public void setLinear(boolean linear) {
|
||||
this.linear = linear;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-12
@@ -22,21 +22,20 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MySqlPartitionByList extends MySqlPartitioningClause {
|
||||
public class MySqlPartitionByList extends MySqlPartitionByClause {
|
||||
|
||||
private SQLExpr expr;
|
||||
|
||||
private List<SQLName> columns = new ArrayList<SQLName>();
|
||||
|
||||
private SQLExpr partitionCount;
|
||||
|
||||
@Override
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, expr);
|
||||
acceptChild(visitor, columns);
|
||||
acceptChild(visitor, partitionCount);
|
||||
acceptChild(visitor, partitionsCount);
|
||||
acceptChild(visitor, getPartitions());
|
||||
acceptChild(visitor, subPartitionBy);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
@@ -52,14 +51,6 @@ public class MySqlPartitionByList extends MySqlPartitioningClause {
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
public SQLExpr getPartitionCount() {
|
||||
return partitionCount;
|
||||
}
|
||||
|
||||
public void setPartitionCount(SQLExpr partitionCount) {
|
||||
this.partitionCount = partitionCount;
|
||||
}
|
||||
|
||||
public List<SQLName> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
+3
-12
@@ -22,21 +22,20 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MySqlPartitionByRange extends MySqlPartitioningClause {
|
||||
public class MySqlPartitionByRange extends MySqlPartitionByClause {
|
||||
|
||||
private SQLExpr expr;
|
||||
|
||||
private List<SQLName> columns = new ArrayList<SQLName>();
|
||||
|
||||
private SQLExpr partitionCount;
|
||||
|
||||
@Override
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, expr);
|
||||
acceptChild(visitor, columns);
|
||||
acceptChild(visitor, partitionCount);
|
||||
acceptChild(visitor, partitionsCount);
|
||||
acceptChild(visitor, getPartitions());
|
||||
acceptChild(visitor, subPartitionBy);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
@@ -52,14 +51,6 @@ public class MySqlPartitionByRange extends MySqlPartitioningClause {
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
public SQLExpr getPartitionCount() {
|
||||
return partitionCount;
|
||||
}
|
||||
|
||||
public void setPartitionCount(SQLExpr partitionCount) {
|
||||
this.partitionCount = partitionCount;
|
||||
}
|
||||
|
||||
public List<SQLName> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
+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.dialect.mysql.ast.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitioningClause;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObjectImpl;
|
||||
|
||||
public abstract class MySqlSubPartitionByClause extends MySqlObjectImpl implements SQLPartitioningClause {
|
||||
|
||||
protected SQLExpr subPartitionsCount;
|
||||
|
||||
protected boolean linear;
|
||||
|
||||
protected List<SQLAssignItem> options = new ArrayList<SQLAssignItem>();
|
||||
|
||||
public SQLExpr getSubPartitionsCount() {
|
||||
return subPartitionsCount;
|
||||
}
|
||||
|
||||
public void setSubPartitionsCount(SQLExpr subPartitionsCount) {
|
||||
this.subPartitionsCount = subPartitionsCount;
|
||||
}
|
||||
|
||||
public boolean isLinear() {
|
||||
return linear;
|
||||
}
|
||||
|
||||
public void setLinear(boolean linear) {
|
||||
this.linear = linear;
|
||||
}
|
||||
|
||||
public List<SQLAssignItem> getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
}
|
||||
+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.dialect.mysql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MySqlSubPartitionByHash extends MySqlSubPartitionByClause {
|
||||
|
||||
private SQLExpr expr;
|
||||
|
||||
// for aliyun ads
|
||||
private boolean key;
|
||||
|
||||
@Override
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, expr);
|
||||
acceptChild(visitor, subPartitionsCount);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getExpr() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
public void setExpr(SQLExpr expr) {
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
public boolean isKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(boolean key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+45
-36
@@ -1,36 +1,45 @@
|
||||
/*
|
||||
* 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.dialect.mysql.ast.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLPartitioningClause;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObjectImpl;
|
||||
|
||||
public abstract class MySqlPartitioningClause extends MySqlObjectImpl implements SQLPartitioningClause {
|
||||
|
||||
private List<MySqlPartitioningDef> partitions = new ArrayList<MySqlPartitioningDef>();
|
||||
|
||||
public List<MySqlPartitioningDef> getPartitions() {
|
||||
return partitions;
|
||||
}
|
||||
|
||||
public void setPartitions(List<MySqlPartitioningDef> partitions) {
|
||||
this.partitions = partitions;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* 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.dialect.mysql.ast.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MySqlSubPartitionByKey extends MySqlSubPartitionByClause {
|
||||
|
||||
private List<SQLName> columns = new ArrayList<SQLName>();
|
||||
|
||||
@Override
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, columns);
|
||||
acceptChild(visitor, subPartitionsCount);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public List<SQLName> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void setColumns(List<SQLName> columns) {
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.dialect.mysql.ast.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MySqlSubPartitionByList extends MySqlSubPartitionByClause {
|
||||
|
||||
private SQLExpr expr;
|
||||
|
||||
private List<SQLColumnDefinition> columns = new ArrayList<SQLColumnDefinition>();
|
||||
|
||||
@Override
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, expr);
|
||||
acceptChild(visitor, columns);
|
||||
acceptChild(visitor, subPartitionsCount);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getExpr() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
public void setExpr(SQLExpr expr) {
|
||||
if (expr != null) {
|
||||
expr.setParent(this);
|
||||
}
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
public List<SQLColumnDefinition> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void setColumns(List<SQLColumnDefinition> columns) {
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
}
|
||||
+156
-19
@@ -15,9 +15,12 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.mysql.parser;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLDataTypeImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderingSpecification;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCheck;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
@@ -32,12 +35,16 @@ import com.alibaba.druid.sql.dialect.mysql.ast.MysqlForeignKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement.TableSpaceOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByClause;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByHash;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByList;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByRange;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitioningClause;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitioningDef;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByClause;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByHash;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByList;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLCreateTableParser;
|
||||
@@ -380,6 +387,14 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
stmt.getTableOptions().put("TABLESPACE", option);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("TABLEGROUP")) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLName tableGroup = this.exprParser.name();
|
||||
stmt.setTableGroup(tableGroup);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("TYPE")) {
|
||||
lexer.nextToken();
|
||||
@@ -393,7 +408,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
|
||||
MySqlPartitioningClause partitionClause;
|
||||
MySqlPartitionByClause partitionClause;
|
||||
|
||||
boolean linera = false;
|
||||
if (identifierEquals("LINEAR")) {
|
||||
@@ -422,10 +437,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
|
||||
partitionClause = clause;
|
||||
|
||||
if (identifierEquals("PARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
clause.setPartitionCount(this.exprParser.expr());
|
||||
}
|
||||
partitionClauseRest(clause);
|
||||
} else if (identifierEquals("HASH")) {
|
||||
lexer.nextToken();
|
||||
MySqlPartitionByHash clause = new MySqlPartitionByHash();
|
||||
@@ -433,16 +445,18 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (linera) {
|
||||
clause.setLinear(true);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.KEY) {
|
||||
lexer.nextToken();
|
||||
clause.setKey(true);
|
||||
}
|
||||
|
||||
accept(Token.LPAREN);
|
||||
clause.setExpr(this.exprParser.expr());
|
||||
accept(Token.RPAREN);
|
||||
partitionClause = clause;
|
||||
|
||||
if (identifierEquals("PARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
clause.setPartitionCount(this.exprParser.expr());
|
||||
}
|
||||
partitionClauseRest(clause);
|
||||
|
||||
} else if (identifierEquals("RANGE")) {
|
||||
lexer.nextToken();
|
||||
@@ -467,11 +481,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
}
|
||||
partitionClause = clause;
|
||||
|
||||
if (identifierEquals("PARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
clause.setPartitionCount(this.exprParser.expr());
|
||||
}
|
||||
//
|
||||
partitionClauseRest(clause);
|
||||
|
||||
} else if (identifierEquals("LIST")) {
|
||||
lexer.nextToken();
|
||||
@@ -496,10 +506,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
}
|
||||
partitionClause = clause;
|
||||
|
||||
if (identifierEquals("PARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
clause.setPartitionCount(this.exprParser.expr());
|
||||
}
|
||||
partitionClauseRest(clause);
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
}
|
||||
@@ -569,6 +576,8 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
}
|
||||
|
||||
stmt.setPartitioning(partitionClause);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -593,6 +602,134 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
protected void partitionClauseRest(MySqlPartitionByClause clause) {
|
||||
if (identifierEquals("PARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
clause.setPartitionsCount(this.exprParser.expr());
|
||||
}
|
||||
|
||||
if (identifierEquals("PARTITION")) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (identifierEquals("NUM")) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
clause.setPartitionsCount(this.exprParser.expr());
|
||||
|
||||
clause.putAttribute("ads.partition", Boolean.TRUE);
|
||||
}
|
||||
|
||||
if (identifierEquals("SUBPARTITION")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
|
||||
MySqlSubPartitionByClause subPartitionByClause = null;
|
||||
|
||||
boolean linear = false;
|
||||
if (identifierEquals("LINEAR")) {
|
||||
lexer.nextToken();
|
||||
linear = true;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.KEY) {
|
||||
MySqlSubPartitionByKey subPartitionKey = new MySqlSubPartitionByKey();
|
||||
lexer.nextToken();
|
||||
|
||||
if (linear) {
|
||||
clause.setLinear(true);
|
||||
}
|
||||
|
||||
accept(Token.LPAREN);
|
||||
for (;;) {
|
||||
subPartitionKey.getColumns().add(this.exprParser.name());
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
|
||||
subPartitionByClause = subPartitionKey;
|
||||
|
||||
} else if (identifierEquals("HASH")) {
|
||||
lexer.nextToken();
|
||||
MySqlSubPartitionByHash subPartitionHash = new MySqlSubPartitionByHash();
|
||||
|
||||
if (linear) {
|
||||
clause.setLinear(true);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.KEY) {
|
||||
lexer.nextToken();
|
||||
subPartitionHash.setKey(true);
|
||||
}
|
||||
|
||||
accept(Token.LPAREN);
|
||||
subPartitionHash.setExpr(this.exprParser.expr());
|
||||
accept(Token.RPAREN);
|
||||
subPartitionByClause = subPartitionHash;
|
||||
|
||||
} else if (identifierEquals("LIST")) {
|
||||
lexer.nextToken();
|
||||
MySqlSubPartitionByList subPartitionList = new MySqlSubPartitionByList();
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
SQLExpr expr = this.exprParser.expr();
|
||||
|
||||
if (expr instanceof SQLIdentifierExpr && (identifierEquals("bigint") || identifierEquals("long"))) {
|
||||
String dataType = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
|
||||
SQLColumnDefinition column = this.exprParser.createColumnDefinition();
|
||||
column.setName((SQLIdentifierExpr)expr);
|
||||
column.setDataType(new SQLDataTypeImpl(dataType));
|
||||
subPartitionList.getColumns().add(column);
|
||||
|
||||
subPartitionList.putAttribute("ads.subPartitionList", Boolean.TRUE);
|
||||
} else {
|
||||
subPartitionList.setExpr(expr);
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
} else {
|
||||
acceptIdentifier("COLUMNS");
|
||||
accept(Token.LPAREN);
|
||||
for (;;) {
|
||||
subPartitionList.getColumns().add(this.exprParser.parseColumn());
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
subPartitionByClause = subPartitionList;
|
||||
}
|
||||
|
||||
if (identifierEquals("SUBPARTITION")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("OPTIONS");
|
||||
accept(Token.LPAREN);
|
||||
|
||||
SQLAssignItem option = this.exprParser.parseAssignItem();
|
||||
accept(Token.RPAREN);
|
||||
|
||||
option.setParent(subPartitionByClause);
|
||||
|
||||
subPartitionByClause.getOptions().add(option);
|
||||
}
|
||||
|
||||
if (subPartitionByClause != null) {
|
||||
subPartitionByClause.setLinear(linear);
|
||||
|
||||
clause.setSubPartitionBy(subPartitionByClause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean parseTableOptionCharsetOrCollate(MySqlCreateTableStatement stmt) {
|
||||
if (identifierEquals("CHARACTER")) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -33,9 +33,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlSelectIntoStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlWhileStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlExtractExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlIntervalExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlMatchAgainstExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlUserName;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.CobarShowStatus;
|
||||
@@ -122,6 +122,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTriggersStatem
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowVariantsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowWarningsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStartTransactionStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByHash;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByList;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnionQuery;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement;
|
||||
@@ -604,5 +607,17 @@ public interface MySqlASTVisitor extends SQLASTVisitor {
|
||||
boolean visit(MySqlAlterTableAlterColumn x);
|
||||
|
||||
void endVisit(MySqlAlterTableAlterColumn x);
|
||||
|
||||
boolean visit(MySqlSubPartitionByHash x);
|
||||
|
||||
void endVisit(MySqlSubPartitionByHash x);
|
||||
|
||||
boolean visit(MySqlSubPartitionByKey x);
|
||||
|
||||
void endVisit(MySqlSubPartitionByKey x);
|
||||
|
||||
boolean visit(MySqlSubPartitionByList x);
|
||||
|
||||
void endVisit(MySqlSubPartitionByList x);
|
||||
|
||||
} //
|
||||
|
||||
+111
-79
@@ -33,9 +33,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlSelectIntoStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlWhileStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlExtractExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlIntervalExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlMatchAgainstExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlUserName;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.CobarShowStatus;
|
||||
@@ -127,6 +127,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTriggersStatem
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowVariantsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowWarningsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStartTransactionStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByHash;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByList;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnionQuery;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement;
|
||||
@@ -135,6 +138,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateTableSource;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter;
|
||||
|
||||
public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements MySqlASTVisitor {
|
||||
|
||||
@Override
|
||||
public boolean visit(Limit x) {
|
||||
return true;
|
||||
@@ -1209,9 +1213,9 @@ public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements MySq
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlHintStatement x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlOrderingExpr x) {
|
||||
return true;
|
||||
@@ -1222,98 +1226,98 @@ public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements MySq
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlWhileStatement x) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean visit(MySqlWhileStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlWhileStatement x) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void endVisit(MySqlWhileStatement x) {
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlCaseStatement x) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlCaseStatement x) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean visit(MySqlCaseStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlDeclareStatement x) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void endVisit(MySqlCaseStatement x) {
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlDeclareStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlSelectIntoStatement x) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean visit(MySqlDeclareStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSelectIntoStatement x) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void endVisit(MySqlDeclareStatement x) {
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlWhenStatement x) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlWhenStatement x) {
|
||||
|
||||
}
|
||||
//add:end
|
||||
@Override
|
||||
public boolean visit(MySqlSelectIntoStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlLeaveStatement x) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void endVisit(MySqlSelectIntoStatement x) {
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlLeaveStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlIterateStatement x) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean visit(MySqlWhenStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlIterateStatement x) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void endVisit(MySqlWhenStatement x) {
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlRepeatStatement x) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// add:end
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlRepeatStatement x) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean visit(MySqlLeaveStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlCursorDeclareStatement x) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void endVisit(MySqlLeaveStatement x) {
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlCursorDeclareStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlIterateStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlIterateStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlRepeatStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlRepeatStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlCursorDeclareStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlCursorDeclareStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlUpdateTableSource x) {
|
||||
return true;
|
||||
}
|
||||
@@ -1330,7 +1334,35 @@ public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements MySq
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlAlterTableAlterColumn x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlSubPartitionByKey x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSubPartitionByKey x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlSubPartitionByHash x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSubPartitionByHash x) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlSubPartitionByList x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSubPartitionByList x) {
|
||||
}
|
||||
|
||||
} //
|
||||
|
||||
+343
-231
@@ -63,9 +63,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlSelectIntoStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlWhileStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlExtractExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlIntervalExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlMatchAgainstExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlUserName;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.CobarShowStatus;
|
||||
@@ -96,6 +96,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadDataInFileStat
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadXmlStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLockTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlOptimizeStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByClause;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByHash;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByList;
|
||||
@@ -158,6 +159,10 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTriggersStatem
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowVariantsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowWarningsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStartTransactionStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByClause;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByHash;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByList;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnionQuery;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement;
|
||||
@@ -167,6 +172,7 @@ import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTVisitor {
|
||||
|
||||
{
|
||||
this.dbType = JdbcConstants.MYSQL;
|
||||
}
|
||||
@@ -371,12 +377,11 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
if (Boolean.TRUE == x.getAttribute("UNSIGNED")) {
|
||||
print0(ucase ? " UNSIGNED" : " unsigned");
|
||||
}
|
||||
|
||||
|
||||
if (Boolean.TRUE == x.getAttribute("ZEROFILL")) {
|
||||
print0(ucase ? " ZEROFILL" : " zerofill");
|
||||
}
|
||||
|
||||
|
||||
if (x instanceof SQLCharacterDataType) {
|
||||
SQLCharacterDataType charType = (SQLCharacterDataType) x;
|
||||
if (charType.getCharSetName() != null) {
|
||||
@@ -403,7 +408,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
if (x.isHasBinary()) {
|
||||
print0(ucase ? " BINARY " : " binary ");
|
||||
}
|
||||
|
||||
|
||||
if (x.getCharSetName() != null) {
|
||||
print0(ucase ? " CHARACTER SET " : " character set ");
|
||||
print0(x.getCharSetName());
|
||||
@@ -411,11 +416,11 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print0(ucase ? " COLLATE " : " collate ");
|
||||
print0(x.getCollate());
|
||||
}
|
||||
}else if (x.getCollate() != null) {
|
||||
} else if (x.getCollate() != null) {
|
||||
print0(ucase ? " COLLATE " : " collate ");
|
||||
print0(x.getCollate());
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -522,6 +527,12 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print(' ');
|
||||
x.getPartitioning().accept(this);
|
||||
}
|
||||
|
||||
if (x.getTableGroup() != null) {
|
||||
println();
|
||||
print0(ucase ? "TABLEGROUP " : "tablegroup ");
|
||||
x.getTableGroup().accept(this);
|
||||
}
|
||||
|
||||
if (x.getSelect() != null) {
|
||||
incrementIndent();
|
||||
@@ -598,7 +609,8 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print0(ucase ? "PRIMARY KEY" : "primary key");
|
||||
|
||||
if (x.getIndexType() != null) {
|
||||
print0(ucase ? " USING " : " using ");;
|
||||
print0(ucase ? " USING " : " using ");
|
||||
;
|
||||
print0(x.getIndexType());
|
||||
}
|
||||
|
||||
@@ -649,7 +661,15 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
&& (!varName.startsWith("#")) //
|
||||
&& (!varName.startsWith("$")) //
|
||||
&& (!varName.startsWith(":"))) {
|
||||
print0("@@");
|
||||
|
||||
boolean subPartitionOption = false;
|
||||
if (x.getParent() != null) {
|
||||
subPartitionOption = x.getParent().getParent() instanceof MySqlSubPartitionByClause;
|
||||
}
|
||||
|
||||
if (!subPartitionOption) {
|
||||
print0("@@");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -731,7 +751,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
return false;
|
||||
}
|
||||
|
||||
if (("CONVERT".equalsIgnoreCase(x.getMethodName()))||"CHAR".equalsIgnoreCase(x.getMethodName())) {
|
||||
if (("CONVERT".equalsIgnoreCase(x.getMethodName())) || "CHAR".equalsIgnoreCase(x.getMethodName())) {
|
||||
if (x.getOwner() != null) {
|
||||
x.getOwner().accept(this);
|
||||
print('.');
|
||||
@@ -742,7 +762,8 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
String charset = (String) x.getAttribute("USING");
|
||||
if (charset != null) {
|
||||
print0(ucase ? " USING " : " using ");;
|
||||
print0(ucase ? " USING " : " using ");
|
||||
;
|
||||
print0(charset);
|
||||
}
|
||||
print(')');
|
||||
@@ -826,7 +847,8 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print0(ucase ? "EXECUTE " : "execute ");
|
||||
x.getStatementName().accept(this);
|
||||
if (x.getParameters().size() > 0) {
|
||||
print0(ucase ? " USING " : " using ");;
|
||||
print0(ucase ? " USING " : " using ");
|
||||
;
|
||||
printAndAccept(x.getParameters(), ", ");
|
||||
}
|
||||
return false;
|
||||
@@ -1050,8 +1072,8 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
x.getLinesTerminatedBy().accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
if(x.getIgnoreLinesNumber() != null) {
|
||||
|
||||
if (x.getIgnoreLinesNumber() != null) {
|
||||
print0(ucase ? " IGNORE " : " ignore ");
|
||||
x.getIgnoreLinesNumber().accept(this);
|
||||
print0(ucase ? " LINES" : " lines");
|
||||
@@ -1062,7 +1084,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
printAndAccept(x.getColumns(), ", ");
|
||||
print(')');
|
||||
}
|
||||
|
||||
|
||||
if (x.getSetList().size() != 0) {
|
||||
print0(ucase ? " SET " : " set ");
|
||||
printAndAccept(x.getSetList(), ", ");
|
||||
@@ -1137,7 +1159,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
if (x.isConsistentSnapshot()) {
|
||||
print0(ucase ? " WITH CONSISTENT SNAPSHOT" : " with consistent snapshot");
|
||||
}
|
||||
|
||||
|
||||
if (x.getHints() != null && x.getHints().size() > 0) {
|
||||
print(' ');
|
||||
printAndAccept(x.getHints(), " ");
|
||||
@@ -1227,9 +1249,9 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
@Override
|
||||
public boolean visit(MySqlShowColumnsStatement x) {
|
||||
if (x.isFull()) {
|
||||
print0(ucase ? "SHOW FULL COLUMNS" : "show full columns");
|
||||
print0(ucase ? "SHOW FULL COLUMNS" : "show full columns");
|
||||
} else {
|
||||
print0(ucase ? "SHOW COLUMNS": "show columns");
|
||||
print0(ucase ? "SHOW COLUMNS" : "show columns");
|
||||
}
|
||||
|
||||
if (x.getTable() != null) {
|
||||
@@ -1519,10 +1541,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
printAndAccept(x.getColumns(), ", ");
|
||||
print(')');
|
||||
|
||||
if (x.getPartitionCount() != null) {
|
||||
print0(ucase ? " PARTITIONS " : " partitions ");
|
||||
x.getPartitionCount().accept(this);
|
||||
}
|
||||
printPartitionsCountAndSubPartitions(x);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1544,10 +1563,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print(')');
|
||||
}
|
||||
|
||||
if (x.getPartitionCount() != null) {
|
||||
print0(ucase ? " PARTITIONS " : " partitions ");
|
||||
x.getPartitionCount().accept(this);
|
||||
}
|
||||
printPartitionsCountAndSubPartitions(x);
|
||||
|
||||
List<MySqlPartitioningDef> partitions = x.getPartitions();
|
||||
int partitionsSize = partitions.size();
|
||||
@@ -1586,10 +1602,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print0(") ");
|
||||
}
|
||||
|
||||
if (x.getPartitionCount() != null) {
|
||||
print0(ucase ? " PARTITIONS " : " partitions ");
|
||||
x.getPartitionCount().accept(this);
|
||||
}
|
||||
printPartitionsCountAndSubPartitions(x);
|
||||
|
||||
List<MySqlPartitioningDef> partitions = x.getPartitions();
|
||||
int partitionsSize = partitions.size();
|
||||
@@ -1620,22 +1633,42 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
@Override
|
||||
public boolean visit(MySqlPartitionByHash x) {
|
||||
if (x.isLinear()) {
|
||||
print0(ucase ? "PARTITION BY LINEAR HASH (" : "partition by linear hash (");
|
||||
print0(ucase ? "PARTITION BY LINEAR HASH " : "partition by linear hash ");
|
||||
} else {
|
||||
print0(ucase ? "PARTITION BY HASH (" : "partition by hash (");
|
||||
print0(ucase ? "PARTITION BY HASH " : "partition by hash ");
|
||||
}
|
||||
//
|
||||
|
||||
if (x.isKey()) {
|
||||
print0(ucase ? "KEY" : "key");
|
||||
}
|
||||
|
||||
print('(');
|
||||
x.getExpr().accept(this);
|
||||
print(')');
|
||||
|
||||
if (x.getPartitionCount() != null) {
|
||||
print0(ucase ? " PARTITIONS " : " partitions ");
|
||||
x.getPartitionCount().accept(this);
|
||||
}
|
||||
printPartitionsCountAndSubPartitions(x);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void printPartitionsCountAndSubPartitions(MySqlPartitionByClause x) {
|
||||
if (x.getPartitionsCount() != null) {
|
||||
|
||||
if (Boolean.TRUE.equals(x.getAttribute("ads.partition"))) {
|
||||
print0(ucase ? " PARTITION NUM " : " partition num ");
|
||||
} else {
|
||||
print0(ucase ? " PARTITIONS " : " partitions ");
|
||||
}
|
||||
|
||||
x.getPartitionsCount().accept(this);
|
||||
}
|
||||
|
||||
if (x.getSubPartitionBy() != null) {
|
||||
println();
|
||||
x.getSubPartitionBy().accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSelectQueryBlock x) {
|
||||
|
||||
@@ -1783,7 +1816,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSetTransactionStatement x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2164,7 +2197,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
x.getTable().accept(this);
|
||||
}
|
||||
|
||||
|
||||
if (x.getHints() != null && x.getHints().size() > 0) {
|
||||
print(' ');
|
||||
printAndAccept(x.getHints(), " ");
|
||||
@@ -2510,7 +2543,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableAddColumn x) {
|
||||
print0(ucase ? "ADD COLUMN " : "add column ");
|
||||
|
||||
|
||||
if (x.getColumns().size() > 1) {
|
||||
print('(');
|
||||
}
|
||||
@@ -2524,7 +2557,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
} else if (x.isFirst()) {
|
||||
print0(ucase ? " FIRST" : " first");
|
||||
}
|
||||
|
||||
|
||||
if (x.getColumns().size() > 1) {
|
||||
print(')');
|
||||
}
|
||||
@@ -2677,7 +2710,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print(' ');
|
||||
print0(x.getLockType().name);
|
||||
}
|
||||
|
||||
|
||||
if (x.getHints() != null && x.getHints().size() > 0) {
|
||||
print(' ');
|
||||
printAndAccept(x.getHints(), " ");
|
||||
@@ -2843,7 +2876,8 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
|
||||
if (x.getIndexType() != null) {
|
||||
print0(ucase ? " USING " : " using ");;
|
||||
print0(ucase ? " USING " : " using ");
|
||||
;
|
||||
print0(x.getIndexType());
|
||||
}
|
||||
|
||||
@@ -2881,17 +2915,17 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print0(" (");
|
||||
printAndAccept(x.getReferencedColumns(), ", ");
|
||||
print(')');
|
||||
|
||||
if(x.getReferenceMatch() != null) {
|
||||
|
||||
if (x.getReferenceMatch() != null) {
|
||||
print0(ucase ? " MATCH " : " match ");
|
||||
print0(x.getReferenceMatch().name());
|
||||
}
|
||||
|
||||
if(x.getReferenceOn()!= null) {
|
||||
|
||||
if (x.getReferenceOn() != null) {
|
||||
print0(ucase ? " ON " : " on ");
|
||||
print0(x.getReferenceOn().name());
|
||||
print(' ');
|
||||
if(x.getReferenceOption() != null) {
|
||||
if (x.getReferenceOption() != null) {
|
||||
print0(x.getReferenceOption().getText());
|
||||
}
|
||||
}
|
||||
@@ -3121,9 +3155,9 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlHintStatement x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlOrderingExpr x) {
|
||||
x.getExpr().accept(this);
|
||||
@@ -3168,13 +3202,12 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* visit procedure create node
|
||||
*/
|
||||
@Override
|
||||
public boolean visit(SQLCreateProcedureStatement x) {
|
||||
if (x.isOrReplace()) {
|
||||
@Override
|
||||
public boolean visit(SQLCreateProcedureStatement x) {
|
||||
if (x.isOrReplace()) {
|
||||
print0(ucase ? "CREATE OR REPLACE PROCEDURE " : "create or replace procedure ");
|
||||
} else {
|
||||
print0(ucase ? "CREATE PROCEDURE " : "create procedure ");
|
||||
@@ -3206,19 +3239,19 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
x.getBlock().setParent(x);
|
||||
x.getBlock().accept(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlWhileStatement x) {
|
||||
@Override
|
||||
public boolean visit(MySqlWhileStatement x) {
|
||||
if (x.getLabelName() != null && !x.getLabelName().equals("")) {
|
||||
print0(x.getLabelName());
|
||||
print0(": ");
|
||||
}
|
||||
print0(ucase ? "WHILE " : "while ");
|
||||
x.getCondition().accept(this);
|
||||
print0(ucase ? " DO" : " do");
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
print0(ucase ? "WHILE " : "while ");
|
||||
x.getCondition().accept(this);
|
||||
print0(ucase ? " DO" : " do");
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
SQLStatement item = x.getStatements().get(i);
|
||||
item.setParent(x);
|
||||
item.accept(this);
|
||||
@@ -3226,26 +3259,25 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
println();
|
||||
}
|
||||
}
|
||||
println();
|
||||
println();
|
||||
print0(ucase ? "END WHILE" : "end while");
|
||||
if(x.getLabelName()!=null&&!x.getLabelName().equals(""))
|
||||
print(' ');
|
||||
print0(x.getLabelName());
|
||||
return false;
|
||||
}
|
||||
if (x.getLabelName() != null && !x.getLabelName().equals("")) print(' ');
|
||||
print0(x.getLabelName());
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlWhileStatement x) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void endVisit(MySqlWhileStatement x) {
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLIfStatement x) {
|
||||
print0(ucase ? "IF " : "if ");
|
||||
x.getCondition().accept(this);
|
||||
print0(ucase ? " THEN" : " then");
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLIfStatement x) {
|
||||
print0(ucase ? "IF " : "if ");
|
||||
x.getCondition().accept(this);
|
||||
print0(ucase ? " THEN" : " then");
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
SQLStatement item = x.getStatements().get(i);
|
||||
item.setParent(x);
|
||||
item.accept(this);
|
||||
@@ -3253,25 +3285,24 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
println();
|
||||
}
|
||||
}
|
||||
println();
|
||||
for (SQLIfStatement.ElseIf iterable_element : x.getElseIfList()) {
|
||||
iterable_element.accept(this);
|
||||
}
|
||||
|
||||
if(x.getElseItem()!=null)
|
||||
x.getElseItem().accept(this);
|
||||
|
||||
print0(ucase ? "END IF" : "end if");
|
||||
return false;
|
||||
}
|
||||
println();
|
||||
for (SQLIfStatement.ElseIf iterable_element : x.getElseIfList()) {
|
||||
iterable_element.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLIfStatement.ElseIf x) {
|
||||
print0(ucase ? "ELSE IF " : "else if ");
|
||||
x.getCondition().accept(this);
|
||||
print0(ucase ? " THEN" : " then");
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
if (x.getElseItem() != null) x.getElseItem().accept(this);
|
||||
|
||||
print0(ucase ? "END IF" : "end if");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLIfStatement.ElseIf x) {
|
||||
print0(ucase ? "ELSE IF " : "else if ");
|
||||
x.getCondition().accept(this);
|
||||
print0(ucase ? " THEN" : " then");
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
SQLStatement item = x.getStatements().get(i);
|
||||
item.setParent(x);
|
||||
item.accept(this);
|
||||
@@ -3279,15 +3310,15 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
println();
|
||||
}
|
||||
}
|
||||
println();
|
||||
return false;
|
||||
}
|
||||
println();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLIfStatement.Else x) {
|
||||
print0(ucase ? "ELSE " : "else ");
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
@Override
|
||||
public boolean visit(SQLIfStatement.Else x) {
|
||||
print0(ucase ? "ELSE " : "else ");
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
SQLStatement item = x.getStatements().get(i);
|
||||
item.setParent(x);
|
||||
item.accept(this);
|
||||
@@ -3295,89 +3326,87 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
println();
|
||||
}
|
||||
}
|
||||
println();
|
||||
return false;
|
||||
}
|
||||
println();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlCaseStatement x) {
|
||||
print0(ucase ? "CASE " : "case ");
|
||||
x.getCondition().accept(this);
|
||||
println();
|
||||
for (int i = 0; i < x.getWhenList().size(); i++) {
|
||||
x.getWhenList().get(i).accept(this);
|
||||
}
|
||||
if(x.getElseItem()!=null)
|
||||
x.getElseItem().accept(this);
|
||||
print0(ucase ? "END CASE" : "end case");
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean visit(MySqlCaseStatement x) {
|
||||
print0(ucase ? "CASE " : "case ");
|
||||
x.getCondition().accept(this);
|
||||
println();
|
||||
for (int i = 0; i < x.getWhenList().size(); i++) {
|
||||
x.getWhenList().get(i).accept(this);
|
||||
}
|
||||
if (x.getElseItem() != null) x.getElseItem().accept(this);
|
||||
print0(ucase ? "END CASE" : "end case");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlCaseStatement x) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void endVisit(MySqlCaseStatement x) {
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlDeclareStatement x) {
|
||||
print0(ucase ? "DECLARE " : "declare ");
|
||||
printAndAccept(x.getVarList(), ", ");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlDeclareStatement x) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean visit(MySqlDeclareStatement x) {
|
||||
print0(ucase ? "DECLARE " : "declare ");
|
||||
printAndAccept(x.getVarList(), ", ");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlSelectIntoStatement x) {
|
||||
x.getSelect().accept(this);
|
||||
print0(ucase ? " INTO " : " into ");
|
||||
for (int i = 0; i < x.getVarList().size(); i++) {
|
||||
x.getVarList().get(i).accept(this);
|
||||
if(i!=x.getVarList().size()-1)
|
||||
print0(", ");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void endVisit(MySqlDeclareStatement x) {
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSelectIntoStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlWhenStatement x) {
|
||||
print0(ucase ? "WHEN " : "when ");
|
||||
x.getCondition().accept(this);
|
||||
print0(" THEN");
|
||||
println();
|
||||
for (int i = 0; i < x.getStatements().size(); i++) {
|
||||
x.getStatements().get(i).accept(this);
|
||||
if (i != x.getStatements().size() - 1) {
|
||||
@Override
|
||||
public boolean visit(MySqlSelectIntoStatement x) {
|
||||
x.getSelect().accept(this);
|
||||
print0(ucase ? " INTO " : " into ");
|
||||
for (int i = 0; i < x.getVarList().size(); i++) {
|
||||
x.getVarList().get(i).accept(this);
|
||||
if (i != x.getVarList().size() - 1) print0(", ");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSelectIntoStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlWhenStatement x) {
|
||||
print0(ucase ? "WHEN " : "when ");
|
||||
x.getCondition().accept(this);
|
||||
print0(" THEN");
|
||||
println();
|
||||
for (int i = 0; i < x.getStatements().size(); i++) {
|
||||
x.getStatements().get(i).accept(this);
|
||||
if (i != x.getStatements().size() - 1) {
|
||||
println();
|
||||
}
|
||||
}
|
||||
println();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
println();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlWhenStatement x) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void endVisit(MySqlWhenStatement x) {
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLLoopStatement x) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLLoopStatement x) {
|
||||
if (x.getLabelName() != null && !x.getLabelName().equals("")) {
|
||||
print0(x.getLabelName());
|
||||
print0(": ");
|
||||
}
|
||||
|
||||
print0(ucase ? "LOOP " : "loop ");
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
|
||||
print0(ucase ? "LOOP " : "loop ");
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
SQLStatement item = x.getStatements().get(i);
|
||||
item.setParent(x);
|
||||
item.accept(this);
|
||||
@@ -3385,52 +3414,52 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
println();
|
||||
}
|
||||
}
|
||||
println();
|
||||
print0(ucase ? "END LOOP" : "end loop");
|
||||
println();
|
||||
print0(ucase ? "END LOOP" : "end loop");
|
||||
if (x.getLabelName() != null && !x.getLabelName().equals("")) {
|
||||
print0(" ");
|
||||
print0(x.getLabelName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlLeaveStatement x) {
|
||||
print0(ucase ? "LEAVE " : "leave ");
|
||||
print0(x.getLabelName());
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean visit(MySqlLeaveStatement x) {
|
||||
print0(ucase ? "LEAVE " : "leave ");
|
||||
print0(x.getLabelName());
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlLeaveStatement x) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@Override
|
||||
public void endVisit(MySqlLeaveStatement x) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlIterateStatement x) {
|
||||
print0(ucase ? "ITERATE " : "iterate ");
|
||||
print0(x.getLabelName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlIterateStatement x) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean visit(MySqlIterateStatement x) {
|
||||
print0(ucase ? "ITERATE " : "iterate ");
|
||||
print0(x.getLabelName());
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlRepeatStatement x) {
|
||||
// TODO Auto-generated method stub
|
||||
@Override
|
||||
public void endVisit(MySqlIterateStatement x) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlRepeatStatement x) {
|
||||
// TODO Auto-generated method stub
|
||||
if (x.getLabelName() != null && !x.getLabelName().equals("")) {
|
||||
print0(x.getLabelName());
|
||||
print0(": ");
|
||||
}
|
||||
|
||||
print0(ucase ? "REPEAT " : "repeat ");
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
|
||||
print0(ucase ? "REPEAT " : "repeat ");
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
SQLStatement item = x.getStatements().get(i);
|
||||
item.setParent(x);
|
||||
item.accept(this);
|
||||
@@ -3438,40 +3467,40 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
println();
|
||||
}
|
||||
}
|
||||
println();
|
||||
print0(ucase ? "UNTIL " : "until ");
|
||||
x.getCondition().accept(this);
|
||||
println();
|
||||
print0(ucase ? "END REPEAT" : "end repeat");
|
||||
println();
|
||||
print0(ucase ? "UNTIL " : "until ");
|
||||
x.getCondition().accept(this);
|
||||
println();
|
||||
print0(ucase ? "END REPEAT" : "end repeat");
|
||||
if (x.getLabelName() != null && !x.getLabelName().equals("")) {
|
||||
print(' ');
|
||||
print0(x.getLabelName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlRepeatStatement x) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@Override
|
||||
public void endVisit(MySqlRepeatStatement x) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlCursorDeclareStatement x) {
|
||||
print0(ucase ? "DECLARE " : "declare ");
|
||||
print0(x.getCursorName());
|
||||
print0(ucase ? " CURSOR FOR " : " cursor for ");
|
||||
x.getSelect().accept(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlCursorDeclareStatement x) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean visit(MySqlCursorDeclareStatement x) {
|
||||
print0(ucase ? "DECLARE " : "declare ");
|
||||
print0(x.getCursorName());
|
||||
print0(ucase ? " CURSOR FOR " : " cursor for ");
|
||||
x.getSelect().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void endVisit(MySqlCursorDeclareStatement x) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlUpdateTableSource x) {
|
||||
MySqlUpdateStatement update = x.getUpdate();
|
||||
if (update != null) {
|
||||
@@ -3500,6 +3529,89 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlAlterTableAlterColumn x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlSubPartitionByHash x) {
|
||||
if (x.isLinear()) {
|
||||
print0(ucase ? "SUBPARTITION BY LINEAR HASH " : "subpartition by linear hash ");
|
||||
} else {
|
||||
print0(ucase ? "SUBPARTITION BY HASH " : "subpartition by hash ");
|
||||
}
|
||||
|
||||
if (x.isKey()) {
|
||||
print0(ucase ? "KEY" : "key");
|
||||
}
|
||||
|
||||
print('(');
|
||||
x.getExpr().accept(this);
|
||||
print(')');
|
||||
|
||||
if (x.getSubPartitionsCount() != null) {
|
||||
print0(ucase ? " PARTITIONS " : " partitions ");
|
||||
x.getSubPartitionsCount().accept(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSubPartitionByHash x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlSubPartitionByKey x) {
|
||||
if (x.isLinear()) {
|
||||
print0(ucase ? "SUBPARTITION BY LINEAR KEY (" : "subpartition by linear key (");
|
||||
} else {
|
||||
print0(ucase ? "SUBPARTITION BY KEY (" : "subpartition by key (");
|
||||
}
|
||||
printAndAccept(x.getColumns(), ", ");
|
||||
print(')');
|
||||
|
||||
if (x.getSubPartitionsCount() != null) {
|
||||
print0(ucase ? " SUBPARTITIONS " : " subpartitions ");
|
||||
x.getSubPartitionsCount().accept(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSubPartitionByKey x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlSubPartitionByList x) {
|
||||
print0(ucase ? "SUBPARTITION BY LIST " : "subpartition by list ");
|
||||
if (x.getExpr() != null) {
|
||||
print('(');
|
||||
x.getExpr().accept(this);
|
||||
print0(") ");
|
||||
} else {
|
||||
if (x.getColumns().size() == 1 && Boolean.TRUE.equals(x.getAttribute("ads.subPartitionList"))) {
|
||||
print('(');
|
||||
} else {
|
||||
print0(ucase ? "COLUMNS (" : "columns (");
|
||||
}
|
||||
printAndAccept(x.getColumns(), ", ");
|
||||
print(")");
|
||||
}
|
||||
|
||||
if (x.getOptions().size() != 0) {
|
||||
println();
|
||||
print0(ucase ? "SUBPARTITION OPTIONS (" : "subpartition options (");
|
||||
printAndAccept(x.getOptions(), ", ");
|
||||
print(')');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSubPartitionByList x) {
|
||||
|
||||
}
|
||||
} //
|
||||
|
||||
+32
-1
@@ -47,9 +47,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlSelectIntoStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlWhileStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlExtractExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlIntervalExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlMatchAgainstExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlUserName;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.CobarShowStatus;
|
||||
@@ -141,6 +141,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTriggersStatem
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowVariantsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowWarningsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStartTransactionStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByHash;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByList;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnionQuery;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement;
|
||||
@@ -1449,5 +1452,33 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlSubPartitionByHash x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSubPartitionByHash x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlSubPartitionByKey x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSubPartitionByKey x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlSubPartitionByList x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSubPartitionByList x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -191,7 +191,7 @@ public class SQLServerExprParser extends SQLExprParser {
|
||||
return new SQLSelectItem(expr, alias);
|
||||
}
|
||||
|
||||
protected SQLColumnDefinition createColumnDefinition() {
|
||||
public SQLColumnDefinition createColumnDefinition() {
|
||||
SQLColumnDefinition column = new SQLServerColumnDefinition();
|
||||
return column;
|
||||
}
|
||||
|
||||
@@ -1595,7 +1595,7 @@ public class SQLExprParser extends SQLParser {
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
|
||||
protected SQLColumnDefinition createColumnDefinition() {
|
||||
public SQLColumnDefinition createColumnDefinition() {
|
||||
SQLColumnDefinition column = new SQLColumnDefinition();
|
||||
return column;
|
||||
}
|
||||
|
||||
@@ -32,8 +32,12 @@ public class ExportConditions extends UDF {
|
||||
public String evaluate(String sql) {
|
||||
return evaluate(sql, null);
|
||||
}
|
||||
|
||||
|
||||
public String evaluate(String sql, String dbType) {
|
||||
return evaluate(sql, dbType, null);
|
||||
}
|
||||
|
||||
public String evaluate(String sql, String dbType, Boolean compactValues) {
|
||||
try {
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, dbType);
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(dbType);
|
||||
@@ -57,7 +61,11 @@ public class ExportConditions extends UDF {
|
||||
if (values.size() == 0) {
|
||||
row.add(null);
|
||||
} else if (values.size() == 1) {
|
||||
row.add(values.get(0));
|
||||
if (compactValues != null && compactValues.booleanValue()) {
|
||||
row.add(values);
|
||||
} else {
|
||||
row.add(values.get(0));
|
||||
}
|
||||
} else {
|
||||
row.add(values);
|
||||
}
|
||||
|
||||
@@ -62,6 +62,9 @@ public interface JdbcConstants {
|
||||
|
||||
public static final String KINGBASE = "kingbase";
|
||||
public static final String KINGBASE_DRIVER = "com.kingbase.Driver";
|
||||
|
||||
public static final String OCEANBASE = "oceanbase";
|
||||
public static final String OCEANBASE_DRIVER = "com.mysql.jdbc.Driver";
|
||||
|
||||
/**
|
||||
* 阿里云odps
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.bvt.sql.mysql;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
|
||||
public class MySqlCreateTableTest66 extends MysqlTest {
|
||||
|
||||
@Test
|
||||
public void test_one() throws Exception {
|
||||
String sql = "create table hp_db.g20_relationship_communication_daily( "
|
||||
+ " a_iden_string varchar,"
|
||||
+ " b_iden_string varchar,"
|
||||
+ " counter bigint,"
|
||||
+ " durationtime bigint"
|
||||
+ ") "
|
||||
+ "\nPARTITION BY HASH KEY(a_iden_string) PARTITION NUM 100"
|
||||
+ "\nSUBPARTITION BY LIST(bdt bigint)"
|
||||
+ "\nSUBPARTITION OPTIONS(available_Partition_Num=90)"
|
||||
+ "\nTABLEGROUP g20_test_group;";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseCreateTable();
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE TABLE hp_db.g20_relationship_communication_daily ("
|
||||
+ "\n\ta_iden_string varchar, "
|
||||
+ "\n\tb_iden_string varchar, "
|
||||
+ "\n\tcounter bigint, "
|
||||
+ "\n\tdurationtime bigint"
|
||||
+ "\n) PARTITION BY HASH KEY(a_iden_string) PARTITION NUM 100"
|
||||
+ "\nSUBPARTITION BY LIST (bdt bigint)"
|
||||
+ "\nSUBPARTITION OPTIONS (available_Partition_Num = 90)"
|
||||
+ "\nTABLEGROUP g20_test_group", output);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.alibaba.druid.bvt.support.odps.udf;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.support.opds.udf.ExportConditions;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ExportConditionsTest5 extends TestCase {
|
||||
ExportConditions udf = new ExportConditions();
|
||||
|
||||
public void test_export_conditions() throws Exception {
|
||||
String result = udf.evaluate("select * from t where name = 'a1' or name = 'a2'");
|
||||
Assert.assertEquals("[[\"t\",\"name\",\"=\",[\"a1\",\"a2\"]]]", result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.alibaba.druid.bvt.support.odps.udf;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.support.opds.udf.ExportConditions;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ExportConditionsTest6 extends TestCase {
|
||||
ExportConditions udf = new ExportConditions();
|
||||
|
||||
public void test_export_conditions() throws Exception {
|
||||
String result = udf.evaluate("select * from t where name = 'a1'", "odbps", true);
|
||||
Assert.assertEquals("[[\"t\",\"name\",\"=\",[\"a1\"]]]", result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user