mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser support create table partition syntax
This commit is contained in:
@@ -16,6 +16,9 @@
|
||||
package com.alibaba.druid.sql.parser;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLPartition;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionValue;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
@@ -90,7 +93,7 @@ public class SQLCreateTableParser extends SQLDDLParser {
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
if (lexer.token() == Token.RPAREN) { // compatible for sql server
|
||||
break;
|
||||
}
|
||||
@@ -126,4 +129,45 @@ public class SQLCreateTableParser extends SQLDDLParser {
|
||||
protected SQLCreateTableStatement newCreateStatement() {
|
||||
return new SQLCreateTableStatement(getDbType());
|
||||
}
|
||||
|
||||
protected SQLPartitionValue parsePartitionValues() {
|
||||
if (lexer.token() != Token.VALUES) {
|
||||
return null;
|
||||
}
|
||||
lexer.nextToken();
|
||||
|
||||
SQLPartitionValue values = null;
|
||||
|
||||
if (lexer.token() == Token.IN) {
|
||||
lexer.nextToken();
|
||||
values = new SQLPartitionValue(SQLPartitionValue.Operator.In);
|
||||
|
||||
accept(Token.LPAREN);
|
||||
this.exprParser.exprList(values.getItems(), values);
|
||||
accept(Token.RPAREN);
|
||||
} else if (identifierEquals("LESS")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("THAN");
|
||||
|
||||
values = new SQLPartitionValue(SQLPartitionValue.Operator.LessThan);
|
||||
|
||||
if (identifierEquals("MAXVALUE")) {
|
||||
SQLIdentifierExpr maxValue = new SQLIdentifierExpr(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
maxValue.setParent(values);
|
||||
values.getItems().add(maxValue);
|
||||
} else {
|
||||
accept(Token.LPAREN);
|
||||
this.exprParser.exprList(values.getItems(), values);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
} else if (lexer.token() == Token.LPAREN) {
|
||||
values = new SQLPartitionValue(SQLPartitionValue.Operator.List);
|
||||
lexer.nextToken();
|
||||
this.exprParser.exprList(values.getItems(), values);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user