Merge pull request #1088 from wenshao/master

improved sql parser, bug fixed for parent is null
This commit is contained in:
wenshao
2016-02-27 19:19:35 +08:00
94 changed files with 1293 additions and 954 deletions
@@ -19,7 +19,6 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableDiscardT
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableImportTablespace;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableModifyColumn;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableOption;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement.TableSpaceOption;
@@ -160,7 +159,6 @@ public class MySqlASTVisitorAdapterTest extends TestCase {
new MySqlShowSlaveStatusStatement().accept(adapter);
new MySqlShowTableStatusStatement().accept(adapter);
new MySqlShowTriggersStatement().accept(adapter);
new MySqlAlterTableStatement().accept(adapter);
new MySqlRenameTableStatement().accept(adapter);
new MySqlUnionQuery().accept(adapter);
new MySqlUseIndexHint().accept(adapter);
@@ -0,0 +1,38 @@
/*
* 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 junit.framework.TestCase;
import org.junit.Assert;
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.parser.Token;
public class MySqlAlterDbTest0 extends TestCase {
public void test_alter_first() throws Exception {
String sql = "ALTER DATABASE `#mysql50#a-b-c` UPGRADE DATA DIRECTORY NAME;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("ALTER DATABASE `#mysql50#a-b-c` UPGRADE DATA DIRECTORY NAME", output);
}
}
@@ -0,0 +1,38 @@
/*
* 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 junit.framework.TestCase;
import org.junit.Assert;
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.parser.Token;
public class MySqlAlterTableTest21 extends TestCase {
public void test_alter_add_key() throws Exception {
String sql = "ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("ALTER TABLE tbl_name"
+ "\n\tCONVERT TO CHARACTER SET charset_name", output);
}
}
@@ -0,0 +1,56 @@
/*
* 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 MySqlCreateTableTest69 extends MysqlTest {
@Test
public void test_one() throws Exception {
String sql = "CREATE TABLE t1 ("
+ " s1 INT,"
+ " s2 INT AS (EXP(s1)) STORED"
+ ")"
+ "PARTITION BY LIST (s2) ("
+ " PARTITION p1 VALUES IN (1)"
+ ");";
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 t1 ("
+ "\n\ts1 INT, "
+ "\n\ts2 INT AS (EXP(s1)) SORTED"
+ "\n)"
+ "\nPARTITION BY LIST (s2)"
+ "\n("
+ "\n\tPARTITION p1 VALUES IN (1)"
+ "\n)", output);
}
}
@@ -54,7 +54,6 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTableDropPartiti
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTableModify;
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTableMoveTablespace;
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTableSplitPartition;
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTableStatement;
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTableTruncatePartition;
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTablespaceAddDataFile;
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTablespaceStatement;
@@ -185,7 +184,6 @@ public class OracleASTVisitorAdapterTest extends TestCase {
new OracleAlterProcedureStatement().accept(adapter);
new OracleAlterTableDropPartition().accept(adapter);
new OracleAlterTableTruncatePartition().accept(adapter);
new OracleAlterTableStatement().accept(adapter);
new OracleAlterTableSplitPartition.TableSpaceItem().accept(adapter);
new OracleAlterTableSplitPartition.UpdateIndexesClause().accept(adapter);
new OracleAlterTableSplitPartition.NestedTablePartitionSpec().accept(adapter);