improved mysql create table parser. for fulltext key, for issue #2271

This commit is contained in:
wenshao
2018-01-22 10:50:30 +08:00
parent 8fa2643385
commit 1c331c217d
3 changed files with 84 additions and 4 deletions
@@ -41,10 +41,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByKey;
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;
import com.alibaba.druid.sql.parser.SQLExprParser;
import com.alibaba.druid.sql.parser.Token;
import com.alibaba.druid.sql.parser.*;
import com.alibaba.druid.util.FnvHash;
public class MySqlCreateTableParser extends SQLCreateTableParser {
@@ -109,6 +106,21 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
stmt.setSelect(query);
} else {
for (;;) {
if (lexer.identifierEquals(FnvHash.Constants.FULLTEXT)) {
Lexer.SavePoint mark = lexer.mark();
lexer.nextToken();
if (lexer.token() == Token.KEY) {
MySqlKey fulltextKey = (MySqlKey) parseConstraint();
fulltextKey.setIndexType("FULLTEXT");
stmt.getTableElementList().add(fulltextKey);
if (lexer.token() == Token.RPAREN) {
break;
}
} else {
lexer.reset(mark);
}
}
SQLColumnDefinition column = null;
if (lexer.token() == Token.IDENTIFIER //
|| lexer.token() == Token.LITERAL_CHARS) {
@@ -632,5 +632,6 @@ public final class FnvHash {
long EXIST = fnv1a_64_lower("EXIST");
long TBLPROPERTIES = fnv1a_64_lower("TBLPROPERTIES");
long FULLTEXT = fnv1a_64_lower("FULLTEXT");
}
}