Skip to content

Commit

Permalink
Merge pull request #227 from polardb/feature/ziyang_add_new_syntax_4_…
Browse files Browse the repository at this point in the history
…parser

support new sql syntax for parser
  • Loading branch information
agapple authored Dec 20, 2024
2 parents ba432af + 40fa83b commit 437d00a
Show file tree
Hide file tree
Showing 6 changed files with 403 additions and 4 deletions.
1 change: 1 addition & 0 deletions polardbx-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<includes>
<include>**/bvt/**/*.java</include>
<include>com/alibaba/polardbx/druid/sql/visitor/ExportParameterVisitorUtilsTest.java</include>
<include>com/alibaba/polardbx/druid/sql/repository/*.java</include>
</includes>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void removeArchiveCciInfoForTtlDefinitionOptionIfNeed() {
int elementIdx = -1;
for (int i = 0; i < tableElementList.size(); i++) {
SQLTableElement element = tableElementList.get(i);
if (element instanceof MySqlTableIndex) {
if (element instanceof MySqlTableIndex) {
MySqlTableIndex idx = (MySqlTableIndex) element;
if (idx.isColumnar()) {
targetArcCci = idx;
Expand All @@ -161,7 +161,6 @@ public void removeArchiveCciInfoForTtlDefinitionOptionIfNeed() {
}
}


public List<SQLCommentHint> getHints() {
return hints;
}
Expand Down Expand Up @@ -1179,6 +1178,21 @@ public SQLExpr getAutoSplit() {
return this.autoSplit;
}

public void setPageChecksum(SQLExpr x) {
if (x != null) {
x.setParent(this);
}
addOption("PAGE_CHECKSUM", x);
}

public void setTransactional(SQLExpr x) {
if (x != null) {
x.setParent(this);
}
addOption("TRANSACTIONAL", x);
}


private final Set<String> VALID_TABLE_OPTIONS = new HashSet<String>(Arrays.asList(
"AUTO_INCREMENT", "AVG_ROW_LENGTH", "CHARACTER SET", "DEFAULT CHARACTER SET", "CHARSET", "DEFAULT CHARSET",
"CHECKSUM", "COLLATE", "DEFAULT COLLATE", "COMMENT", "COMPRESSION", "CONNECTION", "DATA DIRECTORY",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ public MySqlCreateTableStatement parseCreateTable(boolean acceptCreate) {
stmt.getTableElementList().add(column);
}

if (lexer.token() == Token.HINT) {
lexer.nextToken();
}

if (lexer.token() != Token.COMMA) {
break;
} else {
Expand Down Expand Up @@ -659,6 +663,28 @@ public MySqlCreateTableStatement parseCreateTable(boolean acceptCreate) {
continue;
}

if (lexer.identifierEquals("PAGE_CHECKSUM")) {
lexer.nextToken();
if (lexer.token() == Token.EQ) {
lexer.nextToken();
}

SQLExpr expr = this.exprParser.expr();
stmt.setPageChecksum(expr);
continue;
}

if (lexer.identifierEquals("TRANSACTIONAL")) {
lexer.nextToken();
if (lexer.token() == Token.EQ) {
lexer.nextToken();
}

SQLExpr expr = this.exprParser.expr();
stmt.setTransactional(expr);
continue;
}

if (lexer.identifierEquals(FnvHash.Constants.BLOCK_SIZE)) {
lexer.nextToken();
if (lexer.token() == Token.EQ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ public SQLColumnDefinition parseColumnRest(SQLColumnDefinition column) {
accept(Token.RPAREN);
}

if (lexer.identifierEquals(FnvHash.Constants.STORED)) {
if (lexer.identifierEquals(FnvHash.Constants.STORED) || lexer.identifierEquals("PERSISTENT")) {
lexer.nextToken();
column.setStored(true);
}
Expand Down Expand Up @@ -1928,7 +1928,15 @@ public SQLPartition parsePartition() {

SQLPartition partitionDef = new SQLPartition();

partitionDef.setName(this.name());
SQLName name;
if (lexer.token() == Token.LITERAL_INT) {
Number number = lexer.integerValue();
name = new SQLIdentifierExpr(number.toString());
lexer.nextToken();
} else {
name = this.name();
}
partitionDef.setName(name);

SQLPartitionValue values = this.parsePartitionValues();
if (values != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public class SchemaRepository {

private String defaultCharset;

private boolean forceReplace;

public SchemaRepository() {

}
Expand Down Expand Up @@ -220,6 +222,14 @@ public void setDefaultSchema(Schema schema) {
this.defaultSchema = schema;
}

public boolean isForceReplace() {
return forceReplace;
}

public void setForceReplace(boolean forceReplace) {
this.forceReplace = forceReplace;
}

public SchemaObject findTable(String tableName) {
if (tableName.indexOf('.') != -1) {
SQLExpr expr = SQLUtils.toSQLExpr(tableName, dbType);
Expand Down Expand Up @@ -899,6 +909,10 @@ SchemaObject acceptCreateTable(SQLCreateTableStatement x) {
String name = x1.computeName();
SchemaObject table = schema.findTableOrView(name);
if (table != null) {
if (x1.isIfNotExists() && !forceReplace) {
return table;
}

if (LOG.isDebugEnabled()) {
LOG.debug("replaced table '" + name + "'");
}
Expand Down
Loading

0 comments on commit 437d00a

Please sign in to comment.