mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved mysql parser, support checksum table syntax.
This commit is contained in:
+54
@@ -0,0 +1,54 @@
|
||||
package com.alibaba.druid.sql.dialect.mysql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlChecksumTableStatement extends MySqlStatementImpl {
|
||||
private final List<SQLExprTableSource> tables = new ArrayList<SQLExprTableSource>();
|
||||
|
||||
private boolean quick;
|
||||
private boolean extended;
|
||||
|
||||
public MySqlChecksumTableStatement() {
|
||||
|
||||
}
|
||||
|
||||
public void addTable(SQLExprTableSource table) {
|
||||
if (table == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
table.setParent(this);
|
||||
tables.add(table);
|
||||
}
|
||||
|
||||
public List<SQLExprTableSource> getTables() {
|
||||
return tables;
|
||||
}
|
||||
|
||||
public boolean isQuick() {
|
||||
return quick;
|
||||
}
|
||||
|
||||
public void setQuick(boolean quick) {
|
||||
this.quick = quick;
|
||||
}
|
||||
|
||||
public boolean isExtended() {
|
||||
return extended;
|
||||
}
|
||||
|
||||
public void setExtended(boolean extended) {
|
||||
this.extended = extended;
|
||||
}
|
||||
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, tables);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
@@ -851,6 +851,11 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.CHECKSUM)) {
|
||||
statementList.add(this.parseChecksum());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.HINT) {
|
||||
List<SQLCommentHint> hints = this.exprParser.parseHints();
|
||||
|
||||
@@ -4662,6 +4667,11 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.CHECKSUM)) {
|
||||
statementList.add(this.parseChecksum());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
String label = lexer.stringVal();
|
||||
char ch = lexer.current();
|
||||
@@ -4693,6 +4703,30 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public MySqlChecksumTableStatement parseChecksum() {
|
||||
MySqlChecksumTableStatement stmt = new MySqlChecksumTableStatement();
|
||||
if (lexer.identifierEquals(FnvHash.Constants.CHECKSUM)) {
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
SQLExprTableSource table = (SQLExprTableSource) this.createSQLSelectParser().parseTableSource();
|
||||
stmt.addTable(table);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse if statement
|
||||
*
|
||||
|
||||
@@ -494,4 +494,7 @@ public interface MySqlASTVisitor extends SQLASTVisitor {
|
||||
boolean visit(MySqlShowDatabasePartitionStatusStatement x);
|
||||
void endVisit(MySqlShowDatabasePartitionStatusStatement x);
|
||||
|
||||
boolean visit(MySqlChecksumTableStatement x);
|
||||
void endVisit(MySqlChecksumTableStatement x);
|
||||
|
||||
} //
|
||||
|
||||
@@ -1228,4 +1228,14 @@ public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements MySq
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlChecksumTableStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlChecksumTableStatement x) {
|
||||
|
||||
}
|
||||
|
||||
} //
|
||||
|
||||
@@ -4200,4 +4200,16 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlChecksumTableStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlChecksumTableStatement x) {
|
||||
print0(ucase ? "CHECKSUM TABLE " : "checksum table ");
|
||||
printAndAccept(x.getTables(), ",");
|
||||
return false;
|
||||
}
|
||||
} //
|
||||
|
||||
@@ -1361,4 +1361,14 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
public void endVisit(MySqlShowDatabasePartitionStatusStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlChecksumTableStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlChecksumTableStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -638,5 +638,6 @@ public final class FnvHash {
|
||||
long PATH = fnv1a_64_lower("PATH");
|
||||
long COMPRESSION = fnv1a_64_lower("COMPRESSION");
|
||||
long KEY_BLOCK_SIZE = fnv1a_64_lower("KEY_BLOCK_SIZE");
|
||||
long CHECKSUM = fnv1a_64_lower("CHECKSUM");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user